From 99c41b1370b73725b09a945065056515917311d3 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 1 Jan 2026 13:28:32 +0100 Subject: [PATCH] fix: resolved archiving issues after 2.0 update --- .gitignore | 2 +- run.py | 12 +++++++++--- src/Archive/Archive.py | 10 +++++++++- src/Archive/Filesystem.py | 5 +++-- src/Config.py | 8 ++++---- src/Stdout.py | 10 +++++----- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 974fcfd..b17b62f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -.example.config.json +.config.json __pycache__ diff --git a/run.py b/run.py index 95a80d2..0544117 100644 --- a/run.py +++ b/run.py @@ -1,3 +1,4 @@ +import os import typing import argparse @@ -9,7 +10,7 @@ from src.Enums import StdoutLevel, Namespace stdout = Stdout(Namespace.CLI) -def main(file: str) -> None: +def main() -> None: """ Autorun from a config file @@ -20,7 +21,7 @@ def main(file: str) -> None: parser = argparse.ArgumentParser(description="Testing") parser.add_argument("-s", "--sleep", type=int, help="Global log sleep level") - parser.add_argument("-i", "--input", action="store_true", help="Load config file from path") + parser.add_argument("-i", "--input", help="Load config file from path",default=".config.json") parser.add_argument("-d", "--dryrun", action="store_true", help="Dry run") parser.add_argument("-l", "--log-level", type=str, help="Global log level") @@ -42,12 +43,17 @@ def main(file: str) -> None: # Set enable dry run if args.dryrun: Aws.dry_run = True + Archive.preserve_archives = True stdout.ok("Dry run enabled") stdout.log("Starting...") + if not os.path.isfile(args.input): + stdout.error(f"No config file found at path: '{args.input}'") + exit(1) + for item in Config.from_json_file(args.input): - Archive(item) + Aws(Archive(item)).upload() stdout.log("Finished!") diff --git a/src/Archive/Archive.py b/src/Archive/Archive.py index 406c114..5f72f1c 100644 --- a/src/Archive/Archive.py +++ b/src/Archive/Archive.py @@ -6,10 +6,12 @@ import subprocess from ..Cli import Cli from ..Stdout import Stdout from ..Config import Config -from .Filesystem import PATH_MANIFEST, Filesystem +from .Filesystem import Filesystem from ..Enums import Namespace, Format, StdoutLevel class Archive(): + preserve_archives = False + def __init__(self, item: Config): """ Create a new Archive instance for a target item @@ -46,6 +48,9 @@ class Archive(): Remove archive file """ + if Archive.preserve_archives: + return + os.remove(self.output_path) self.__stdout.info(f"Archive removed: {self.output_path}") @@ -56,6 +61,8 @@ class Archive(): self.__stdout.warn(f"Archiving skipped for: {self.item.abspath_target}") + self.cleanup() + def __compress(self) -> None: """ Compress the target path @@ -95,3 +102,4 @@ class Archive(): self.__stdout.ok(f"Compression completed for: {self.item.abspath_target}") cmd.cleanup() + self.cleanup() diff --git a/src/Archive/Filesystem.py b/src/Archive/Filesystem.py index 440829a..5b0137d 100644 --- a/src/Archive/Filesystem.py +++ b/src/Archive/Filesystem.py @@ -33,8 +33,8 @@ class Filesystem(): paths = [] - for item in Config.pathnames: - paths.append(item["path_target_from"]) + for path in Config.pathnames: + paths.append(path) return paths @@ -71,6 +71,7 @@ class Filesystem(): Returns: str | None: Common pathname with base path or None if no common path (or is base path) """ + base_path = os.path.normpath(self.path) target_path = os.path.normpath(path) diff --git a/src/Config.py b/src/Config.py index 464be0d..700e502 100644 --- a/src/Config.py +++ b/src/Config.py @@ -39,12 +39,12 @@ class Config(): """ with open(pathname, "r") as f: - json = json.load(f) + config = json.load(f) - for item in json: + for item in config: Config.pathnames.add(item[ConfigKeys.ABSPATH_TARGET.value]) - Config.for_each(json) + return Config.for_each(config) @staticmethod def __throw_missing_key(key: ConfigKeys) -> None: @@ -83,7 +83,7 @@ class Config(): self.__item = item @property - def password(self) -> str|False: + def password(self) -> str|bool: """ Returns the password for this item, or None if unset diff --git a/src/Stdout.py b/src/Stdout.py index ee4368e..8d6d8d8 100644 --- a/src/Stdout.py +++ b/src/Stdout.py @@ -103,7 +103,7 @@ class Stdout(): """ # Bail out if stdout is disabled - if Stdout.global_level.value == StdoutLevel.NONE.value: + if self.global_level.value == StdoutLevel.NONE.value: return self.die() print(f"{Format.HEADER.value}> {self.namespace.value}:{Format.ENDC.value}{msg}{Format.ENDC.value}") @@ -136,7 +136,7 @@ class Stdout(): """ # Bail out if log level is less than verbose - if not Stdout.global_level.value >= StdoutLevel.STANDARD.value: + if not self.global_level.value >= StdoutLevel.STANDARD.value: return self.die() return self.print(f" {msg}") @@ -153,7 +153,7 @@ class Stdout(): """ # Bail out if log level is less than verbose - if not Stdout.global_level.value >= StdoutLevel.VERBOSE.value: + if not self.global_level.value >= StdoutLevel.VERBOSE.value: return self.die() return self.print(f" {msg}") @@ -170,7 +170,7 @@ class Stdout(): """ # Bail out if log level is less than verbose - if not Stdout.global_level.value >= StdoutLevel.DEBUG.value: + if not self.global_level.value >= StdoutLevel.DEBUG.value: return self.die() return self.print(f" {msg}") @@ -187,7 +187,7 @@ class Stdout(): """ # Bail out if log level is less than default - if not Stdout.global_level.value >= StdoutLevel.STANDARD.value: + if not self.global_level.value >= StdoutLevel.STANDARD.value: return self.die() return self.print(f" {Format.WARNING.value}! WARN: {msg}")