Package rtslib :: Module config_tree :: Class ConfigTree

[hide private]
[frames] | no frames]

# Class ConfigTree

    object --+
             |
            ConfigTree

An ordered tree structure to hold configuration data.

A node can be referred to by its path, relative to the current node. A path is a list of keys, each key a tuple of either string or None items.

Instance Methods | [hide private]

__init__(self, data=None, sort_key=<function <lambda> at 0x7fa9c632bb18>, key_to_string=<function <lambda> at 0x7fa9c632bb90>) Initializes a new ConfigTree. |

__repr__(self) repr(x) |

__str__(self) str(x) |

get_clone(self, parent=None) Returns a clone of the ConfigTree, not sharing any mutable data. |

get(self, node_key) Returns the current node's child having node_key, or None. |

set(self, node_key, node_data=None) Creates and adds a child node to the current node, and returns that new node. |

cine(self, node_key, node_data=None) cine stands for create if not exist: it makes sure a node exists. |

update(self, node_key, node_data=None) If a node already has node_key as key, its data will be replaced with node_data. |

delete(self, path) Given a path, deletes an entire subtree from the configuration, relative to the current node. |

get_path(self, path) Returns either the node matching path, relative to the current node, or None if the path does not exists. |

search(self, search_path, node_filter=<function <lambda> at 0x7fa9c632f578>) Returns a list of nodes matching the search_path, relative to the current node, or an empty list if no match was found. |

walk(self, node_filter=<function <lambda> at 0x7fa9c632f668>) Returns a generator yielding our children's tree in depth-first order. |

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Properties | [hide private]

| root Returns the root node of the tree.
| key Returns the current node's key tuple.
| key_str Returns the current node's key as a string.
| path Returns the node's full path from the tree root as a list of keys.
| path_str Returns the node's full path from the tree root as a string.
| nodes Returns the list of all children nodes, sorted with potential dependencies first.
| keys Generates all children nodes keys, sorted with potential dependencies first.
| parent Returns the parent node of the current node, or None.
| is_root Returns True if this is a root node, else False.
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, data=None, sort_key=<function <lambda> at 0x7fa9c632bb18>, key_to_string=<function <lambda> at 0x7fa9c632bb90>)
(Constructor)

Initializes a new ConfigTree.

The optional sort_key is a function used when ordering children of a configuration node.

The optional key_to_string is a function used when converting a node key to string.

Direct instanciation should only happen for the root node of the tree. Adding a new node to the tree is achieved by using the set() method of the desired parent for that new node.

Overrides: object.__init__

### __repr__(self)
(Representation operator)

repr(x)

Overrides: object.__repr__
  (inherited documentation)

### __str__(self)
(Informal representation operator)

str(x)

Overrides: object.__str__
  (inherited documentation)

### set(self, node_key, node_data=None)

Creates and adds a child node to the current node, and returns that new node. If the node already exists, then a ConfigTreeError exception will be raised. Else, the new node will be returned.

node_key is any tuple of strings node_data is an optional arbitrary value

### cine(self, node_key, node_data=None)

cine stands for create if not exist: it makes sure a node exists. If it does not, it will create it using node_data. Else node_data will not be updated.

Returns the matching node in all cases.

node_key is any tuple of strings node_data is an optional arbitrary value

### update(self, node_key, node_data=None)

If a node already has node_key as key, its data will be replaced with node_data. Else, it will be created using node_data.

The matching node will be returned in both cases.

node_key is any tuple of strings. node_data is an optional arbitrary value.

### delete(self, path)

Given a path, deletes an entire subtree from the configuration, relative to the current node.

The deleted subtree will be returned, or None is the path does not exist or is empty. The path must be a list of node keys.

### search(self, search_path, node_filter=<function <lambda> at 0x7fa9c632f578>)

    Returns a list of nodes matching the search_path, relative to the
    current node, or an empty list if no match was found.

    The search_path is a list of node search_key. Each will be matched
    against node key tuples items-for-item, with search_key containing
    regular expressions patterns or None values, and key containing string
    or None values.

    node_filter is a function applied to each node before returning it:
        node_filter(node_in) -> node_out | None (aka filtered out)

### walk(self, node_filter=<function <lambda> at 0x7fa9c632f668>)

    Returns a generator yielding our children's tree in depth-first order.

    node_filter is a function applied to each node before dumping it:
        node_filter(node_in) -> node_out | None (aka filtered out)

    When a node is filtered out, its children will still be walked and
    filtered/yielded as usual.

Property Details | [hide private]

### root

Returns the root node of the tree.

Get Method:
  unreachable.root(self) - Returns the root node of the tree.

### key

Returns the current node's key tuple.

Get Method:
  unreachable.key(self) - Returns the current node's key tuple.

### key_str

Returns the current node's key as a string.

Get Method:
  unreachable.key_str(self) - Returns the current node's key as a string.

### path

Returns the node's full path from the tree root as a list of keys.

Get Method:
  unreachable.path(self) - Returns the node's full path from the tree root as a list of keys.

### path_str

Returns the node's full path from the tree root as a string.

Get Method:
  unreachable.path_str(self) - Returns the node's full path from the tree root as a string.

### nodes

Returns the list of all children nodes, sorted with potential dependencies first.

Get Method:
  unreachable.nodes(self) - Returns the list of all children nodes, sorted with potential dependencies first.

### keys

Generates all children nodes keys, sorted with potential dependencies first.

Get Method:
  unreachable.keys(self) - Generates all children nodes keys, sorted with potential dependencies first.

### parent

Returns the parent node of the current node, or None.

Get Method:
  unreachable.parent(self) - Returns the parent node of the current node, or None.

### is_root

Returns True if this is a root node, else False.

Get Method:
  unreachable.is_root(self) - Returns True if this is a root node, else False.