Skip to content

Commit

Permalink
FIX: Corrected the opening process on the chained collections in data…
Browse files Browse the repository at this point in the history
…base.xsh to put collections into their respective maps rather than the outputs of the iter method.
  • Loading branch information
zthatch committed Jul 22, 2021
1 parent 64d9fff commit ac9b007
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions regolith/database.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,29 @@ def dump_database(db, client, rc):
raise ValueError('Do not know how to dump this kind of database')


def open_dbs(rc, dbs=None):
def open_dbs(rc, colls=None):
"""Open the databases
Parameters
----------
rc : RunControl instance
The rc which has links to the dbs
dbs: set or None, optional
colls: set or None, optional
The databases to load. If None load all, defaults to None
Returns
-------
client : {FileSystemClient, MongoClient}
The database client
"""
if dbs is None:
dbs = []
if colls is None:
colls = []
client = ClientManager(rc.databases, rc)
client.open()
chained_db = {}
for db in rc.databases:
# if we only want to access some dbs and this db is not in that some
db['whitelist'] = dbs
# if we only want to access some colls and this db is not in that some
db['whitelist'] = colls
if 'blacklist' not in db:
db['blacklist'] = ['.travis.yml', '.travis.yaml']
load_database(db, client, rc)
Expand All @@ -176,10 +176,10 @@ def open_dbs(rc, dbs=None):
if base not in chained_db:
chained_db[base] = ChainCollection()
for k, v in coll.items():
if k in chained_db[base]:
chained_db[base][k].maps.append(v)
if k in chained_db[base].fs_map:
chained_db[base].fs_map[k].maps.append(v)
else:
chained_db[base][k] = ChainDocument(v)
chained_db[base].fs_map[k] = ChainDocument(v)
else:
if base not in chained_db:
chained_db[base] = ChainCollection(coll)
Expand All @@ -189,10 +189,10 @@ def open_dbs(rc, dbs=None):
return client

@contextmanager
def connect(rc, dbs=None):
def connect(rc, colls=None):
"""Context manager for ensuring that database is properly setup and torn
down"""
client = open_dbs(rc, dbs=dbs)
client = open_dbs(rc, colls=colls)
yield client
for db in rc.databases:
dump_database(db, client, rc)
Expand Down
8 changes: 4 additions & 4 deletions regolith/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ def main(args=None):
if rc.cmd in DISCONNECTED_COMMANDS:
DISCONNECTED_COMMANDS[rc.cmd](rc)
else:
dbs = None
colls = None
if rc.cmd == 'build':
dbs = commands.build_db_check(rc)
colls = commands.build_db_check(rc)
elif rc.cmd == 'helper':
dbs = commands.helper_db_check(rc)
with connect(rc, dbs=dbs) as rc.client:
colls = commands.helper_db_check(rc)
with connect(rc, colls=colls) as rc.client:
CONNECTED_COMMANDS[rc.cmd](rc)


Expand Down

0 comments on commit ac9b007

Please sign in to comment.