def dump_database(self, db): """Dumps a database dict via mongoexport.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] colls = self.client[db["name"]].collection_names( include_system_collections=False) for collection in colls: f = os.path.join(dbpath, collection + ".json") cmd = [ "mongoexport", "--db", db["name"], "--collection", collection, "--out", f, ] try: subprocess.check_call(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: print("Status : FAIL", exc.returncode, exc.output) raise exc to_add.append(os.path.join(db["path"], collection + ".json")) return to_add
def load_database(self, db): """Loads a database via mongoimport. Takes a database dict db.""" dbpath = dbpathname(db, self.rc) for f in iglob(os.path.join(dbpath, '*.json')): base, ext = os.path.splitext(os.path.split(f)[-1]) cmd = ['mongoimport', '--db', db['name'], '--collection', base, '--file', f] subprocess.check_call(cmd)
def load_database(self, db): """Loads a database via mongoimport. Takes a database dict db.""" dbpath = dbpathname(db, self.rc) for f in iglob(os.path.join(dbpath, '*.json')): base, ext = os.path.splitext(os.path.split(f)[-1]) cmd = [ 'mongoimport', '--db', db['name'], '--collection', base, '--file', f ] subprocess.check_call(cmd)
def dump_database(self, db): """Dumps a database dict via mongoexport.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] colls = self.client[db['name']].collection_names( include_system_collections=False) for collection in colls: f = os.path.join(dbpath, collection + '.json') cmd = ['mongoexport', '--db', db['name'], '--collection', collection, '--out', f] subprocess.check_call(cmd) to_add.append(os.path.join(db['path'], collection + '.json')) return to_add
def import_database(self, db: dict): """Import the database from filesystem to the mongo backend. Parameters ---------- db : dict The dictionary of data base information, such as 'name'. """ host = getattr(self.rc, 'host', None) uri = db.get('dst_url', None) dbpath = dbpathname(db, self.rc) dbname = db['name'] import_jsons(dbpath, dbname, host=host, uri=uri) import_yamls(dbpath, dbname, host=host, uri=uri) return
def load_database(self, db): """Loads a database via mongoimport. Takes a database dict db.""" dbpath = dbpathname(db, self.rc) for f in iglob(os.path.join(dbpath, "*.json")): base, ext = os.path.splitext(os.path.split(f)[-1]) cmd = [ "mongoimport", "--db", db["name"], "--collection", base, "--file", f, ] subprocess.check_call(cmd)
def dump_database(self, db): """Dumps a database back to the filesystem.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] for collname, collection in self.dbs[db["name"]].items(): print("dumping " + collname + "...", file=sys.stderr) filetype = self._collfiletypes.get(collname, "yaml") if filetype == "json": filename = self.dump_json(collection, collname, dbpath) elif filetype == "yaml": filename = self.dump_yaml(collection, collname, dbpath) else: raise ValueError("did not recognize file type for regolith") to_add.append(os.path.join(db["path"], filename)) return to_add
def dump_database(self, db): """Dumps a database back to the filesystem.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] for collname, collection in self.dbs[db['name']].items(): print('dumping ' + collname + '...', file=sys.stderr) filetype = self._collfiletypes.get(collname, 'yaml') if filetype == 'json': filename = self.dump_json(collection, collname, dbpath) elif filetype == 'yaml': filename = self.dump_yaml(collection, collname, dbpath) else: raise ValueError('did not recognize file type for regolith') to_add.append(os.path.join(db['path'], filename)) return to_add
def dump_database(self, db): """Dumps a database dict via mongoexport.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] colls = self.client[db['name']].collection_names( include_system_collections=False) for collection in colls: f = os.path.join(dbpath, collection + '.json') cmd = [ 'mongoexport', '--db', db['name'], '--collection', collection, '--out', f ] subprocess.check_call(cmd) to_add.append(os.path.join(db['path'], collection + '.json')) return to_add
def export_database(self, db: dict): """Exports the database from mongo backend to the filesystem. Parameters ---------- db : dict The dictionary of data base information, such as 'name'. """ host = getattr(self.rc, 'host', None) uri = db.get('dst_url', None) # Catch the easy/common regolith rc error of putting the db uri as localhost rather than host if uri == 'localhost': uri = None host = 'localhost' dbpath = os.path.abspath(dbpathname(db, self.rc)) dbname = db['name'] for collection in self.dbs[dbname].keys(): export_json(collection, dbpath, dbname, host=host, uri=uri) return
def import_database(self, db: dict): """Import the database from filesystem to the mongo backend. Parameters ---------- db : dict The dictionary of data base information, such as 'name'. """ host = getattr(self.rc, 'host', None) uri = db.get('dst_url', None) # Catch the easy/common regolith rc error of putting the db uri as localhost rather than host if uri == 'localhost': uri = None host = 'localhost' dbpath = dbpathname(db, self.rc) dbname = db['name'] import_jsons(dbpath, dbname, host=host, uri=uri) import_yamls(dbpath, dbname, host=host, uri=uri) return
def dump_database(self, db): """Dumps a database dict via mongoexport.""" dbpath = dbpathname(db, self.rc) os.makedirs(dbpath, exist_ok=True) to_add = [] colls = self.client[db["name"]].collection_names( include_system_collections=False) for collection in colls: f = os.path.join(dbpath, collection + ".json") cmd = [ "mongoexport", "--db", db["name"], "--collection", collection, "--out", f, ] subprocess.check_call(cmd) to_add.append(os.path.join(db["path"], collection + ".json")) return to_add
def load_database(self, db): """Loads a database.""" dbpath = dbpathname(db, self.rc) self.load_json(db, dbpath) self.load_yaml(db, dbpath)