taucmdr.cf.storage.storage_dispatch module

TAU Commander storage dispatch

This Storage class dispatches calls to either TinyDB or SQLite, depending on which is selected.

class taucmdr.cf.storage.storage_dispatch.ProjectStorageDispatch[source]

Bases: taucmdr.cf.storage.storage_dispatch.StorageDispatch

Dispatches Project storage method calls to the backing Project storage class

destroy(ignore_errors=False)[source]
class taucmdr.cf.storage.storage_dispatch.StorageDispatch(name=None, prefix=None, kind=None)[source]

Bases: taucmdr.cf.storage.AbstractStorage

Dispatches storage method calls to backend storage based on runtime selection of the type.

__contains__(key)[source]

Returns True if key maps to a value is in the key/value store.

__delitem__(key)[source]

Remove a value from the key/value store.

__enter__()[source]

Initiates the database transaction.

__exit__(ex_type, value, traceback)[source]

Finalizes the database transaction.

__getattr__(item)[source]

Dispatches any messages not otherwise caught to the selected storage backend.

__getitem__(key)[source]

Retrieve a value from the key/value store.

__iter__()[source]

Iterate over keys in the key/value store.

__len__()[source]

Return the number of items in the key/value store.

__setitem__(key, value)[source]

Store a value in the key/value store.

connect_database(*args, **kwargs)[source]

Open the database for reading and writing.

connect_filesystem(*args, **kwargs)[source]

Prepares the store filesystem for reading and writing.

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:

bool

Raises:

ValueError – Invalid value for keys.

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:int
database_exists()[source]

Determine if the database file backing this Storage object exists.

Returns:True if database exists; false otherwise.
Return type:bool
default_backend = 'tinydb'
disconnect_database(*args, **kwargs)[source]

Close the database for reading and writing.

disconnect_filesystem(*args, **kwargs)[source]

Makes the store filesystem unreadable and unwritable.

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:

Record

Raises:

ValueError – Invalid value for keys.

insert(data, table_name=None)[source]

Create a new record.

If the table doesn’t exist it will be created.

Parameters:
Returns:

The new record.

Return type:

Record

Raises:

TypeError – If bytes, bytearray or memoryview found in data

items()[source]

Iterate over items in the key/value store.

keys()[source]

Iterate over keys in the key/value store.

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 caues 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:

list

Raises:

ValueError – Invalid value for keys.

prefix

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:str
purge(table_name=None)[source]

Delete all records.

Parameters:table_name (str) – Name of the table to operate on. See AbstractStorage.table.
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:

ValueErrorbool(keys) == False or invalid value for keys.

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:

list

Raises:

ValueError – Invalid value for keys.

set_backend(backend)[source]

Set the backend that is to be used for subsequent storage method calls.

Parameters:backend (str) – The backend to use. One of ‘tinydb’, ‘sqlite’, or ‘auto’. If ‘auto’, the backend is SQLite if a SQLite database is already present, and is TinyDB otherwise.
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.

Parameters:table_name (str) – Name of the table or None.
Returns:A database table object.
Return type:object
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:

ValueErrorbool(keys) == False or invalid value for keys.

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:
  • ValueErrorbool(keys) == False or invalid value for keys.
  • TypeError – If binary data (bytes, bytearray, memoryview) found in fields or key dict
values()[source]

Iterate over values in the key/value store.