From db91577485eaa0dd67d2c9f0a5668251b427cf78 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 11 Dec 2020 13:34:29 +0100 Subject: [PATCH] Use calibre-web folder in tempdir on upload cover and metadata backup fix upload cover on windows (slash vs. backslash) --- cps/gdrive.py | 15 +- cps/helper.py | 11 +- test/Calibre-Web TestSummary_Windows.html | 547 ++++++++++------------ 3 files changed, 256 insertions(+), 317 deletions(-) diff --git a/cps/gdrive.py b/cps/gdrive.py index e2b6298d..a4df41dd 100644 --- a/cps/gdrive.py +++ b/cps/gdrive.py @@ -125,7 +125,7 @@ def on_received_watch_confirmation(): if request.headers.get('X-Goog-Channel-Token') != gdrive_watch_callback_token \ or request.headers.get('X-Goog-Resource-State') != 'change' \ or not request.data: - return '' # redirect(url_for('admin.configuration')) + return '' log.debug('%r', request.headers) log.debug('%r', request.data) @@ -143,14 +143,17 @@ def on_received_watch_confirmation(): dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode() if not response['deleted'] and response['file']['title'] == 'metadata.db' \ and response['file']['md5Checksum'] != hashlib.md5(dbpath): - tmpDir = tempfile.gettempdir() + tmp_dir = os.path.join(tempfile.gettempdir(), 'calibre_web') + if not os.path.isdir(tmp_dir): + os.mkdir(tmp_dir) + log.info('Database file updated') - copyfile(dbpath, os.path.join(tmpDir, "metadata.db_" + str(current_milli_time()))) + copyfile(dbpath, os.path.join(tmp_dir, "metadata.db_" + str(current_milli_time()))) log.info('Backing up existing and downloading updated metadata.db') - gdriveutils.downloadFile(None, "metadata.db", os.path.join(tmpDir, "tmp_metadata.db")) + gdriveutils.downloadFile(None, "metadata.db", os.path.join(tmp_dir, "tmp_metadata.db")) log.info('Setting up new DB') - # prevent error on windows, as os.rename does on exisiting files - move(os.path.join(tmpDir, "tmp_metadata.db"), dbpath) + # prevent error on windows, as os.rename does on existing files, also allow cross hdd move + move(os.path.join(tmp_dir, "tmp_metadata.db"), dbpath) calibre_db.reconnect_db(config, ub.app_DB_path) except Exception as e: log.exception(e) diff --git a/cps/helper.py b/cps/helper.py index e5197fb0..95943f2f 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -634,11 +634,14 @@ def save_cover(img, book_path): return False, _("Only jpg/jpeg files are supported as coverfile") if config.config_use_google_drive: - tmpDir = gettempdir() - ret, message = save_cover_from_filestorage(tmpDir, "uploaded_cover.jpg", img) + tmp_dir = os.path.join(gettempdir(), 'calibre_web') + + if not os.path.isdir(tmp_dir): + os.mkdir(tmp_dir) + ret, message = save_cover_from_filestorage(tmp_dir, "uploaded_cover.jpg", img) if ret is True: - gd.uploadFileToEbooksFolder(os.path.join(book_path, 'cover.jpg'), - os.path.join(tmpDir, "uploaded_cover.jpg")) + gd.uploadFileToEbooksFolder(os.path.join(book_path, 'cover.jpg').replace("\\","/"), + os.path.join(tmp_dir, "uploaded_cover.jpg")) log.info("Cover is saved on Google Drive") return True, None else: diff --git a/test/Calibre-Web TestSummary_Windows.html b/test/Calibre-Web TestSummary_Windows.html index 0c4136ea..f2378fc7 100644 --- a/test/Calibre-Web TestSummary_Windows.html +++ b/test/Calibre-Web TestSummary_Windows.html @@ -37,20 +37,20 @@
-

Start Time: 2020-12-02 18:51:45

+

Start Time: 2020-12-11 09:26:17

-

Stop Time: 2020-12-02 21:19:42

+

Stop Time: 2020-12-11 12:06:47

-

Duration: 1h 56 min

+

Duration: 2h 9 min

