def init_runtime(store, args): store.set("runtime/config", paths.local("config.yml")) store.set("runtime/definition", paths.find_definition_file(args.deffile)) # load defaults / home configuration into variable store config = util.yaml_read(store.get("runtime/config")) store.set("global", config) if args.parallel is False: store.set("global/parallel", args.parallel) if args.verbose: store.set("global/verbose", True) # merge with arguments from commandline for define in [d.split("=") for d in args.defines]: if len(define) != 2: warn("Invalid variable definition detected") warn("Use -Dscope/variable=value") return 1 store.set(define[0], util.convert_type(define[1])) for envvar in filter(lambda x: x.startswith("XII_"), os.environ): store.set(envvar[4:], os.environ[envvar])
def test_convert_type(): tests = [ ("True", True), ("true", True), ("False", False), ("false", False), ("123", 123), ("foo", "foo") ] for test, result in tests: assert(util.convert_type(test) == result)
def init_defines(store, args): # merge with arguments from commandline for define in [d.split("=") for d in args.defines]: if len(define) != 2: warn("Invalid variable definition detected") warn("Use -Dscope/variable=value") return 1 store.set(define[0], util.convert_type(define[1])) # merge with arguments from environment for envvar in filter(lambda x: x.startswith("XII_"), os.environ): store.set(envvar[4:], os.environ[envvar])
def run_cli(): extension.load_builtin() parser = cli_arg_parser() try: # prepare local environment xii runs in paths.prepare_local_paths() # parse arguments cli_args = parser.parse_args() # load variable store store = Store() store.set("runtime/config", paths.local("config.yml")) store.set("runtime/definition", paths.find_definition_file(cli_args.deffile)) # load defaults / home configuration into variable store config = util.yaml_read(store.get("runtime/config")) store.set("global", config) if cli_args.parallel is False: store.set("global/parallel", cli_args.parallel) # merge with arguments from commandline for define in [d.split("=") for d in cli_args.defines]: if len(define) != 2: warn("Invalid variable definition detected") warn("Use -Dscope/variable=value") return 1 store.set(define[0], util.convert_type(define[1])) for envvar in filter(lambda x: x.startswith("XII_"), os.environ): print("define {} = {}".format(envvar[4:], os.environ[envvar])) store.set(envvar[4:], os.environ[envvar]) # parse definifition file defn = util.jinja_read(store.get("runtime/definition"), store) # construct component configurations definition.prepare_store(defn, store) # run command instance = command.Register.get(cli_args.command, cli_args.command_args, store) # return exit code if not instance: warn("Invalid command `{}`. Command not unknown.".format(cli_args.command)) return 1 return instance.run() except Interrupted: warn("interrupted... stopping immediately!") return 1 except XiiError as e: it = iter(e.error()) warn(e.error_title() + ": " + next(it)) for line in it: warn(line) if cli_args.debug: store.dump() return 1