From cd787c3cea9681166677144a079549ba6d24b931 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 25 Mar 2024 13:09:24 +0100 Subject: [PATCH] Fix traceback in case source file does not exist. Also use f"" syntax instead of .format Signed-off-by: Petr "Stone" Hracek --- container_workflow_tool/sync.py | 17 ++++++++++------- setup.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/container_workflow_tool/sync.py b/container_workflow_tool/sync.py index 641aa77..5e833c4 100644 --- a/container_workflow_tool/sync.py +++ b/container_workflow_tool/sync.py @@ -48,17 +48,17 @@ def copy_upstream2downstream(self, src_parent, dest_parent): src = os.path.join(src_parent, f) # First remove the dest if os.path.isdir(dest): - self.logger.debug("rmtree {}".format(dest)) + self.logger.debug(f"rmtree {dest}") shutil.rmtree(dest) else: _remove_file(dest, self.logger) # Now copy the src to dest if os.path.islink(src) or not os.path.isdir(src): - self.logger.debug("cp {} {}".format(src, dest)) + self.logger.debug(f"cp {src} {dest}") shutil.copy2(src, dest, follow_symlinks=False) else: - self.logger.debug("cp -r {} {}".format(src, dest)) + self.logger.debug(f"cp -r {src} {dest}") shutil.copytree(src, dest, symlinks=True) def handle_dangling_symlinks(self, src_parent, dest_parent): @@ -95,7 +95,7 @@ def handle_dangling_symlinks(self, src_parent, dest_parent): dest_file ) src_path_content = os.path.join(src_parent, dest_path_rel) - self.logger.debug("unlink {dest}".format(dest=dest_file)) + self.logger.debug(f"unlink {dest_file}") os.unlink(dest_file) src_full = os.path.join(os.path.dirname(src_path_content), os.readlink(src_path_content)) @@ -103,9 +103,12 @@ def handle_dangling_symlinks(self, src_parent, dest_parent): # In this case, when the source directory includes another symlinks outside # of this directory, those wouldn't be fixed, so let's run the same function # to fix dangling symlinks recursively. - self.logger.debug("cp -r {src} {dest}".format(src=src_full, dest=dest_file)) + self.logger.debug(f"cp -r {src_full} {dest_file}") shutil.copytree(src_full, dest_file, symlinks=True) self.handle_dangling_symlinks(src_parent, dest_parent) else: - self.logger.debug("cp {src} {dest}".format(src=src_full, dest=dest_file)) - shutil.copy2(src_full, dest_file, follow_symlinks=False) + try: + self.logger.debug(f"cp {src_full} {dest_file}") + shutil.copy2(src_full, dest_file, follow_symlinks=False) + except FileNotFoundError: + self.logger.debug(f"Source file {src_full} does not exist") diff --git a/setup.py b/setup.py index 471237d..d267067 100755 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def get_dir(system_path=None, virtual_path=None): setup( name='container-workflow-tool', - version="1.5.5", + version="1.5.6", description='A python3 tool to make rebuilding images easier by automating several steps of the process.', long_description=long_description, long_description_content_type='text/markdown',