exopy.tasks.tasks.database module¶
Definition of the base tasks.
The base tasks define how task interact between them and with the database, how ressources can be shared and how preferences are handled.
-
class
exopy.tasks.tasks.database.
DatabaseNode
[source]¶ Bases:
atom.atom.Atom
Helper class to differentiate nodes and dict in database
-
parent
¶ Reference to the parent node.
-
data
¶ Actual data hold by this node.
-
meta
¶ Metadata associated with this node such as access exceptions.
-
-
class
exopy.tasks.tasks.database.
TaskDatabase
[source]¶ Bases:
atom.atom.Atom
A database for inter tasks communication.
The database has two modes:
an edition mode in which the number of entries and their hierarchy can change. In this mode the database is represented by a nested dict.
a running mode in which the entries are fixed (only their values can change). In this mode the database is represented as a flat list. In running mode the database is thread safe but the object it contains may not be so (dict, list, etc)
-
notifier
¶ Signal used to notify a value changed in the database. In edition mode the update is passed as a tuple (‘added’, path, value) for creation, as (‘renamed’, old, new, value) in case of renaming, (‘removed’, old) in case of deletion or as a list of such tuples. In running mode, a 2-tuple (path, value) is sent as entries cannot be renamed or removed.
-
access_notifier
¶ Signal emitted to notify that access exceptions has changed. The update is passed as a tuple (‘added’, path, relative, entry) for creation or as (‘renamed’, path, relative, old, new) in case of renaming of the related entry, (‘removed’, path, relative, old) in case of deletion (if old is None all exceptions have been removed) or as a list of such tuples. Path indicate the node where the exception is located, relative the relative path from the ‘path’ node to the real location of the entry.
-
nodes_notifier
¶ Signal emitted to notify that the nodes were modified. The update is passed as a tuple (‘added’, path, name, node) for creation or as (‘renamed’, path, old, new) in case of renaming of the related node, (‘removed’, path, old) in case of deletion or as a list of such tuples.
-
excluded
¶ List of root entries which should not be listed.
-
running
¶ Flag indicating whether or not the database entered the running mode. In running mode the database is flattened into a list for faster acces.
-
set_value
(node_path, value_name, value)[source]¶ Method used to set the value of the entry at the specified path
This method can be used both in edition and running mode.
- Parameters
node_path (
unicode
) – Path to the node holding the value to be setvalue_name (
unicode
) – Public key associated with the value to be set, internally converted so that we do not mix value and nodesvalue (
any
) – Actual value to be stored
- Returns
new_val – Boolean indicating whether or not a new entry has been created in the database
- Return type
-
get_value
(assumed_path, value_name)[source]¶ Method to get a value from the database from its name and a path
This method returns the value stored under the specified name. It starts looking at the specified path and if necessary goes up in the hierarchy.
- Parameters
assumed_path (
unicode
) – Path where we start looking for the entryvalue_name (
unicode
) – Name of the value we are looking for
- Returns
value – Value stored under the entry value_name
- Return type
-
rename_values
(node_path, old, new, access_exs=None)[source]¶ Rename database entries.
This method can update the access exceptions attached to them. This method cannot be used in running mode.
- Parameters
node_path (
unicode
) – Path to the node holding the value.old (
iterable
) – Old names of the values.new (
iterable
) – New names of the values.access_exs (
iterable
, optional) – Dict mapping old entries names to how far the access exception is located.
-
delete_value
(node_path, value_name)[source]¶ Remove an entry from the specified node
This method remove the specified entry from the specified node. It does not handle removing the access exceptions attached to it. This method cannot be used in running mode.
- Parameters
assumed_path (
unicode
) – Path where we start looking for the entryvalue_name (
unicode
) – Name of the value we are looking for
-
get_values_by_index
(indexes, prefix=None)[source]¶ Access to a list of values using the flat database.
- Parameters
indexes (
list(int)
) – List of index for which values should be returned.prefix (
unicode
, optional) – If provided return the values in dict with key of the form : prefix + index.
- Returns
values – List of requested values in the same order as indexes or dict if prefix was not None.
- Return type
-
get_entries_indexes
(assumed_path, entries)[source]¶ Access to the index in the flattened database for some entries.
- Parameters
assumed_path (
unicode
) – Path to the node in which the values are assumed to be stored.entries (
iterable(unicode)
) – Names of the entries for which the indexes should be returned.
- Returns
indexes – Dict mapping the entries names to their index in the flattened database.
- Return type
-
list_accessible_entries
(node_path)[source]¶ Method used to get a list of all entries accessible from a node.
DO NOT USE THIS METHOD IN RUNNING MODE (ie never in the check method of a task, use a try except clause instead and get_value or get_entries_indexes).
- Parameters
node_path (
unicode
) – Path to the node from which accessible entries should be listed.- Returns
entries_list – List of entries accessible from the specified node
- Return type
list(unicode)
-
list_all_entries
(path='root', values=False)[source]¶ List all entries in the database.
- Parameters
path (
unicode
, optional) – Starting node. This parameters is for internal use only.values (
bool
, optional) – Whether or not to return the values associated with the entries.
- Returns
paths – List of all accessible entries with their full path.
- Return type
list(unicode)
ordict if values
-
add_access_exception
(node_path, entry_node, entry)[source]¶ Add an access exception in a node for an entry located in a node below.
- Parameters
node_path (
unicode
) – Path to the node which should hold the exception.entry_node (
unicode
) – Absolute path to the node holding the entry.entry (
unicode
) – Name of the entry for which to create an exception.
-
remove_access_exception
(node_path, entry=None)[source]¶ Remove an access exception from a node for a given entry.
- Parameters
node_path (
unicode
) – Path to the node holding the exception.entry (
unicode
, optional) – Name of the entry for which to remove the exception, if not provided all access exceptions will be removed.
-
create_node
(parent_path, node_name)[source]¶ Method used to create a new node in the database
This method creates a new node in the database at the specified path. This method is not thread safe safe as the hierarchy of the tasks’ database is not supposed to change during a measurement but only during the configuration phase
- Parameters
parent_path (
unicode
) – Path to the node parent of the new onenode_name (
unicode
) – Name of the new node to create
-
rename_node
(parent_path, old_name, new_name)[source]¶ Method used to rename a node in the database
- Parameters
parent_path (
unicode
) – Path to the parent of the node being renamedold_name (
unicode
) – Old name of the node.node_name (
unicode
) – New name of node
-
delete_node
(parent_path, node_name)[source]¶ Method used to delete an existing node from the database
- Parameters
parent_path (
unicode
) – Path to the node parent of the new onenode_name (
unicode
) – Name of the new node to create
-
copy_node_values
(node='root')[source]¶ Copy the values (ie not subnodes) found in a node.
- Parameters
node (
unicode
, optional) – Path to the node to copy.- Returns
copy – Copy of the node values.
- Return type
-
prepare_to_run
()[source]¶ Enter a thread safe, flat database state.
This is used when tasks are executed.