API¶
nodestack is a Python library to manage Nodes classes. A node is an object which is related to other nodes given a tree chart.
- class nodestack.Node(name: str, parent: Node | None = None)[source]¶
Should be subclassed only
- add_child(child: Node) None [source]¶
Add new child node to current instance
- Parameters:
child – Node object
- static check_lineage(nodes: list[Node]) bool [source]¶
- check if the list of nodes is a straight lineage:
node 1 (ancestor) -> node 2 -> node 3 -> … -> node n (grand children)
- classmethod create_random_nodes(type_: str = 'cmd', depth: int = 0) Node [source]¶
Creates random tree of nodes for testing purpose
- get_child(name: str) Node | None [source]¶
find and returns a child with specified name. None if nothing found
- get_sibling(name: str) Node | None [source]¶
find and returns a sibling with specified name. None if nothing found
- is_sibling(other: str) bool [source]¶
Check if Node object is a sibling of the other Node object
- Parameters:
other – Other Node object to be compared with
- property level: int¶
Returns the level of the Node object
- property path: str¶
Returns a representation of the ancestor lineage of self