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>
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import typing
|
|
import argparse
|
|
|
|
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
|
|
|
|
stdout = Stdout(Namespace.CLI)
|
|
|
|
def main(file: str) -> 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("-i", "--input", action="store_true", help="Load config file from path")
|
|
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 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 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 enable dry run
|
|
if args.dryrun:
|
|
Aws.dry_run = True
|
|
stdout.ok("Dry run enabled")
|
|
|
|
stdout.log("Starting...")
|
|
|
|
for item in Config.from_json_file(args.input):
|
|
Archive(item)
|
|
|
|
stdout.log("Finished!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|