diff options
| author | Brad Bishop <bradleyb@us.ibm.com> | 2016-04-01 14:29:46 -0400 |
|---|---|---|
| committer | Brad Bishop <bradleyb@us.ibm.com> | 2016-04-15 08:44:02 -0400 |
| commit | 4e601a0a4441c802b294f16db97eca0312134683 (patch) | |
| tree | bbc54c7a31ea23f881398208a87af711347417cc /obmc/utils | |
| parent | 8ffe1e4424799a58e7f664a982b9417f5555d12d (diff) | |
| download | pyphosphor-4e601a0a4441c802b294f16db97eca0312134683.tar.gz pyphosphor-4e601a0a4441c802b294f16db97eca0312134683.zip | |
Add dictionary export to PathTree
PathTree is a dictionary extension with paths as keys and lets
you do things like iterate on subpaths, etc. Internally it is
implemented as a nested dictionary but on the outside it acts
like a normal dictionary.
This change enables exporting a PathTree structure as a nested
dictionary, which is useful for python_2_xyz encoders that understand
nested data structures.
Diffstat (limited to 'obmc/utils')
| -rw-r--r-- | obmc/utils/pathtree.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/obmc/utils/pathtree.py b/obmc/utils/pathtree.py index 221495e..a13c6cb 100644 --- a/obmc/utils/pathtree.py +++ b/obmc/utils/pathtree.py @@ -181,3 +181,17 @@ class PathTree: if not self.root: return {}.iteritems() return PathTreeItemIterator(self, subtree, depth) + + def dumpd(self, subtree='/'): + result = {} + d = result + + for k, v in self.iteritems(subtree): + elements = ['/'] + filter(bool, k.split('/')) + d = result + for k in elements: + d = d.setdefault(k, {}) + if v is not None: + d.update(v) + + return result |

