import typing from ..Cli import Cli from ..Stdout import Stdout from ..Enums import Namespace, StdoutLevel from ..Archive.Archive import Archive class Aws(): dry_run = False def __init__(self, archive: Archive): """ Create a new Aws instance Args: archive (Archive): Target Archive instance to upload to AWS """ self.archive = archive self.__stdout = Stdout(Namespace.AWS) def upload(self) -> None: """ Create a backup of an Archive instance to AWS """ self.__stdout.log(f"Starting upload of archive for: {self.archive.item.abspath_target}") self.__stdout.debug(f"Archive object: {self.archive}") args = [ "aws", "s3", "cp", self.archive.output_path, self.archive.item.abspath_destination ] if Aws.dry_run: args.append("--dryrun") if self.__stdout.global_level.value == StdoutLevel.DEBUG: args.append("--progress") cmd = Cli() cmd.run(args) if cmd.stderr: self.__stdout.error(f"Failed to upload archive for: {self.archive.item.abspath_target}") return self.__stdout.info("Cleaning up temporary files") cmd.cleanup() self.archive.cleanup() self.__stdout.ok(f"Archive uploaded: {self.archive.item.abspath_target}")