scenario.confignode module¶
Configuration node management.
- class ConfigNode¶
Bases:
object
Considering that configurations are organized in a tree structure, this class represents a node of the tree, with either:
a final item,
a dictionary of
ConfigNode
,or a list of
ConfigNode
.
- __init__(parent, key)¶
- Parameters:
parent – Parent node.
None
for the root node.key – Key of the configuration node.
- parent¶
Parent node.
None
for the root node, as well as for removed nodes.
- key¶
Configuration key.
- _data¶
Configuration data.
Either:
a final item,
a dictionary of
ConfigNode
,or a list of
ConfigNode
.
- origins¶
Origins of the configuration value: either a string or the path of the configuration file it was defined in.
- __repr__()¶
Canonical string representation.
Gives the configuration key and type of data.
- set(data, subkey=None, origin=None)¶
Sets configuration data.
- Parameters:
data –
Configuration data: dictionary, list or single value.
When
None
is given and nosubkey
is provided, it is equivalent to callingremove()
on the current node.subkey – Relative key from this node to store the data in.
origin – Origin of the configuration data: either a simple string, or the path of the configuration file it was defined in. Defaults to code location when not set.
- _setdata(data)¶
Sets the node’s data, applying conversions when applicable, and displays debug info on the data stored.
- Parameters:
data – Node’s data being set.
- remove()¶
Removes the node from its parent.
Note: Does nothing on the root node (no parent for the root node, by definition).
- show(log_level)¶
Displays the configuration database with the given log level.
- Parameters:
log_level –
logging
log level.
- getkeys()¶
Retrieves the list of full keys from this node.
- Returns:
List of full keys.
- getsubkeys()¶
Retrieves the list of sub-keys from this node.
- Returns:
List of sub-keys.
- get(subkey)¶
Finds a sub-node from this node.
- Parameters:
subkey – Sub-key from this node.
- Returns:
Sub-node if found,
None
otherwise.
- _getsubnode(subkey, create_missing=False, origin=None)¶
Finds or creates a sub-node from this node.
- Parameters:
subkey – Sub-key from this node.
create_missing –
True
to create missing sub-nodes.origin – Origin info to set for each sub-node walked through or created, starting from this one.
- Returns:
Sub-node if found,
None
otherwise.
- property data¶
Retrieves the node data as a JSON-like structure, or value as given.
- Returns:
JSON-like structure or value.
- cast(type)¶
Ensures the retrieval of the node data with the expected type.
- Parameters:
type – Expected type.
- Returns:
JSON-like structure or value of the expected type.
When the configuration data is not of the expected type, a
ValueError
is raised.
- property origin¶
Representative origin for the current node.