[PATCH pyphosphor v2 2/4] Add dictionary export to PathTree
OpenBMC Patches
openbmc-patches at stwcx.xyz
Sat Apr 30 03:10:45 AEST 2016
From: Brad Bishop <bradleyb at us.ibm.com>
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.
---
obmc/utils/pathtree.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
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
--
2.8.1
More information about the openbmc
mailing list