taucmdr.cf.storage package¶
TAU Storage Containers.
A storage container provides a record database, a persistent filesystem, and a key/value store.
The database is accessed via member methods like AbstractStorage.insert(),
AbstractStorage.search(), etc.
The filesystem is accessed via its filesystem prefix (e.g. /usr/local/packages) via
AbstractStorage.prefix().
The key/value store is accessed via the [] operator, i.e. treat the storage object like a dictionary.
- class taucmdr.cf.storage.AbstractStorage(name: str)[source]¶
Bases:
objectAbstract base class for storage containers.
A storage container provides a record database, a persistent filesystem, and a key/value store. The database is accessed via member methods like
insert(),search(), etc. The filesystem is accessed via its filesystem prefix (e.g./usr/local/packages) viaprefix(). The key/value store is accessed via the [] operator, i.e. treat the storage object like a dictionary.- Record¶
alias of
StorageRecord
- abstractmethod __contains__(key)[source]¶
Returns True if
keymaps to a value is in the key/value store.
- _abc_impl = <_abc._abc_data object>¶
- abstractmethod connect_database(*args, **kwargs)[source]¶
Open the database for reading and writing.
- abstractmethod connect_filesystem(*args, **kwargs)[source]¶
Prepares the store filesystem for reading and writing.
- abstractmethod contains(keys, table_name=None, match_any=False)[source]¶
Check if the specified table contains at least one matching record.
- The behavior depends on the type of keys:
self.Record.eid_type: check for the record with that element identifier.
dict: check for the record with attributes matching keys.
list or tuple: return the equivalent of
map(contains, keys).
- Parameters:
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Returns:
True if the table contains at least one matching record, False otherwise.
- Return type:
- Raises:
ValueError – Invalid value for keys.
- abstractmethod count(table_name=None)[source]¶
Count the records in the database.
- Parameters:
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.- Returns:
Number of records in the table.
- Return type:
- abstractmethod database_exists()[source]¶
Determine if the database file backing this Storage object exists.
- Returns:
True if database exists; false otherwise.
- Return type:
- abstractmethod disconnect_database(*args, **kwargs)[source]¶
Close the database for reading and writing.
- abstractmethod disconnect_filesystem(*args, **kwargs)[source]¶
Makes the store filesystem unreadable and unwritable.
- abstractmethod get(keys, table_name=None, match_any=False)[source]¶
Find a single record.
- The behavior depends on the type of keys:
self.Record.eid_type: return the record with that element identifier.
dict: return the record with attributes matching keys.
list or tuple: return a list of records matching the elements of keys
None: return None.
- Parameters:
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Returns:
The matching data record if keys was a self.Record.eid_type or dict. list: All matching data records if keys was a list or tuple. None: No record found or
bool(keys) == False.- Return type:
- Raises:
ValueError – Invalid value for keys.
- abstractmethod insert(data, table_name=None)[source]¶
Create a new record.
If the table doesn’t exist it will be created.
- Parameters:
data (dict) – Data to insert in table.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.
- Returns:
The new record.
- Return type:
- abstractmethod match(field, table_name=None, regex=None, test=None)[source]¶
Find records where field matches regex or test.
Either regex or test may be specified, not both. If regex is given, then all records with field matching the regular expression are returned. If test is given then all records with field set to a value that causes test to return True are returned. If neither is given, return all records where field is set to any value.
- Parameters:
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.field (string) – Name of the data field to match.
regex (string) – Regular expression string.
test – Callable returning a boolean value.
- Returns:
Matching data records.
- Return type:
- Raises:
ValueError – Invalid value for keys.
- abstract property prefix: str¶
Get the filesystem prefix for file storage.
The filesystem must be persistent and provide the usual POSIX filesystem calls. In particular, GNU software packages should be installable in the filesystem.
- Returns:
Absolute path in the filesystem.
- Return type:
- abstractmethod purge(table_name=None)[source]¶
Delete all records.
- Parameters:
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.
- abstractmethod remove(keys, table_name=None, match_any=False)[source]¶
Delete records.
- The behavior depends on the type of keys:
self.Record.eid_type: delete the record with that element identifier.
dict: delete all records with attributes matching keys.
list or tuple: delete all records matching the elements of keys.
- Parameters:
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Raises:
ValueError –
bool(keys) == Falseor invalid value for keys.
- abstractmethod search(keys=None, table_name=None, match_any=False)[source]¶
Find multiple records.
- The behavior depends on the type of keys:
Record.eid_type: return the record with that element identifier.
dict: return all records with attributes matching keys.
list or tuple: return a list of records matching the elements of keys
None: return all records.
- Parameters:
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Returns:
Matching data records.
- Return type:
- Raises:
ValueError – Invalid value for keys.
- abstractmethod table(table_name)[source]¶
Return a handle to a table.
Return a handle to the named table or, if table_name is None, return the default table.
- abstractmethod unset(fields, keys, table_name=None, match_any=False)[source]¶
Update records by unsetting fields.
Update only allows you to update a record by adding new fields or overwriting existing fields. Use this method to remove a field from the record.
- The behavior depends on the type of keys:
self.Record.eid_type: update the record with that element identifier.
dict: update all records with attributes matching keys.
list or tuple: apply update to all records matching the elements of keys.
- Parameters:
fields (list) – Names of fields to remove from matching records.
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Raises:
ValueError –
bool(keys) == Falseor invalid value for keys.
- abstractmethod update(fields, keys, table_name=None, match_any=False)[source]¶
Update records.
- The behavior depends on the type of keys:
self.Record.eid_type: update the record with that element identifier.
dict: update all records with attributes matching keys.
list or tuple: apply update to all records matching the elements of keys.
- Parameters:
fields (dict) – Data to record.
keys – Fields or element identifiers to match.
table_name (str) – Name of the table to operate on. See
AbstractStorage.table.match_any (bool) – Only applies if keys is a dictionary. If True then any key in keys may match or if False then all keys in keys must match.
- Raises:
ValueError –
bool(keys) == Falseor invalid value for keys.
- exception taucmdr.cf.storage.StorageError(value, *hints)[source]¶
Bases:
ErrorIndicates a failure in the storage system.
- message_fmt = '%(value)s\n%(hints)s\n'¶
Format string for the error message.
- class taucmdr.cf.storage.StorageRecord(storage, eid, element)[source]¶
Bases:
dictA record in the storage container’s database.
- storage¶
Storage container whose database contains this record.
- eid¶
Element identifier value.
- eid_type = None¶
Element identifier type.
Subpackages¶
- taucmdr.cf.storage.tests package
- Submodules
- taucmdr.cf.storage.tests.test_levels module
- taucmdr.cf.storage.tests.test_local_file module
- taucmdr.cf.storage.tests.test_old_databases module
- taucmdr.cf.storage.tests.test_project module
- taucmdr.cf.storage.tests.test_sqlite3_file module
- taucmdr.cf.storage.tests.test_sqlite3_project module
- taucmdr.cf.storage.tests.test_storage_dispatch module
- Submodules
Submodules¶
- taucmdr.cf.storage.levels module
- taucmdr.cf.storage.local_file module
LocalFileStorageLocalFileStorage.RecordLocalFileStorage.__enter__()LocalFileStorage.__exit__()LocalFileStorage.__str__()LocalFileStorage._abc_implLocalFileStorage._make_prefix()LocalFileStorage._query()LocalFileStorage.connect_database()LocalFileStorage.connect_filesystem()LocalFileStorage.contains()LocalFileStorage.count()LocalFileStorage.database_exists()LocalFileStorage.dbfileLocalFileStorage.disconnect_database()LocalFileStorage.disconnect_filesystem()LocalFileStorage.get()LocalFileStorage.insert()LocalFileStorage.is_writable()LocalFileStorage.items()LocalFileStorage.keys()LocalFileStorage.match()LocalFileStorage.prefixLocalFileStorage.purge()LocalFileStorage.remove()LocalFileStorage.search()LocalFileStorage.table()LocalFileStorage.unset()LocalFileStorage.update()LocalFileStorage.values()
_CachingMiddleware_JsonFileStorage_JsonRecord
- taucmdr.cf.storage.project module
- taucmdr.cf.storage.sqlite3_file module
SQLiteDatabaseSQLiteDatabase.dbfileSQLiteDatabase._LoggingCursorSQLiteDatabase.check_writable()SQLiteDatabase.close()SQLiteDatabase.commit_transaction()SQLiteDatabase.cursor()SQLiteDatabase.open()SQLiteDatabase.purge()SQLiteDatabase.revert_transaction()SQLiteDatabase.start_transaction()SQLiteDatabase.table()SQLiteDatabase.tables()
SQLiteLocalFileStorageSQLiteLocalFileStorage.RecordSQLiteLocalFileStorage.__enter__()SQLiteLocalFileStorage.__exit__()SQLiteLocalFileStorage.__str__()SQLiteLocalFileStorage._abc_implSQLiteLocalFileStorage._database_writable()SQLiteLocalFileStorage.connect_database()SQLiteLocalFileStorage.contains()SQLiteLocalFileStorage.count()SQLiteLocalFileStorage.database_exists()SQLiteLocalFileStorage.dbfileSQLiteLocalFileStorage.disconnect_database()SQLiteLocalFileStorage.get()SQLiteLocalFileStorage.insert()SQLiteLocalFileStorage.match()SQLiteLocalFileStorage.purge()SQLiteLocalFileStorage.remove()SQLiteLocalFileStorage.search()SQLiteLocalFileStorage.table()SQLiteLocalFileStorage.unset()SQLiteLocalFileStorage.update()
SQLiteStorageError_SQLiteJsonRecord_SQLiteJsonTable_SQLiteJsonTable.Record_SQLiteJsonTable._ensure_exists()_SQLiteJsonTable._get()_SQLiteJsonTable._json_query()_SQLiteJsonTable.count()_SQLiteJsonTable.exists()_SQLiteJsonTable.get()_SQLiteJsonTable.insert()_SQLiteJsonTable.name_SQLiteJsonTable.purge()_SQLiteJsonTable.remove()_SQLiteJsonTable.search()_SQLiteJsonTable.update()
- taucmdr.cf.storage.sqlite3_project module
- taucmdr.cf.storage.storage_dispatch module
ProjectStorageDispatchStorageDispatchStorageDispatch.__contains__()StorageDispatch.__delitem__()StorageDispatch.__enter__()StorageDispatch.__exit__()StorageDispatch.__getattr__()StorageDispatch.__getitem__()StorageDispatch.__iter__()StorageDispatch.__len__()StorageDispatch.__setitem__()StorageDispatch._abc_implStorageDispatch._get_storage()StorageDispatch.connect_database()StorageDispatch.connect_filesystem()StorageDispatch.contains()StorageDispatch.count()StorageDispatch.database_exists()StorageDispatch.default_backendStorageDispatch.disconnect_database()StorageDispatch.disconnect_filesystem()StorageDispatch.get()StorageDispatch.insert()StorageDispatch.items()StorageDispatch.keys()StorageDispatch.match()StorageDispatch.prefixStorageDispatch.purge()StorageDispatch.remove()StorageDispatch.search()StorageDispatch.set_backend()StorageDispatch.table()StorageDispatch.unset()StorageDispatch.update()StorageDispatch.values()