Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
8d406117
Commit
8d406117
authored
Jul 14, 2018
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #432 added more checks for deleting books
parent
eb656477
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
helper.py
cps/helper.py
+16
-10
No files found.
cps/helper.py
View file @
8d406117
...
...
@@ -290,18 +290,24 @@ def get_sorted_author(value):
else
:
value2
=
value
[
-
1
]
+
", "
+
" "
.
join
(
value
[:
-
1
])
except
Exception
:
logging
.
getLogger
(
'cps.web'
)
.
error
(
"Sorting author "
+
str
(
value
)
+
"failed"
)
web
.
app
.
logger
.
error
(
"Sorting author "
+
str
(
value
)
+
"failed"
)
value2
=
value
return
value2
# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
def
delete_book_file
(
book
,
calibrepath
):
# check that path is 2 elements deep, check that target path has no subfolders
if
"/"
in
book
.
path
:
if
book
.
path
.
count
(
'/'
)
==
1
:
path
=
os
.
path
.
join
(
calibrepath
,
book
.
path
)
if
len
(
next
(
os
.
walk
(
path
))[
1
]):
web
.
app
.
logger
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, path has subfolders: "
+
book
.
path
)
return
False
shutil
.
rmtree
(
path
,
ignore_errors
=
True
)
return
True
else
:
logging
.
getLogger
(
'cps.web'
)
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, book path value: "
+
book
.
path
)
web
.
app
.
logger
.
error
(
"Deleting book "
+
str
(
book
.
id
)
+
" failed, book path value: "
+
book
.
path
)
return
False
def
update_dir_stucture_file
(
book_id
,
calibrepath
):
...
...
@@ -320,15 +326,15 @@ def update_dir_stucture_file(book_id, calibrepath):
if
not
os
.
path
.
exists
(
new_title_path
):
os
.
renames
(
path
,
new_title_path
)
else
:
logging
.
getLogger
(
'cps.web'
)
.
info
(
"Copying title: "
+
path
+
" into existing: "
+
new_title_path
)
web
.
app
.
logger
.
info
(
"Copying title: "
+
path
+
" into existing: "
+
new_title_path
)
for
dir_name
,
subdir_list
,
file_list
in
os
.
walk
(
path
):
for
file
in
file_list
:
os
.
renames
(
os
.
path
.
join
(
dir_name
,
file
),
os
.
path
.
join
(
new_title_path
+
dir_name
[
len
(
path
):],
file
))
path
=
new_title_path
localbook
.
path
=
localbook
.
path
.
split
(
'/'
)[
0
]
+
'/'
+
new_titledir
except
OSError
as
ex
:
logging
.
getLogger
(
'cps.web'
)
.
error
(
"Rename title from: "
+
path
+
" to "
+
new_title_path
)
logging
.
getLogger
(
'cps.web'
)
.
error
(
ex
,
exc_info
=
True
)
web
.
app
.
logger
.
error
(
"Rename title from: "
+
path
+
" to "
+
new_title_path
)
web
.
app
.
logger
.
error
(
ex
,
exc_info
=
True
)
return
_
(
'Rename title from: "
%
s" to "
%
s" failed with error:
%
s'
%
(
path
,
new_title_path
,
str
(
ex
)))
if
authordir
!=
new_authordir
:
try
:
...
...
@@ -336,8 +342,8 @@ def update_dir_stucture_file(book_id, calibrepath):
os
.
renames
(
path
,
new_author_path
)
localbook
.
path
=
new_authordir
+
'/'
+
localbook
.
path
.
split
(
'/'
)[
1
]
except
OSError
as
ex
:
logging
.
getLogger
(
'cps.web'
)
.
error
(
"Rename author from: "
+
path
+
" to "
+
new_author_path
)
logging
.
getLogger
(
'cps.web'
)
.
error
(
ex
,
exc_info
=
True
)
web
.
app
.
logger
.
error
(
"Rename author from: "
+
path
+
" to "
+
new_author_path
)
web
.
app
.
logger
.
error
(
ex
,
exc_info
=
True
)
return
_
(
'Rename author from: "
%
s" to "
%
s" failed with error:
%
s'
%
(
path
,
new_title_path
,
str
(
ex
)))
return
False
...
...
@@ -381,7 +387,7 @@ def delete_book_gdrive(book):
gd
.
deleteDatabaseEntry
(
gFile
[
'id'
])
gFile
.
Trash
()
else
:
error
=
_
(
u'Path
%
s not found on gdrive'
%
book
.
path
)
# file not found
error
=
_
(
u'
delete_book
Path
%
s not found on gdrive'
%
book
.
path
)
# file not found
return
error
################################## External interface
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment