diff options
author | Magnus Ahltorp <map@kth.se> | 2017-07-03 00:21:02 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-07-06 17:48:30 +0200 |
commit | bb67c23918ba22be498537a29c01b696732d5b3b (patch) | |
tree | 4562cc0f90eac0fb992508f64946ad28ee4bb636 /tools/orderedtree.py | |
parent | b09e878a21c09d8344ec8b2a896d7d1a8162387e (diff) |
Automatic generation of config man page skeleton
Diffstat (limited to 'tools/orderedtree.py')
-rw-r--r-- | tools/orderedtree.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/orderedtree.py b/tools/orderedtree.py new file mode 100644 index 0000000..def8928 --- /dev/null +++ b/tools/orderedtree.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# Copyright (c) 2017, NORDUnet A/S. +# See LICENSE for licensing information. + +class OrderDict(dict): + def __init__(self): + self._order = [] + dict.__init__({}) + def __setitem__(self, key, value): + if key not in self: + self._order.append(key) + super(OrderDict, self).__setitem__(key, value) + def iterkeys(self): + return iter(self._order) + +class TreeNode(): + def __init__(self): + self.entry = None + self._children = OrderDict() + def add(self, k, e, subtree=None): + if subtree != None: + self._children[k] = subtree + else: + self._children[k] = TreeNode() + self._children[k].entry = e + def __getitem__(self, key): + return self._children[key] + def iterkeys(self): + return self._children.iterkeys() + def __contains__(self, key): + return key in self._children + def walk(self, keys): + node = self + for k in keys: + node = node[k] + return node + def __str__(self): + s = str(self.entry) + "\n" + for k in self.iterkeys(): + s += str(k) + ":\n" + for row in str(self._children[k]).split("\n"): + if row: + s += " " + row + "\n" + return s |