Ejemplo n.º 1
0
Archivo: cli.py Proyecto: jloehel/xii
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])
Ejemplo n.º 2
0
Archivo: cli.py Proyecto: xii/xii
def run_cli():
    try:
        # load all components
        ext_mgr = ExtensionManager()
        ext_mgr.add_builtin_path()
        ext_mgr.load()

        # prepare local environment xii runs in
        paths.prepare_local_paths()

        # load variable store
        store = Store()

        # parse cli arguments
        parser = init_cli_args_parser(ext_mgr)
        cli_args = parser.parse_args()

        # initialize store and command
        init_config(store)
        init_defines(store, cli_args)
        init_cli_settings(store, cli_args)

        if cli_args.command is None:
            parser.print_usage()
            return 0

        cmd = init_command(store, cli_args, ext_mgr)

        return cmd.run()

    except Interrupted:
        warn("interrupted... stopping immediately!")
        return 1
Ejemplo n.º 3
0
Archivo: cli.py Proyecto: xii/xii
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])
Ejemplo n.º 4
0
Archivo: cli.py Proyecto: jloehel/xii
def run_cli():
    try:

        # load all components
        ext_mgr = ExtensionManager()
        ext_mgr.add_builtin_path()
        ext_mgr.load()

        # prepare local environment xii runs in
        paths.prepare_local_paths()

        # parse arguments
        parser = cli_arg_parser(ext_mgr)
        cli_args = parser.parse_args()

        # load variable store
        store = Store()

        # initialize variables
        init_runtime(store, cli_args)

        # parse definifition file
        defn = util.jinja_read(store.get("runtime/definition"), store)

        # construct component configurations
        definition.prepare_store(defn, store)

        # get command
        cmd = ext_mgr.get_command(cli_args.command)

        if not cmd:
            warn("Invalid command `{}`. Command not unknown.".format(
                cli_args.command))
            return 1

        command_arg_parser = cmd["class"].argument_parser()
        command_args = command_arg_parser.parse_args(cli_args.command_args)

        store.set("command/args", vars(command_args))

        instance = cmd["class"](command_args, cmd["templates"], store)
        prepare_command(instance, ext_mgr)

        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)

        return 1
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def test_warn(capsys):
    output.warn("test")

    out, _ = capsys.readouterr()

    assert('[xii] test' in out)
Ejemplo n.º 7
0
def test_warn(capsys):
    output.warn("test")

    out, _ = capsys.readouterr()

    assert ('[xii] test' in out)