From cfb09c29de86f3cf7f9a5d442092d54c7aa9797e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 12:28:25 +0100 Subject: [PATCH] simplify main script --- scripts/ucloud | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/scripts/ucloud b/scripts/ucloud index 1bb752b..277bf2e 100755 --- a/scripts/ucloud +++ b/scripts/ucloud @@ -1,49 +1,34 @@ #!/usr/bin/env python3 import argparse -import multiprocessing as mp import logging +import importlib -from os.path import join as join_path -from ucloud.sanity_checks import check +# For the exception +import decouple +import sys + +COMMANDS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata'] if __name__ == "__main__": + log = logging.getLogger("ucloud") + arg_parser = argparse.ArgumentParser(prog='ucloud', description='Open Source Cloud Management Software') - arg_parser.add_argument('component', - choices=['api', 'scheduler', 'host', - 'filescanner', 'imagescanner', - 'metadata']) + arg_parser.add_argument('component', choices=COMMANDS) arg_parser.add_argument('component_args', nargs='*') args = arg_parser.parse_args() try: - if args.component == 'api': - from ucloud.api.main import main + name = args.component - main() - elif args.component == 'host': - from ucloud.host.main import main + mod = importlib.import_module("ucloud.{}.main".format(name)) + main = getattr(mod, "main") + main() - hostname = args.component_args - mp.set_start_method('spawn') - main(*hostname) - elif args.component == 'scheduler': - from ucloud.scheduler.main import main - - main() - elif args.component == 'filescanner': - from ucloud.filescanner.main import main - - main() - elif args.component == 'imagescanner': - from ucloud.imagescanner.main import main - - main() - elif args.component == 'metadata': - from ucloud.metadata.main import main - - main() + except decouple.UndefinedValueError as e: + print(e) + sys.exit(1) except Exception as e: logging.exception(e)