diff --git a/cps/services/Metadata.py b/cps/services/Metadata.py index f4a5662c..ab4fd482 100644 --- a/cps/services/Metadata.py +++ b/cps/services/Metadata.py @@ -72,6 +72,10 @@ class Metadata: ) -> Generator[str, None, None]: """ Taken from calibre source code + It's a simplified (cut out what is unnecessary) version of + https://github.com/kovidgoyal/calibre/blob/99d85b97918625d172227c8ffb7e0c71794966c0/ + src/calibre/ebooks/metadata/sources/base.py#L363-L367 + (src/calibre/ebooks/metadata/sources/base.py - lines 363-398) """ title_patterns = [ (re.compile(pat, re.IGNORECASE), repl) diff --git a/cps/updater.py b/cps/updater.py index 1e11ff78..2166b334 100644 --- a/cps/updater.py +++ b/cps/updater.py @@ -182,29 +182,30 @@ class Updater(threading.Thread): return rf @classmethod - def check_permissions(cls, root_src_dir, root_dst_dir, logfunction): + def check_permissions(cls, root_src_dir, root_dst_dir, log_function): access = True remove_path = len(root_src_dir) + 1 for src_dir, __, files in os.walk(root_src_dir): root_dir = os.path.join(root_dst_dir, src_dir[remove_path:]) - # Skip non existing folders on check - if not os.path.isdir(root_dir): # root_dir.lstrip(os.sep).startswith('.') or + # Skip non-existing folders on check + if not os.path.isdir(root_dir): continue - if not os.access(root_dir, os.R_OK|os.W_OK): - logfunction("Missing permissions for {}".format(root_dir)) + if not os.access(root_dir, os.R_OK | os.W_OK): + log_function("Missing permissions for {}".format(root_dir)) access = False for file_ in files: curr_file = os.path.join(root_dir, file_) - # Skip non existing files on check - if not os.path.isfile(curr_file): # or curr_file.startswith('.'): + # Skip non-existing files on check + if not os.path.isfile(curr_file): # or curr_file.startswith('.'): continue - if not os.access(curr_file, os.R_OK|os.W_OK): - logfunction("Missing permissions for {}".format(curr_file)) + if not os.access(curr_file, os.R_OK | os.W_OK): + log_function("Missing permissions for {}".format(curr_file)) access = False return access @classmethod - def moveallfiles(cls, root_src_dir, root_dst_dir): + def move_all_files(cls, root_src_dir, root_dst_dir): + permission = None new_permissions = os.stat(root_dst_dir) log.debug('Performing Update on OS-System: %s', sys.platform) change_permissions = not (sys.platform == "win32" or sys.platform == "darwin") @@ -257,9 +258,10 @@ class Updater(threading.Thread): # destination files old_list = list() exclude = self._add_excluded_files(log.info) - additional_path =self.is_venv() + additional_path = self.is_venv() if additional_path: exclude.append(additional_path) + exclude = tuple(exclude) # check if we are in a package, rename cps.py to __init__.py if constants.HOME_CONFIG: shutil.move(os.path.join(source, 'cps.py'), os.path.join(source, '__init__.py')) @@ -284,7 +286,7 @@ class Updater(threading.Thread): remove_items = self.reduce_dirs(rf, new_list) if self.check_permissions(source, destination, log.debug): - self.moveallfiles(source, destination) + self.move_all_files(source, destination) for item in remove_items: item_path = os.path.join(destination, item[1:]) @@ -336,6 +338,7 @@ class Updater(threading.Thread): remaining_parents_cnt = 10 except (IndexError, KeyError): remaining_parents_cnt = None + parent_commit = None if remaining_parents_cnt is not None: while True: @@ -388,7 +391,7 @@ class Updater(threading.Thread): return status, update_data @staticmethod - def _add_excluded_files(logfunction): + def _add_excluded_files(log_function): excluded_files = [ os.sep + 'app.db', os.sep + 'calibre-web.log1', os.sep + 'calibre-web.log2', os.sep + 'gdrive.db', os.sep + 'vendor', os.sep + 'calibre-web.log', os.sep + '.git', os.sep + 'client_secrets.json', @@ -401,14 +404,14 @@ class Updater(threading.Thread): with open(os.path.join(constants.BASE_DIR, "exclude.txt"), "r") as f: lines = f.readlines() for line in lines: - proccessed_line = line.strip("\n\r ").strip("\"'").lstrip("\\/ ").\ + processed_line = line.strip("\n\r ").strip("\"'").lstrip("\\/ ").\ replace("\\", os.sep).replace("/", os.sep) - if os.path.exists(os.path.join(constants.BASE_DIR, proccessed_line)): - excluded_files.append(os.sep + proccessed_line) + if os.path.exists(os.path.join(constants.BASE_DIR, processed_line)): + excluded_files.append(os.sep + processed_line) else: - logfunction("File list for updater: {} not found".format(line)) + log_function("File list for updater: {} not found".format(line)) except (PermissionError, FileNotFoundError): - logfunction("Excluded file list for updater not found, or not accessible") + log_function("Excluded file list for updater not found, or not accessible") return excluded_files def _nightly_available_updates(self, request_method, locale): @@ -469,7 +472,7 @@ class Updater(threading.Thread): return '' def _stable_updater_set_status(self, i, newer, status, parents, commit): - if i == -1 and newer == False: + if i == -1 and newer is False: status.update({ 'update': True, 'success': True, @@ -478,7 +481,7 @@ class Updater(threading.Thread): 'history': parents }) self.updateFile = commit[0]['zipball_url'] - elif i == -1 and newer == True: + elif i == -1 and newer is True: status.update({ 'update': True, 'success': True, @@ -515,6 +518,7 @@ class Updater(threading.Thread): return status, parents def _stable_available_updates(self, request_method): + status = None if request_method == "GET": parents = [] # repository_url = 'https://api.github.com/repos/flatpak/flatpak/releases' # test URL @@ -559,7 +563,7 @@ class Updater(threading.Thread): except ValueError: current_version[2] = int(current_version[2].split(' ')[0])-1 - # Check if major versions are identical search for newest non equal commit and update to this one + # Check if major versions are identical search for newest non-equal commit and update to this one if major_version_update == current_version[0]: if (minor_version_update == current_version[1] and patch_version_update > current_version[2]) or \ @@ -572,7 +576,7 @@ class Updater(threading.Thread): i -= 1 continue if major_version_update > current_version[0]: - # found update update to last version before major update, unless current version is on last version + # found update to last version before major update, unless current version is on last version # before major update if i == (len(commit) - 1): i -= 1 diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 9fc44030..0004c7a0 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2022-01-27 10:57:52

+

Start Time: 2022-01-29 21:23:00

-

Stop Time: 2022-01-27 14:58:14

+

Stop Time: 2022-01-30 01:22:23

-

Duration: 3h 19 min

+

Duration: 3h 18 min

@@ -236,13 +236,13 @@ TestCli - 8 - 8 + 9 + 9 0 0 0 - Detail + Detail @@ -304,7 +304,7 @@ -
TestCli - test_environ_port_setting
+
TestCli - test_dryrun_update
PASS @@ -312,6 +312,15 @@ + +
TestCli - test_environ_port_setting
+ + PASS + + + + +
TestCli - test_settingsdb_not_writeable
@@ -411,11 +420,11 @@ - + TestEbookConvertCalibre 15 - 15 - 0 + 14 + 1 0 0 @@ -461,11 +470,33 @@ - +
TestEbookConvertCalibre - test_convert_only
- PASS + +
+ FAIL +
+ + + + @@ -1273,6 +1304,30 @@ + + TestEditAuthors + 1 + 1 + 0 + 0 + 0 + + Detail + + + + + + + +
TestEditAuthors - test_change_capital
+ + PASS + + + + + TestEditBooksList 18 @@ -1281,13 +1336,13 @@ 0 0 - Detail + Detail - +
TestEditBooksList - test_bookslist_edit_author
@@ -1296,7 +1351,7 @@ - +
TestEditBooksList - test_bookslist_edit_categories
@@ -1305,7 +1360,7 @@ - +
TestEditBooksList - test_bookslist_edit_comment
@@ -1314,7 +1369,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_category
@@ -1323,7 +1378,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_comment
@@ -1332,7 +1387,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_enum
@@ -1341,7 +1396,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_float
@@ -1350,7 +1405,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_int
@@ -1359,7 +1414,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_ratings
@@ -1368,7 +1423,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_text
@@ -1377,7 +1432,7 @@ - +
TestEditBooksList - test_bookslist_edit_languages
@@ -1386,7 +1441,7 @@ - +
TestEditBooksList - test_bookslist_edit_publisher
@@ -1395,7 +1450,7 @@ - +
TestEditBooksList - test_bookslist_edit_series
@@ -1404,7 +1459,7 @@ - +
TestEditBooksList - test_bookslist_edit_seriesindex
@@ -1413,7 +1468,7 @@ - +
TestEditBooksList - test_bookslist_edit_title
@@ -1422,7 +1477,7 @@ - +
TestEditBooksList - test_list_visibility
@@ -1431,7 +1486,7 @@ - +
TestEditBooksList - test_restricted_rights
@@ -1440,7 +1495,7 @@ - +
TestEditBooksList - test_search_books_list
@@ -1450,45 +1505,25 @@ - + TestLoadMetadata 1 - 0 1 0 0 + 0 - Detail + Detail - +
TestLoadMetadata - test_load_metadata
- -
- FAIL -
- - - - + PASS @@ -1502,13 +1537,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 0 - Detail + Detail - +
TestEditBooksOnGdrive - test_download_book
@@ -1517,7 +1552,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_author
@@ -1526,7 +1561,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_category
@@ -1535,7 +1570,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_comments
@@ -1544,7 +1579,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_bool
@@ -1553,7 +1588,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_categories
@@ -1562,7 +1597,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_float
@@ -1571,7 +1606,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_int
@@ -1580,7 +1615,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_rating
@@ -1589,7 +1624,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_single_select
@@ -1598,7 +1633,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_custom_text
@@ -1607,7 +1642,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_language
@@ -1616,7 +1651,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_publisher
@@ -1625,7 +1660,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_rating
@@ -1634,7 +1669,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_series
@@ -1643,7 +1678,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_edit_title
@@ -1652,7 +1687,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_upload_book_epub
@@ -1661,7 +1696,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_upload_book_lit
@@ -1670,7 +1705,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_upload_cover_hdd
@@ -1679,7 +1714,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestEditBooksOnGdrive - test_watch_metadata
@@ -1689,25 +1724,45 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - + TestLoadMetadataScholar 1 - 1 0 + 1 0 0 - Detail + Detail - +
TestLoadMetadataScholar - test_load_metadata
- PASS + +
+ FAIL +
+ + + + @@ -1721,13 +1776,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 0 - Detail + Detail - +
TestSTARTTLS - test_STARTTLS
@@ -1736,7 +1791,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSTARTTLS - test_STARTTLS_SSL_setup_error
@@ -1745,7 +1800,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSTARTTLS - test_STARTTLS_resend_password
@@ -1763,13 +1818,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 0 - Detail + Detail - +
TestSSL - test_SSL_None_setup_error
@@ -1778,7 +1833,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_SSL_STARTTLS_setup_error
@@ -1787,7 +1842,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_SSL_logging_email
@@ -1796,7 +1851,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_SSL_non_admin_user
@@ -1805,7 +1860,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_SSL_only
@@ -1814,7 +1869,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_email_limit
@@ -1823,7 +1878,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestSSL - test_filepicker_two_file
@@ -1841,13 +1896,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 0 - Detail + Detail - +
TestBookDatabase - test_invalid_book_path
@@ -1865,13 +1920,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 0 - Detail + Detail - +
TestErrorReadColumn - test_invalid_custom_column
@@ -1880,7 +1935,7 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestErrorReadColumn - test_invalid_custom_read_column
@@ -1898,13 +1953,13 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 0 1 - Detail + Detail - +
TestFilePicker - test_filepicker_limited_file
@@ -1913,19 +1968,19 @@ AssertionError: 0.05971028028146742 not less than or equal to 0.001 - +
TestFilePicker - test_filepicker_new_file
- SKIP + SKIP
-