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
ae7c4908
Commit
ae7c4908
authored
Feb 20, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #767
parent
ea1a8823
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
23 deletions
+6
-23
gdriveutils.py
cps/gdriveutils.py
+5
-13
helper.py
cps/helper.py
+1
-9
web.py
cps/web.py
+0
-1
No files found.
cps/gdriveutils.py
View file @
ae7c4908
...
...
@@ -31,13 +31,9 @@ from ub import config
import
cli
import
shutil
from
flask
import
Response
,
stream_with_context
import
time
from
sqlalchemy
import
*
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
*
import
web
class
Singleton
:
...
...
@@ -286,9 +282,10 @@ def downloadFile(path, filename, output):
def
moveGdriveFolderRemote
(
origin_file
,
target_folder
):
drive
=
getDrive
(
Gdrive
.
Instance
()
.
drive
)
previous_parents
=
","
.
join
([
parent
[
"id"
]
for
parent
in
origin_file
.
get
(
'parents'
)])
children
=
drive
.
auth
.
service
.
children
()
.
list
(
folderId
=
previous_parents
)
.
execute
()
gFileTargetDir
=
getFileFromEbooksFolder
(
None
,
target_folder
)
if
not
gFileTargetDir
:
# Folder is not exis
i
ting, create, and move folder
# Folder is not existing, create, and move folder
gFileTargetDir
=
drive
.
CreateFile
(
{
'title'
:
target_folder
,
'parents'
:
[{
"kind"
:
"drive#fileLink"
,
'id'
:
getEbooksFolderId
()}],
"mimeType"
:
"application/vnd.google-apps.folder"
})
...
...
@@ -298,15 +295,10 @@ def moveGdriveFolderRemote(origin_file, target_folder):
addParents
=
gFileTargetDir
[
'id'
],
removeParents
=
previous_parents
,
fields
=
'id, parents'
)
.
execute
()
# if previous_parents has no childs anymore, delete originfileparent
# is not working correctly, because of slow update on gdrive -> could cause trouble in gdrive.db
# (nonexisting folder has id)
time
.
sleep
(
20
)
children
=
drive
.
auth
.
service
.
children
()
.
list
(
folderId
=
previous_parents
)
.
execute
()
if
not
len
(
children
[
'items'
]):
# if previous_parents has no childs anymore, delete original fileparent
if
len
(
children
[
'items'
])
==
1
:
deleteDatabaseEntry
(
previous_parents
)
drive
.
auth
.
service
.
files
()
.
delete
(
fileId
=
previous_parents
)
.
execute
()
time
.
sleep
(
20
)
def
copyToDrive
(
drive
,
uploadFile
,
createRoot
,
replaceFiles
,
...
...
cps/helper.py
View file @
ae7c4908
...
...
@@ -22,13 +22,11 @@
import
db
import
ub
from
flask
import
current_app
as
app
# import logging
from
tempfile
import
gettempdir
import
sys
import
os
import
re
import
unicodedata
# from io import BytesIO
import
worker
import
time
from
flask
import
send_from_directory
,
make_response
,
redirect
,
abort
...
...
@@ -36,16 +34,13 @@ from flask_babel import gettext as _
from
flask_login
import
current_user
from
babel.dates
import
format_datetime
from
datetime
import
datetime
# import threading
import
shutil
import
requests
# import zipfile
try
:
import
gdriveutils
as
gd
except
ImportError
:
pass
import
web
# import server
import
random
import
subprocess
...
...
@@ -355,9 +350,7 @@ def update_dir_structure_gdrive(book_id, first_author):
gFile
=
gd
.
getFileFromEbooksFolder
(
os
.
path
.
dirname
(
book
.
path
),
titledir
)
if
gFile
:
gFile
[
'title'
]
=
new_titledir
gFile
.
Upload
()
time
.
sleep
(
10
)
book
.
path
=
book
.
path
.
split
(
'/'
)[
0
]
+
u'/'
+
new_titledir
path
=
book
.
path
gd
.
updateDatabaseOnEdit
(
gFile
[
'id'
],
book
.
path
)
# only child folder affected
...
...
@@ -365,10 +358,9 @@ def update_dir_structure_gdrive(book_id, first_author):
error
=
_
(
u'File
%(file)
s not found on Google Drive'
,
file
=
book
.
path
)
# file not found
if
authordir
!=
new_authordir
:
gFile
=
gd
.
getFileFromEbooksFolder
(
os
.
path
.
dirname
(
book
.
path
),
titledir
)
gFile
=
gd
.
getFileFromEbooksFolder
(
os
.
path
.
dirname
(
book
.
path
),
new_
titledir
)
if
gFile
:
gd
.
moveGdriveFolderRemote
(
gFile
,
new_authordir
)
time
.
sleep
(
10
)
book
.
path
=
new_authordir
+
u'/'
+
book
.
path
.
split
(
'/'
)[
1
]
path
=
book
.
path
gd
.
updateDatabaseOnEdit
(
gFile
[
'id'
],
book
.
path
)
...
...
cps/web.py
View file @
ae7c4908
...
...
@@ -3845,7 +3845,6 @@ def upload():
# upload book to gdrive if nesseccary and add "(bookid)" to folder name
if
config
.
config_use_google_drive
:
gdriveutils
.
updateGdriveCalibreFromLocal
()
time
.
sleep
(
10
)
error
=
helper
.
update_dir_stucture
(
book
.
id
,
config
.
config_calibre_dir
)
db
.
session
.
commit
()
if
config
.
config_use_google_drive
:
...
...
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