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)
def test_connect_db(make_db): repo = make_db os.chdir(repo) rc = copy.copy(DEFAULT_RC) rc._update(load_rcfile("regolithrc.json")) filter_databases(rc) with connect(rc) as rc.client: expected_dbs = rc.client.dbs expected_chdb = rc.client.chained_db chained_db, dbs = connect_db(rc) assert chained_db == expected_chdb assert dbs == expected_dbs
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
""" Loads the dbs for interactive sessions """ from regolith.database import connect from regolith.runcontrol import DEFAULT_RC, load_rcfile, filter_databases rc = DEFAULT_RC rc._update(load_rcfile("regolithrc.json")) filter_databases(rc) with connect(rc) as rc.client: dbs = rc.client.dbs chained_db = rc.client.chained_db
def load_db(rc_file="regolithrc.json"): """Create a Broker instance from an rc file""" rc = copy.copy(DEFAULT_RC) rc._update(load_rcfile(rc_file)) filter_databases(rc) return Broker(rc)