diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 49ab5882..7e4c662b 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -64,7 +64,7 @@ except ImportError as err: importError = err gdrive_support = False -from . import logger, cli_param, config +from . import logger, cli_param, config, db from .constants import CONFIG_DIR as _CONFIG_DIR @@ -265,7 +265,7 @@ def getFile(pathId, fileName, drive, nocase): if fileList.__len__() == 0: return None if nocase: - return fileList[0] + return fileList[0] if db.lcase(fileList[0]['title']) == db.lcase(fileName) else None for f in fileList: if f['title'] == fileName: return f @@ -273,8 +273,6 @@ def getFile(pathId, fileName, drive, nocase): def getFolderId(path, drive): - # drive = getDrive(drive) - log.info(f"GetFolder: {path}") currentFolderId = None try: 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')]) children = drive.auth.service.children().list(folderId=previous_parents).execute() if single_book: - # gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) - gFileTargetDir = drive.CreateFile( - {'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() + gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) + if gFileTargetDir: + # 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() + else: + gFileTargetDir = drive.CreateFile( + {'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: #gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) #if gFileTargetDir: @@ -366,12 +371,7 @@ def moveGdriveFolderRemote(origin_file, target_folder, single_book=False): drive.auth.service.files().patch(fileId=origin_file['id'], body={'title': target_folder}, 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 len(children['items']) == 1: deleteDatabaseEntry(previous_parents) diff --git a/cps/helper.py b/cps/helper.py index b3bf3c9a..84e46a24 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -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) + ")" if titledir != new_titledir: - g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), titledir) + g_file = gd.getFileFromEbooksFolder(authordir, titledir) if g_file: gd.moveGdriveFileRemote(g_file, 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: if entry.format.upper() == book_format: name = entry.name + '.' + book_format - g_file = gd.getFileFromEbooksFolder(book.path, name) + g_file = gd.getFileFromEbooksFolder(book.path, name, nocase=True) else: g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), book.path.split('/')[1]) if g_file: diff --git a/optional-requirements.txt b/optional-requirements.txt index e097746f..77f41e1e 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -1,5 +1,5 @@ # 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 greenlet>=0.4.17,<3.1.0 httplib2>=0.9.2,<0.23.0 @@ -13,7 +13,7 @@ rsa>=3.4.2,<4.10.0 # Gmail 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>=0.3.2,<0.4.0 diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index b799e9aa..9a4bf126 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
Start Time: 2024-06-29 20:48:57
+Start Time: 2024-07-01 20:28:34
Stop Time: 2024-06-30 03:48:15
+Stop Time: 2024-07-02 03:50:44
Duration: 5h 44 min
+Duration: 6h 9 min
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_ebook_convert_gdrive.py", line 251, in test_convert_failed_and_email + select.select_by_visible_text('AZW3') + File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/support/select.py", line 134, in select_by_visible_text + raise NoSuchElementException(f"Could not locate element with visible text: {text}") +selenium.common.exceptions.NoSuchElementException: Message: Could not locate element with visible text: AZW3+
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 174, in test_change_capital_one_author_two_books - self.assertFalse(self.check_element_on_page((By.ID, "flash_danger"))) -AssertionError: <selenium.webdriver.remote.webelement.WebElement (session="75cab94e-bc8d-4b29-b4fa-bcb013c9fe05", element="4bd75a44-1bfc-4cf4-a39d-36e9675ec783")> is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 370, in test_change_capital_rename_co_author - self.assertTrue(fs.isfile(os.path.join('test', 'hector Gonçalves/book9 (11)', -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 81, in test_bookslist_edit_title - bl = self.get_books_list(-1) - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1898, in get_books_list - element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" -IndexError: list index out of range-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 331, in test_list_visibility - self.assertEqual(22, len(bl['table'][0])) -AssertionError: 22 != 1-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 335, in test_restricted_rights - self.assertTrue('Delete' in bl['table'][0]) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 57, in test_search_books_list - self.assertEqual(10, len(bl['table'])) -AssertionError: 10 != 1-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 38, in tearDownClass - cls.driver.get("http://127.0.0.1:" + PORTS[0]) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 449, in get - self.execute(Command.GET, {"url": url}) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute - self.error_handler.check_response(response) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response - raise exception_class(message, screen, stacktrace) -selenium.common.exceptions.TimeoutException: Message: Navigation timed out after 300000 ms -Stacktrace: -RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 -WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5 -TimeoutError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:740:5 -bail@chrome://remote/content/marionette/sync.sys.mjs:211:19-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_pip_install.py", line 36, in setUpClass - args = make_release.parse_arguments(['-p']) -NameError: name 'make_release' is not defined-