@@ -360,9 +360,9 @@
Traceback (most recent call last):
-  File "C:\Entwicklung\calibre-web-test\test\test_cover_edit_books.py", line 92, in test_upload_jpg
-    self.assertTrue(self.check_element_on_page((By.ID, 'flash_alert')), "BMP file is not detected")
-AssertionError: False is not true : BMP file is not detected
+ File "C:\Entwicklung\calibre-web-test\test\test_cover_edit_books.py", line 76, in test_upload_jpg + self.assertGreater(diff('web.png', 'jpg.png', delete_diff_file=True), 0.007) +AssertionError: 0.005610772603121106 not greater than 0.007
@@ -766,12 +766,12 @@ AssertionError: False is not true : BMP file is not detected - + TestEditAdditionalBooks 13 - 10 + 11 + 0 0 - 1 2 Detail @@ -843,33 +843,11 @@ AssertionError: False is not true : BMP file is not detected - +
TestEditAdditionalBooks - test_title_sort
- -
- ERROR -
- - - - + PASS @@ -954,11 +932,11 @@ AttributeError: 'bool' object has no attribute 'send_keys' - + TestEditBooks 33 - 31 - 0 + 30 + 1 0 2 @@ -1290,11 +1268,31 @@ AttributeError: 'bool' object has no attribute 'send_keys' - +
TestEditBooks - test_upload_cover_hdd
- PASS + +
+ FAIL +
+ + + + @@ -1345,8 +1343,8 @@ AttributeError: 'bool' object has no attribute 'send_keys' TestEditBooksOnGdrive 20 - 18 - 2 + 19 + 1 0 0 @@ -1535,7 +1533,7 @@ AttributeError: 'bool' object has no attribute 'send_keys'
Traceback (most recent call last):
-  File "C:\Entwicklung\calibre-web-test\test\test_edit_ebooks_gdrive.py", line 700, in test_upload_cover_hdd
+  File "C:\Entwicklung\calibre-web-test\test\test_edit_ebooks_gdrive.py", line 706, in test_upload_cover_hdd
     self.assertGreater(diff('original.png', 'jpeg.png', delete_diff_file=True), 0.02)
 AssertionError: 0.0 not greater than 0.02
@@ -1547,31 +1545,11 @@ AssertionError: 0.0 not greater than 0.02 - +
TestEditBooksOnGdrive - test_watch_metadata
- -
- FAIL -
- - - - + PASS @@ -1843,13 +1821,13 @@ AssertionError: False is not true TestLdapLogin - 12 - 12 + 13 + 13 0 0 0 - Detail + Detail @@ -1902,7 +1880,7 @@ AssertionError: False is not true -
TestLdapLogin - test_LDAP_login
+
TestLdapLogin - test_LDAP_import_memberfield
PASS @@ -1911,7 +1889,7 @@ AssertionError: False is not true -
TestLdapLogin - test_invalid_LDAP
+
TestLdapLogin - test_LDAP_login
PASS @@ -1920,7 +1898,7 @@ AssertionError: False is not true -
TestLdapLogin - test_ldap_about
+
TestLdapLogin - test_invalid_LDAP
PASS @@ -1929,7 +1907,7 @@ AssertionError: False is not true -
TestLdapLogin - test_ldap_authentication
+
TestLdapLogin - test_ldap_about
PASS @@ -1938,7 +1916,7 @@ AssertionError: False is not true -
TestLdapLogin - test_ldap_kobo_sync
+
TestLdapLogin - test_ldap_authentication
PASS @@ -1947,7 +1925,7 @@ AssertionError: False is not true -
TestLdapLogin - test_ldap_opds_anonymous
+
TestLdapLogin - test_ldap_kobo_sync
PASS @@ -1955,6 +1933,15 @@ AssertionError: False is not true + +
TestLdapLogin - test_ldap_opds_anonymous
+ + PASS + + + + +
TestLdapLogin - test_ldap_opds_download_book
@@ -2422,8 +2409,8 @@ AssertionError: False is not true TestReader 5 - 3 - 2 + 4 + 1 0 0 @@ -2477,9 +2464,9 @@ AssertionError: False is not true
Traceback (most recent call last):
-  File "C:\Entwicklung\calibre-web-test\test\test_reader.py", line 189, in test_sound_listener
+  File "C:\Entwicklung\calibre-web-test\test\test_reader.py", line 193, in test_sound_listener
     self.sound_test('music.flac', 'Unknown - music', '0:02')
-  File "C:\Entwicklung\calibre-web-test\test\test_reader.py", line 176, in sound_test
+  File "C:\Entwicklung\calibre-web-test\test\test_reader.py", line 180, in sound_test
     self.assertEqual(title, title_item.text)
 AssertionError: 'Unknown - music' != '✖ ✖ Unknown - music'
 - Unknown - music
