Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_file(cls, db_file, m="materials", **kwargs):
"""
Get a MaterialsDescriptorBuilder using only a db file.
Args:
db_file: (str) path to db file
m: (str) name of "materials" collection
**kwargs: other parameters to feed into the builder
"""
db_write = get_database(db_file, admin=True)
return cls(db_write[m], **kwargs)
Get a TaskMaterialsBuilder using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
c (str): name of "counter" collection
t (str): name of "tasks" collection
**kwargs: other params to put into TasksMaterialsBuilder
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
logger.warning("Warning: could not get read-only database; using write creds")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_write[c], db_read[t], **kwargs)
def from_file(cls, db_file, m="materials", t="tasks", **kwargs):
"""
Get a TagsCollector using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
**kwargs: other parameters to feed into the builder, e.g. update_all
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database; using write creds")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[t], **kwargs)
def from_file(cls, db_file, m="materials", t="tasks", **kwargs):
"""
Get a TagsCollector using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
**kwargs: other parameters to feed into the builder, e.g. update_all
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database; using write creds")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[t], **kwargs)
def from_file(cls, db_file, m="materials", b="boltztrap", **kwargs):
"""
Get a BoltztrapMaterialsBuilder using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
b (str): name of "boltztrap" collection
**kwargs: other params to put into BoltztrapMaterialsBuilder
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[b], **kwargs)
def from_file(db_file, m="materials", **kwargs):
"""
Get builder using only a db file.
Args:
db_file: (str) path to db file
m: (str) name of "materials" collection
**kwargs: other parameters to feed into the builder, e.g. mapi_key
Returns:
BandgapEstimationBuilder
"""
db_write = get_database(db_file, admin=True)
return BandgapEstimationBuilder(db_write[m], **kwargs)
"""
Get a BoltztrapMaterialsBuilder using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
b (str): name of "boltztrap" collection
**kwargs: other params to put into BoltztrapMaterialsBuilder
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[b], **kwargs)
def from_file(cls, db_file, data_file=None, m="materials", **kwargs):
"""
Get a FileMaterialsBuilder using only a db file.
Args:
db_file (str): path to db file
data_file (str): path to data file
m (str): name of "materials" collection
**kwargs: other parameters to feed into the builder, e.g. mapi_key
"""
db_write = get_database(db_file, admin=True)
if data_file:
return cls(db_write[m], data_file, **kwargs)
else:
raise ValueError("data_file must be provided")
def from_file(cls, db_file, m="materials", t="tasks", **kwargs):
"""
Get a TagsCollector using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
**kwargs: other parameters to feed into the builder, e.g. update_all
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database; using write creds")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[t], **kwargs)
def from_file(cls, db_file, m="materials", b="boltztrap", **kwargs):
"""
Get a BoltztrapMaterialsBuilder using only a db file.
Args:
db_file (str): path to db file
m (str): name of "materials" collection
b (str): name of "boltztrap" collection
**kwargs: other params to put into BoltztrapMaterialsBuilder
"""
db_write = get_database(db_file, admin=True)
try:
db_read = get_database(db_file, admin=False)
db_read.collection_names() # throw error if auth failed
except:
print("Warning: could not get read-only database")
db_read = get_database(db_file, admin=True)
return cls(db_write[m], db_read[b], **kwargs)