Data Broker (regolith.broker
)¶
API for accessing the metadata and file storage
- class regolith.broker.Broker(rc=RunControl(builddir='_build', force=False, mongodbpath=<property object>, user_config='/home/travis/.config/regolith/user.json'))[source]¶
Interface to the database and file storage systems
Examples
>>> # Load the db >>> db = Broker.from_rc() >>> # Get a docment from the broker >>> ergs =db['group']['ergs'] >>> # Store a file >>> db.add_file(ergs, 'myfile', '/path/to/file/hello.txt') >>> # Get a file from the store >>> path = db.get_file_path(ergs, 'myfile')
- add_file(document, name, filepath)[source]¶
Add a file to a document in a collection.
- Parameters:
document (dict) – The document to add the file to
name (str) – Name of the reference to the file
filepath (str) – Location of the file on local disk
- get_file_path(document, name)[source]¶
Get a file from the file storage associated with the document and name
- Parameters:
document (dict) – The document which stores the reference to the file
name (str) – The name of the file stored (note that this can be different from the filename itself)
- Returns:
path – The file path, if not in the storage None
- Return type:
str or None