mirror of
https://codeberg.org/vlw/3rd.git
synced 2026-01-11 22:36:01 +01:00
This PR refactors the config file structure into a simpler format, as well as making it more capable at the same time. Config values are now accessed as properties instead of referenced on the parsed config JSON list directly. Config files are also loaded with the `-i` argument which can take any compatible JSON file, this replaces the previous `-a` (autorun) argument. Reviewed-on: https://codeberg.org/vlw/3rd/pulls/1 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
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}")
|