From 927f174df489046d76897e02e42f39f61434162c Mon Sep 17 00:00:00 2001 From: DJSchaffner Date: Wed, 23 Sep 2020 14:13:27 +0200 Subject: [PATCH] - Print debug info during backup/restore process --- src/logic.py | 5 ++--- src/utils.py | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/logic.py b/src/logic.py index 84100f7..bd99025 100644 --- a/src/logic.py +++ b/src/logic.py @@ -58,7 +58,6 @@ def __init__(self): self.patch_list = self.webhook.query_patch_list(self.app_id) self.depot_list = self.__get_depot_list() self.patch_change_list = self.webhook.query_patch_change_list() - self.process_queue = Queue() def patch(self, username: str, password: str, patch: dict, language: Languages): @@ -129,7 +128,7 @@ def restore(self): # Remove added files from the path try: print("Removing patched files") - utils.remove_patched_files(self.game_dir, self.download_dir) + utils.remove_patched_files(self.game_dir, self.download_dir, True) print("Finished removing patched files") # Copy backed up files to game path again @@ -223,7 +222,7 @@ def __backup(self): shutil.rmtree(self.backup_dir.absolute()) self.backup_dir.mkdir() - utils.backup_files(self.game_dir, self.download_dir, self.backup_dir) + utils.backup_files(self.game_dir, self.download_dir, self.backup_dir, True) return True except BaseException: diff --git a/src/utils.py b/src/utils.py index d3d945b..e7571ca 100644 --- a/src/utils.py +++ b/src/utils.py @@ -38,40 +38,54 @@ def remove_file_or_dir(dir, file): else: (dir / file).unlink(missing_ok=True) -def backup_files(original_dir: pathlib.Path, override_dir: pathlib.Path, backup_dir: pathlib.Path): +def backup_files(original_dir: pathlib.Path, override_dir: pathlib.Path, backup_dir: pathlib.Path, debug_info: bool): """Recursively performs backup of original_dir to backup_dir assuming all files/folder from override_dir will be patched.""" changed_file_list = list(set(os.listdir(original_dir.absolute())).intersection(set(os.listdir(override_dir.absolute())))) for file in changed_file_list: + # Its a folder, backup its contents if (original_dir / file).is_dir(): (backup_dir / file).mkdir() - backup_files(original_dir / file, override_dir / file, backup_dir / file) + backup_files(original_dir / file, override_dir / file, backup_dir / file, debug_info) + # Its a file, copy it else: + if debug_info: + print(f"Copying {(original_dir / file).absolute()}") + copy_file_or_dir(original_dir, backup_dir, file) -def remove_patched_files(original_dir: pathlib.Path, override_dir: pathlib.Path): +def remove_patched_files(original_dir: pathlib.Path, override_dir: pathlib.Path, debug_info: bool): """Recursively removes all patched files assuming original_dir has been patched with all files from override_dir.""" changed_file_list = os.listdir(override_dir.absolute()) # Remove all overridden files for file in changed_file_list: + # Its a folder, remove its contents if (original_dir / file).is_dir(): - remove_patched_files(original_dir / file, override_dir / file) + remove_patched_files(original_dir / file, override_dir / file, debug_info) # Remove directory if its now empty if len(os.listdir((original_dir / file).absolute())) == 0: try: + if debug_info: + print(f"Removing {(original_dir / file).absolute()}") + remove_file_or_dir(original_dir, file) except BaseException as e: raise e + # Its a file, remove it else: try: + if debug_info: + print(f"Removing {(original_dir / file).absolute()}") + remove_file_or_dir(original_dir, file) except BaseException as e: raise e def extract_date(date_string: str): """Extract a date in the format of 'd(d) Monthname yyyy'. + Returns a datetime object """ date_stripped = re.search(r"\d+ \w* \d+", date_string).group(0)