1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-21 07:30:30 +00:00

Fix after testrun for G-Drive

This commit is contained in:
Ozzie Isaacs 2024-07-01 20:19:44 +02:00
parent 762074596d
commit 60dd3df861
4 changed files with 321 additions and 461 deletions

View File

@ -64,7 +64,7 @@ except ImportError as err:
importError = err importError = err
gdrive_support = False gdrive_support = False
from . import logger, cli_param, config from . import logger, cli_param, config, db
from .constants import CONFIG_DIR as _CONFIG_DIR from .constants import CONFIG_DIR as _CONFIG_DIR
@ -265,7 +265,7 @@ def getFile(pathId, fileName, drive, nocase):
if fileList.__len__() == 0: if fileList.__len__() == 0:
return None return None
if nocase: if nocase:
return fileList[0] return fileList[0] if db.lcase(fileList[0]['title']) == db.lcase(fileName) else None
for f in fileList: for f in fileList:
if f['title'] == fileName: if f['title'] == fileName:
return f return f
@ -273,8 +273,6 @@ def getFile(pathId, fileName, drive, nocase):
def getFolderId(path, drive): def getFolderId(path, drive):
# drive = getDrive(drive)
log.info(f"GetFolder: {path}")
currentFolderId = None currentFolderId = None
try: try:
currentFolderId = getEbooksFolderId(drive) currentFolderId = getEbooksFolderId(drive)
@ -348,16 +346,23 @@ def moveGdriveFolderRemote(origin_file, target_folder, single_book=False):
previous_parents = ",".join([parent["id"] for parent in origin_file.get('parents')]) previous_parents = ",".join([parent["id"] for parent in origin_file.get('parents')])
children = drive.auth.service.children().list(folderId=previous_parents).execute() children = drive.auth.service.children().list(folderId=previous_parents).execute()
if single_book: if single_book:
# gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True)
gFileTargetDir = drive.CreateFile( if gFileTargetDir:
{'title': target_folder, 'parents': [{"kind": "drive#fileLink", 'id': getEbooksFolderId()}], # Move the file to the new folder
"mimeType": "application/vnd.google-apps.folder"}) drive.auth.service.files().update(fileId=origin_file['id'],
gFileTargetDir.Upload() addParents=gFileTargetDir['id'],
# Move the file to the new folder removeParents=previous_parents,
drive.auth.service.files().update(fileId=origin_file['id'], fields='id, parents').execute()
addParents=gFileTargetDir['id'], else:
removeParents=previous_parents, gFileTargetDir = drive.CreateFile(
fields='id, parents').execute() {'title': target_folder, 'parents': [{"kind": "drive#fileLink", 'id': getEbooksFolderId()}],
"mimeType": "application/vnd.google-apps.folder"})
gFileTargetDir.Upload()
# Move the file to the new folder
drive.auth.service.files().update(fileId=origin_file['id'],
addParents=gFileTargetDir['id'],
removeParents=previous_parents,
fields='id, parents').execute()
elif origin_file['title'] != target_folder: elif origin_file['title'] != target_folder:
#gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) #gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True)
#if gFileTargetDir: #if gFileTargetDir:
@ -366,12 +371,7 @@ def moveGdriveFolderRemote(origin_file, target_folder, single_book=False):
drive.auth.service.files().patch(fileId=origin_file['id'], drive.auth.service.files().patch(fileId=origin_file['id'],
body={'title': target_folder}, body={'title': target_folder},
fields='title').execute() fields='title').execute()
'''else:
# Move the file to the new folder
drive.auth.service.files().update(fileId=origin_file['id'],
addParents=gFileTargetDir['id'],
removeParents=previous_parents,
fields='id, parents').execute()'''
# if previous_parents has no children anymore, delete original fileparent # if previous_parents has no children anymore, delete original fileparent
if len(children['items']) == 1: if len(children['items']) == 1:
deleteDatabaseEntry(previous_parents) deleteDatabaseEntry(previous_parents)

View File

@ -525,7 +525,7 @@ def update_dir_structure_gdrive(book_id, first_author):
new_titledir = get_valid_filename(book.title, chars=96) + " (" + str(book_id) + ")" new_titledir = get_valid_filename(book.title, chars=96) + " (" + str(book_id) + ")"
if titledir != new_titledir: if titledir != new_titledir:
g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), titledir) g_file = gd.getFileFromEbooksFolder(authordir, titledir)
if g_file: if g_file:
gd.moveGdriveFileRemote(g_file, new_titledir) gd.moveGdriveFileRemote(g_file, new_titledir)
book.path = book.path.split('/')[0] + '/' + new_titledir book.path = book.path.split('/')[0] + '/' + new_titledir
@ -612,7 +612,7 @@ def delete_book_gdrive(book, book_format):
for entry in book.data: for entry in book.data:
if entry.format.upper() == book_format: if entry.format.upper() == book_format:
name = entry.name + '.' + book_format name = entry.name + '.' + book_format
g_file = gd.getFileFromEbooksFolder(book.path, name) g_file = gd.getFileFromEbooksFolder(book.path, name, nocase=True)
else: else:
g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), book.path.split('/')[1]) g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), book.path.split('/')[1])
if g_file: if g_file:

View File

@ -1,5 +1,5 @@
# GDrive Integration # GDrive Integration
google-api-python-client>=1.7.11,<2.120.0 google-api-python-client>=1.7.11,<2.200.0
gevent>20.6.0,<24.3.0 gevent>20.6.0,<24.3.0
greenlet>=0.4.17,<3.1.0 greenlet>=0.4.17,<3.1.0
httplib2>=0.9.2,<0.23.0 httplib2>=0.9.2,<0.23.0
@ -13,7 +13,7 @@ rsa>=3.4.2,<4.10.0
# Gmail # Gmail
google-auth-oauthlib>=0.4.3,<1.3.0 google-auth-oauthlib>=0.4.3,<1.3.0
google-api-python-client>=1.7.11,<2.120.0 google-api-python-client>=1.7.11,<2.200.0
# goodreads # goodreads
goodreads>=0.3.2,<0.4.0 goodreads>=0.3.2,<0.4.0

File diff suppressed because it is too large Load Diff