Beispiel #1
0
def main(args=None):
    rc = DEFAULT_RC
    parser = create_parser()
    ns = parser.parse_args(args)
    if ns.cmd in NEED_RC:
        if os.path.exists(rc.user_config):
            rc._update(load_rcfile(rc.user_config))
        rc._update(load_rcfile("regolithrc.json"))
    rc._update(ns.__dict__)
    if "schemas" in rc._dict:
        user_schema = copy.deepcopy(rc.schemas)
        default_schema = copy.deepcopy(SCHEMAS)
        rc.schemas = update_schemas(default_schema, user_schema)
    else:
        rc.schemas = SCHEMAS
    if ns.cmd in NEED_RC:
        filter_databases(rc)
    if rc.cmd in DISCONNECTED_COMMANDS:
        DISCONNECTED_COMMANDS[rc.cmd](rc)
    else:
        dbs = None
        if rc.cmd == 'build':
            dbs = commands.build_db_check(rc)
        with connect(rc, dbs=dbs) as rc.client:
            CONNECTED_COMMANDS[rc.cmd](rc)
Beispiel #2
0
def main(args=None):
    rc = copy.copy(DEFAULT_RC)
    parser = create_parser()
    args0 = Namespace()
    args1, rest = parser.parse_known_args(args, namespace=args0)
    if args1.version:
        print(__version__)
        return rc
    if args1.cmd == 'helper':
        p = ArgumentParser(prog='regolith helper')
        p.add_argument(
            "helper_target",
            help="helper target to run. Currently valid targets are: \n{}".
            format([k for k in HELPERS]),
        )
        if len(rest) == 0:
            p.print_help()
        args2, rest2 = p.parse_known_args(rest, namespace=args0)
        # it is not apparent from this but the following line calls the suparser in
        #   in the helper module to get the rest of the args.
        HELPERS[args2.helper_target][1](p)
        if len(rest2) == 0:
            p.print_help()
        args3, rest3 = p.parse_known_args(rest, namespace=args0)
        ns = args3
    else:
        ns = args1
    if ns.cmd in NEED_RC:
        if os.path.exists(rc.user_config):
            rc._update(load_rcfile(rc.user_config))
        rc._update(load_rcfile("regolithrc.json"))
    rc._update(ns.__dict__)
    if "schemas" in rc._dict:
        user_schema = copy.deepcopy(rc.schemas)
        default_schema = copy.deepcopy(SCHEMAS)
        rc.schemas = update_schemas(default_schema, user_schema)
    else:
        rc.schemas = SCHEMAS
    if ns.cmd in NEED_RC:
        filter_databases(rc)
    if rc.cmd in DISCONNECTED_COMMANDS:
        DISCONNECTED_COMMANDS[rc.cmd](rc)
    else:
        dbs = None
        if rc.cmd == 'build':
            dbs = commands.build_db_check(rc)
        elif rc.cmd == 'helper':
            dbs = commands.helper_db_check(rc)
        with connect(rc, dbs=dbs) as rc.client:
            CONNECTED_COMMANDS[rc.cmd](rc)
    return rc
Beispiel #3
0
def test_update_schemas(default_schema, user_schema, expected_schema):
    updated_schema = update_schemas(default_schema, user_schema)
    assert updated_schema == expected_schema