@@ -2494,31 +2481,11 @@ AssertionError: 'Unknown - music' != '✖ ✖ Unknown - music'
     
     
     
-        
+        
             
                 
TestReader - test_txt_reader
- -
- FAIL -
- - - - + PASS @@ -2809,7 +2776,7 @@ AssertionError: False is not true : Encoding of textfile viewer is not respected
Traceback (most recent call last):
-  File "C:\Entwicklung\calibre-web-test\test\test_updater.py", line 296, in test_perform_update_stable_errors
+  File "C:\Entwicklung\calibre-web-test\test\test_updater.py", line 298, in test_perform_update_stable_errors
     performUpdate.click()
   File "C:\Entwicklung\calibre-web-test\test\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
     self._execute(Command.CLICK_ELEMENT)
@@ -2865,6 +2832,84 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element 
+        TestUserLoad
+        1
+        1
+        0
+        0
+        0
+        
+            Detail
+        
+    
+
+    
+    
+        
+            
+                
TestUserLoad - test_user_change_vis
+ + PASS + + + + + + + _ErrorHolder + 1 + 0 + 0 + 1 + 0 + + Detail + + + + + + + +
tearDownClass (test_user_load)
+ + +
+ ERROR +
+ + + + + + + + + TestUserTemplate 21 @@ -2873,13 +2918,13 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element 0 0 - Detail + Detail - +
TestUserTemplate - test_allow_column_restriction
@@ -2888,7 +2933,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_allow_tag_restriction
@@ -2897,7 +2942,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_archived_format_template
@@ -2906,7 +2951,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_author_user_template
@@ -2915,7 +2960,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_best_user_template
@@ -2924,7 +2969,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_category_user_template
@@ -2933,7 +2978,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_deny_column_restriction
@@ -2942,7 +2987,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_deny_tag_restriction
@@ -2951,7 +2996,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_detail_random_user_template
@@ -2960,7 +3005,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_download_user_template
@@ -2969,7 +3014,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_format_user_template
@@ -2978,7 +3023,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_hot_user_template
@@ -2987,7 +3032,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_language_user_template
@@ -2996,7 +3041,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_limit_book_languages
@@ -3005,7 +3050,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_list_user_template
@@ -3014,7 +3059,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_publisher_user_template
@@ -3023,7 +3068,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_random_user_template
@@ -3032,7 +3077,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_read_user_template
@@ -3041,7 +3086,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_recent_user_template
@@ -3050,7 +3095,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_series_user_template
@@ -3059,7 +3104,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestUserTemplate - test_ui_language_settings
@@ -3069,21 +3114,21 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element + TestCalibreWebVisibilitys 33 - 31 + 33 + 0 0 - 2 0 - Detail + Detail - +
TestCalibreWebVisibilitys - test_about
@@ -3092,7 +3137,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_SMTP_Settings
@@ -3101,7 +3146,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_add_user
@@ -3110,7 +3155,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_password
@@ -3119,7 +3164,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_archived
@@ -3128,7 +3173,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_authors
@@ -3137,7 +3182,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_category
@@ -3146,7 +3191,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_file_formats
@@ -3155,7 +3200,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_hot
@@ -3164,7 +3209,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_language
@@ -3173,7 +3218,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_publisher
@@ -3182,7 +3227,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_random
@@ -3191,7 +3236,7 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_rated
@@ -3200,77 +3245,25 @@ selenium.common.exceptions.ElementNotInteractableException: Message: Element +
TestCalibreWebVisibilitys - test_admin_change_visibility_rating
- -
- ERROR -
- - - - + PASS - +
TestCalibreWebVisibilitys - test_admin_change_visibility_read
- -
- - - - + PASS - +
TestCalibreWebVisibilitys - test_admin_change_visibility_series
@@ -3279,7 +3272,7 @@ TypeError: object of type 'bool' has no len()
- +
TestCalibreWebVisibilitys - test_allow_columns
@@ -3288,7 +3281,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_allow_tags
@@ -3297,7 +3290,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_archive_books
@@ -3306,7 +3299,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_authors_max_settings
@@ -3315,7 +3308,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_change_title
@@ -3324,7 +3317,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_checked_logged_in
@@ -3333,7 +3326,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_hide_custom_column
@@ -3342,7 +3335,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_link_column_to_read_status
@@ -3351,7 +3344,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_random_books_available
@@ -3360,7 +3353,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_restrict_columns
@@ -3369,7 +3362,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_restrict_tags
@@ -3378,7 +3371,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_save_views_recent
@@ -3387,7 +3380,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_search_functions
@@ -3396,7 +3389,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_search_order
@@ -3405,7 +3398,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_search_string
@@ -3414,7 +3407,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_user_email_available
@@ -3423,7 +3416,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreWebVisibilitys - test_user_visibility_sidebar
@@ -3441,13 +3434,13 @@ TypeError: object of type 'bool' has no len() 0 0 - Detail + Detail - +
TestCalibreHelper - test_author_sort
@@ -3456,7 +3449,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_author_sort_comma
@@ -3465,7 +3458,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_author_sort_junior
@@ -3474,7 +3467,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_author_sort_oneword
@@ -3483,7 +3476,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_author_sort_roman
@@ -3492,7 +3485,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_Limit_Length
@@ -3501,7 +3494,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_char_replacement
@@ -3510,7 +3503,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_chinese_Characters
@@ -3519,7 +3512,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_deg_eur_replacement
@@ -3528,7 +3521,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_doubleS
@@ -3537,7 +3530,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_finish_Dot
@@ -3546,7 +3539,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_high23
@@ -3555,7 +3548,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_check_umlauts
@@ -3564,7 +3557,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_random_password
@@ -3573,7 +3566,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_split_authors
@@ -3582,7 +3575,7 @@ TypeError: object of type 'bool' has no len() - +
TestCalibreHelper - test_whitespaces
@@ -3593,10 +3586,10 @@ TypeError: object of type 'bool' has no len() Total - 290 - 267 - 5 + 293 + 273 4 + 2 14   @@ -3631,13 +3624,13 @@ TypeError: object of type 'bool' has no len() Python - 3.8.3 + 3.8.6 Basic Babel - 2.8.0 + 2.8.1 Basic @@ -3655,7 +3648,7 @@ TypeError: object of type 'bool' has no len() Flask-Babel - 1.0.0 + 2.0.0 Basic @@ -3683,24 +3676,6 @@ TypeError: object of type 'bool' has no len() Basic - - natsort - 7.0.1 - Basic - - - - pyasn1 - 0.4.8 - Basic - - - - pyasn1-modules - 0.2.8 - Basic - - PyPDF2 1.26.0 @@ -3709,19 +3684,13 @@ TypeError: object of type 'bool' has no len() pytz - 2020.1 + 2020.4 Basic requests - 2.23.0 - Basic - - - - rsa - 4.6 + 2.24.0 Basic @@ -3739,13 +3708,13 @@ TypeError: object of type 'bool' has no len() SQLAlchemy - 1.3.19 + 1.3.20 Basic tornado - 6.0.4 + 6.1 Basic @@ -3755,15 +3724,9 @@ TypeError: object of type 'bool' has no len() Basic - - uritemplate - 3.0.1 - Basic - - Wand - 0.5.9 + 0.6.5 Basic @@ -3773,12 +3736,6 @@ TypeError: object of type 'bool' has no len() Basic - - Pillow - 8.0.1 - TestCoverEditBooks - - google-api-python-client 1.12.8 @@ -3804,14 +3761,8 @@ TypeError: object of type 'bool' has no len() - Pillow - 8.0.1 - TestEbookConvertCalibreGDrive - - - - PyDrive - 1.3.1 + PyDrive2 + 1.7.0 TestEbookConvertCalibreGDrive @@ -3833,12 +3784,6 @@ TypeError: object of type 'bool' has no len() TestEditAdditionalBooks - - Pillow - 8.0.1 - TestEditAdditionalBooks - - rarfile 4.0 @@ -3851,12 +3796,6 @@ TypeError: object of type 'bool' has no len() TestEditBooks - - Pillow - 8.0.1 - TestEditBooks - - google-api-python-client 1.12.8 @@ -3882,14 +3821,8 @@ TypeError: object of type 'bool' has no len() - Pillow - 8.0.1 - TestEditBooksOnGdrive - - - - PyDrive - 1.3.1 + PyDrive2 + 1.7.0 TestEditBooksOnGdrive @@ -3918,8 +3851,8 @@ TypeError: object of type 'bool' has no len() - PyDrive - 1.3.1 + PyDrive2 + 1.7.0 TestSetupGdrive @@ -3973,7 +3906,7 @@ TypeError: object of type 'bool' has no len()