import os import argparse from typing import Union from src.Config import Config from src.Stdout import Stdout from src.Upload.Aws import Aws from src.Archive.Archive import Archive from src.Enums import StdoutLevel, Namespace from src.Archive.Filesystem import Filesystem stdout = Stdout(Namespace.CLI) def main() -> None: """ Autorun from a config file Args: file (str): Path to the config file to load """ parser = argparse.ArgumentParser(description="Testing") parser.add_argument("-s", "--sleep", type=int, help="Global log sleep level") parser.add_argument("-c", "--cache", type=Union[str, bool], help="Path to a cache file", default=True) 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") args = parser.parse_args() # Set custom global log level if args.log_level: try: Stdout.global_level = StdoutLevel[args.log_level.upper()] stdout.ok(f"Setting global log level to: {Stdout.global_level}") except KeyError: raise ValueError(f"{args.log_level} is not a valid StdoutLevel") # Set custom cache file if args.cache != Filesystem.cache_file: Filesystem.cache_file = args.cache stdout.ok(f"Using cache file: {Filesystem.cache_file}") # Set custom global sleep level if args.sleep: Stdout.global_sleep = args.sleep stdout.ok(f"Setting global log sleep level to: {Stdout.global_sleep} second(s)") # 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 = Archive(item) # Skip paths that have not been modified since last upload if not archive.fs.is_modified: stdout.log(f"'{archive.fs.path}' has not changed since last upload, moving on") continue Aws(archive.compress()).upload() stdout.log("Finished!") if __name__ == "__main__": main()