mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 02:27:22 +00:00
Updated test results
Fix updater Added comment regarding code taken from calibre source
This commit is contained in:
parent
f6b46bb170
commit
3123a914a4
@ -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)
|
||||
|
@ -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
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user