diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index c765b9ab..49ab5882 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -21,6 +21,7 @@ import json import shutil import chardet import ssl +import sqlite3 from flask import Response, stream_with_context from sqlalchemy import create_engine @@ -258,13 +259,17 @@ def getEbooksFolderId(drive=None): return gDriveId.gdrive_id -def getFile(pathId, fileName, drive): - metaDataFile = "'%s' in parents and trashed = false and title = '%s'" % (pathId, fileName.replace("'", r"\'")) +def getFile(pathId, fileName, drive, nocase): + metaDataFile = "'%s' in parents and trashed = false and title contains '%s'" % (pathId, fileName.replace("'", r"\'")) fileList = drive.ListFile({'q': metaDataFile}).GetList() if fileList.__len__() == 0: return None - else: + if nocase: return fileList[0] + for f in fileList: + if f['title'] == fileName: + return f + return None def getFolderId(path, drive): @@ -303,7 +308,7 @@ def getFolderId(path, drive): session.commit() else: currentFolderId = storedPathName.gdrive_id - except (OperationalError, IntegrityError, StaleDataError) as ex: + except (OperationalError, IntegrityError, StaleDataError, sqlite3.IntegrityError) as ex: log.error_or_exception('Database error: {}'.format(ex)) session.rollback() except ApiRequestError as ex: @@ -314,7 +319,7 @@ def getFolderId(path, drive): return currentFolderId -def getFileFromEbooksFolder(path, fileName): +def getFileFromEbooksFolder(path, fileName, nocase=False): drive = getDrive(Gdrive.Instance().drive) if path: # sqlCheckPath=path if path[-1] =='/' else path + '/' @@ -322,7 +327,7 @@ def getFileFromEbooksFolder(path, fileName): else: folderId = getEbooksFolderId(drive) if folderId: - return getFile(folderId, fileName, drive) + return getFile(folderId, fileName, drive, nocase) else: return None @@ -338,12 +343,12 @@ def downloadFile(path, filename, output): f.GetContentFile(output) -def moveGdriveFolderRemote(origin_file, target_folder): +def moveGdriveFolderRemote(origin_file, target_folder, single_book=False): 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: + 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"}) @@ -353,19 +358,20 @@ def moveGdriveFolderRemote(origin_file, target_folder): addParents=gFileTargetDir['id'], removeParents=previous_parents, fields='id, parents').execute() - - elif gFileTargetDir['title'] != target_folder: - deleteDatabasePath(gFileTargetDir['title']) + elif origin_file['title'] != target_folder: + #gFileTargetDir = getFileFromEbooksFolder(None, target_folder, nocase=True) + #if gFileTargetDir: + deleteDatabasePath(origin_file['title']) # Folder is not existing, create, and move folder drive.auth.service.files().patch(fileId=origin_file['id'], body={'title': target_folder}, fields='title').execute() - else: + '''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() + 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 b70cbbe0..85f1689b 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -479,7 +479,10 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth title_dir = local_book.path.split('/')[1] new_title_dir = get_valid_filename(local_book.title, chars=96) + " (" + str(book_id) + ")" - new_author_dir = get_valid_filename(new_author, chars=96) + if new_author: + new_author_dir = get_valid_filename(new_author, chars=96) + else: + new_author = new_author_dir = author_dir if title_dir != new_title_dir or author_dir != new_author_dir or original_filepath: error = move_files_on_change(calibre_path, @@ -533,9 +536,9 @@ def update_dir_structure_gdrive(book_id, first_author): return _('File %(file)s not found on Google Drive', file=book.path) # file not found if authordir != new_authordir: - g_file = gd.getFileFromEbooksFolder(os.path.dirname(book.path), new_titledir) + g_file = gd.getFileFromEbooksFolder(authordir, new_titledir) if g_file: - gd.moveGdriveFolderRemote(g_file, new_authordir) + gd.moveGdriveFolderRemote(g_file, new_authordir, single_book=True) book.path = new_authordir + '/' + book.path.split('/')[1] gd.updateDatabaseOnEdit(g_file['id'], book.path) else: diff --git a/cps/web.py b/cps/web.py index abe62c96..3e0fce9a 100644 --- a/cps/web.py +++ b/cps/web.py @@ -107,7 +107,7 @@ def add_security_headers(resp): resp.headers['X-Content-Type-Options'] = 'nosniff' resp.headers['X-Frame-Options'] = 'SAMEORIGIN' resp.headers['X-XSS-Protection'] = '1; mode=block' - resp.headers['Strict-Transport-Security'] = 'max-age=31536000;' + resp.headers['Strict-Transport-Security'] = 'max-age=31536000'; return resp diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index bb9f8214..b799e9aa 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
Start Time: 2024-06-28 20:08:21
+Start Time: 2024-06-29 20:48:57
Stop Time: 2024-06-29 02:31:07
+Stop Time: 2024-06-30 03:48:15
Duration: 5h 10 min
+Duration: 5h 44 min
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 202, in test_backup_change_book_author - self.assertEqual(["Hector Gonçalves"], metadata['author']) -AssertionError: Lists differ: ['Hector Gonçalves'] != [] - -First list contains 1 additional elements. -First extra element 0: -'Hector Gonçalves' - -- ['Hector Gonçalves'] -+ []-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 177, in test_backup_change_book_title - self.assertEqual(metadata['title'], 'The bok Lo,执|1u') -AssertionError: '' != 'The bok Lo,执|1u' -+ The bok Lo,执|1u-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli.py", line 35, in setUpClass - shutil.copytree('./Calibre_db', TEST_DB) - File "/usr/lib/python3.10/shutil.py", line 557, in copytree - with os.scandir(src) as itr: -FileNotFoundError: [Errno 2] No such file or directory: './Calibre_db'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 201, in test_cli_gdrive_folder - self.start_cw(os.path.join(CALIBRE_WEB_PATH + INDEX, u'cps.py'), gdrive_dir) - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 146, in start_cw - self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 182, in test_cli_gdrive_location - self.start_cw(os.path.join(CALIBRE_WEB_PATH + INDEX, u'cps.py'), os.path.join(gdrive_dir, u'gü dr.app')) - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 146, in start_cw - self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 150, in test_gdrive_db_nonwrite - self.start_cw(os.path.join(CALIBRE_WEB_PATH + INDEX, u'cps.py')) - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 146, in start_cw - self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 230, in test_no_database - self.assertTrue(self.check_element_on_page((By.ID, 'flash_success'))) -AssertionError: False is not true - -During handling of the above exception, another exception occurred: - -Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 237, in test_no_database - self.assertFalse(True, "Inital config failed with normal database") -AssertionError: True is not false : Inital config failed with normal database-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_additional_books.py", line 451, in test_writeonly_path - self.assertTrue(os.path.isdir(book_path)) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books.py", line 193, in test_edit_author - self.assertTrue(os.path.isdir(os.path.join(TEST_DB, 'O0u Zhi', 'book8 (8)'))) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 319, in test_change_capital_co_author - self.assertFalse(self.check_element_on_page((By.ID, "flash_danger"))) -AssertionError: <selenium.webdriver.remote.webelement.WebElement (session="2035360a-7d0e-4230-ba6e-0809c52d1958", element="cb5889ec-bf0f-4bc5-b6ce-787090088d52")> is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 131, in test_change_capital_one_author_one_book - self.assertFalse(self.check_element_on_page((By.ID, "flash_danger"))) -AssertionError: <selenium.webdriver.remote.webelement.WebElement (session="2035360a-7d0e-4230-ba6e-0809c52d1958", element="2c5e0549-fad4-4467-b5fd-80b5cabd1669")> is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 253, in test_change_capital_one_author_two_books - self.assertCountEqual(['Frodo Beutlin', 'Norbert halagal', 'Liu Yang', 'Hector Gonçalves'], details['author']) -AssertionError: Element counts were not equal: -First has 1, Second has 0: 'Liu Yang' -First has 0, Second has 1: 'Liu yang'+ 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 365, in test_change_capital_rename_co_author - self.assertTrue(fs.isfile(os.path.join('test', 'Hector Goncalves/book9 (11)', -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author_gdrive.py", line 463, in test_change_capital_rename_two_co_authors - self.assertFalse(self.check_element_on_page((By.ID, "flash_danger"))) -AssertionError: <selenium.webdriver.remote.webelement.WebElement (session="2035360a-7d0e-4230-ba6e-0809c52d1958", element="a04a321a-7396-4621-84a6-a40ec9d11340")> is not false+ 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_author_gdrive.py", line 562, in test_rename_capital_on_upload - self.assertEqual(200, ret_code) -AssertionError: 200 != 404+ 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+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_metadata.py", line 90, in test_load_metadata + elif 'https://amazon.com/' == results[20]['source']: +IndexError: list index out of range
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_metadata.py", line 173, in test_load_metadata - self.assertGreaterEqual(diff(BytesIO(cover), BytesIO(original_cover), delete_diff_file=True), 0.05) -AssertionError: 0.0 not greater than or equal to 0.05-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_ebooks_gdrive.py", line 310, in test_edit_author - self.assertEqual(u'O0ü 执', values['author'][0]) -AssertionError: 'O0ü 执' != 'Leo Baskerville' -- O0ü 执 -+ Leo Baskerville-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_ebooks_gdrive.py", line 136, in test_edit_title - self.assertEqual(u'O0ü 执', values['title']) -AssertionError: 'O0ü 执' != 'Very long extra super turbo cool title wi[54 chars]ters' -- O0ü 执 -+ Very long extra super turbo cool title without any issue of displaying including ö utf-8 characters-