1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 10:37:23 +00:00

Updated test results

Fix updater
Added comment regarding code taken from calibre source
This commit is contained in:
Ozzie Isaacs 2022-01-30 10:57:29 +01:00
parent f6b46bb170
commit 3123a914a4
3 changed files with 615 additions and 402 deletions

View File

@ -72,6 +72,10 @@ class Metadata:
) -> Generator[str, None, None]: ) -> Generator[str, None, None]:
""" """
Taken from calibre source code 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 = [ title_patterns = [
(re.compile(pat, re.IGNORECASE), repl) (re.compile(pat, re.IGNORECASE), repl)

View File

@ -182,29 +182,30 @@ class Updater(threading.Thread):
return rf return rf
@classmethod @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 access = True
remove_path = len(root_src_dir) + 1 remove_path = len(root_src_dir) + 1
for src_dir, __, files in os.walk(root_src_dir): for src_dir, __, files in os.walk(root_src_dir):
root_dir = os.path.join(root_dst_dir, src_dir[remove_path:]) root_dir = os.path.join(root_dst_dir, src_dir[remove_path:])
# Skip non existing folders on check # Skip non-existing folders on check
if not os.path.isdir(root_dir): # root_dir.lstrip(os.sep).startswith('.') or if not os.path.isdir(root_dir):
continue continue
if not os.access(root_dir, os.R_OK|os.W_OK): if not os.access(root_dir, os.R_OK | os.W_OK):
logfunction("Missing permissions for {}".format(root_dir)) log_function("Missing permissions for {}".format(root_dir))
access = False access = False
for file_ in files: for file_ in files:
curr_file = os.path.join(root_dir, file_) curr_file = os.path.join(root_dir, file_)
# Skip non existing files on check # Skip non-existing files on check
if not os.path.isfile(curr_file): # or curr_file.startswith('.'): if not os.path.isfile(curr_file): # or curr_file.startswith('.'):
continue continue
if not os.access(curr_file, os.R_OK|os.W_OK): if not os.access(curr_file, os.R_OK | os.W_OK):
logfunction("Missing permissions for {}".format(curr_file)) log_function("Missing permissions for {}".format(curr_file))
access = False access = False
return access return access
@classmethod @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) new_permissions = os.stat(root_dst_dir)
log.debug('Performing Update on OS-System: %s', sys.platform) log.debug('Performing Update on OS-System: %s', sys.platform)
change_permissions = not (sys.platform == "win32" or sys.platform == "darwin") change_permissions = not (sys.platform == "win32" or sys.platform == "darwin")
@ -257,9 +258,10 @@ class Updater(threading.Thread):
# destination files # destination files
old_list = list() old_list = list()
exclude = self._add_excluded_files(log.info) exclude = self._add_excluded_files(log.info)
additional_path =self.is_venv() additional_path = self.is_venv()
if additional_path: if additional_path:
exclude.append(additional_path) exclude.append(additional_path)
exclude = tuple(exclude)
# check if we are in a package, rename cps.py to __init__.py # check if we are in a package, rename cps.py to __init__.py
if constants.HOME_CONFIG: if constants.HOME_CONFIG:
shutil.move(os.path.join(source, 'cps.py'), os.path.join(source, '__init__.py')) 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) remove_items = self.reduce_dirs(rf, new_list)
if self.check_permissions(source, destination, log.debug): if self.check_permissions(source, destination, log.debug):
self.moveallfiles(source, destination) self.move_all_files(source, destination)
for item in remove_items: for item in remove_items:
item_path = os.path.join(destination, item[1:]) item_path = os.path.join(destination, item[1:])
@ -336,6 +338,7 @@ class Updater(threading.Thread):
remaining_parents_cnt = 10 remaining_parents_cnt = 10
except (IndexError, KeyError): except (IndexError, KeyError):
remaining_parents_cnt = None remaining_parents_cnt = None
parent_commit = None
if remaining_parents_cnt is not None: if remaining_parents_cnt is not None:
while True: while True:
@ -388,7 +391,7 @@ class Updater(threading.Thread):
return status, update_data return status, update_data
@staticmethod @staticmethod
def _add_excluded_files(logfunction): def _add_excluded_files(log_function):
excluded_files = [ excluded_files = [
os.sep + 'app.db', os.sep + 'calibre-web.log1', os.sep + 'calibre-web.log2', os.sep + 'gdrive.db', 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', 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: with open(os.path.join(constants.BASE_DIR, "exclude.txt"), "r") as f:
lines = f.readlines() lines = f.readlines()
for line in lines: 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) replace("\\", os.sep).replace("/", os.sep)
if os.path.exists(os.path.join(constants.BASE_DIR, proccessed_line)): if os.path.exists(os.path.join(constants.BASE_DIR, processed_line)):
excluded_files.append(os.sep + proccessed_line) excluded_files.append(os.sep + processed_line)
else: else:
logfunction("File list for updater: {} not found".format(line)) log_function("File list for updater: {} not found".format(line))
except (PermissionError, FileNotFoundError): 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 return excluded_files
def _nightly_available_updates(self, request_method, locale): def _nightly_available_updates(self, request_method, locale):
@ -469,7 +472,7 @@ class Updater(threading.Thread):
return '' return ''
def _stable_updater_set_status(self, i, newer, status, parents, commit): 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({ status.update({
'update': True, 'update': True,
'success': True, 'success': True,
@ -478,7 +481,7 @@ class Updater(threading.Thread):
'history': parents 'history': parents
}) })
self.updateFile = commit[0]['zipball_url'] self.updateFile = commit[0]['zipball_url']
elif i == -1 and newer == True: elif i == -1 and newer is True:
status.update({ status.update({
'update': True, 'update': True,
'success': True, 'success': True,
@ -515,6 +518,7 @@ class Updater(threading.Thread):
return status, parents return status, parents
def _stable_available_updates(self, request_method): def _stable_available_updates(self, request_method):
status = None
if request_method == "GET": if request_method == "GET":
parents = [] parents = []
# repository_url = 'https://api.github.com/repos/flatpak/flatpak/releases' # test URL # repository_url = 'https://api.github.com/repos/flatpak/flatpak/releases' # test URL
@ -559,7 +563,7 @@ class Updater(threading.Thread):
except ValueError: except ValueError:
current_version[2] = int(current_version[2].split(' ')[0])-1 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 major_version_update == current_version[0]:
if (minor_version_update == current_version[1] and if (minor_version_update == current_version[1] and
patch_version_update > current_version[2]) or \ patch_version_update > current_version[2]) or \
@ -572,7 +576,7 @@ class Updater(threading.Thread):
i -= 1 i -= 1
continue continue
if major_version_update > current_version[0]: 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 # before major update
if i == (len(commit) - 1): if i == (len(commit) - 1):
i -= 1 i -= 1

File diff suppressed because it is too large Load Diff