All of lore.kernel.org
 help / color / mirror / Atom feed
From: OpenBMC Patches <openbmc-patches@stwcx.xyz>
To: openbmc@lists.ozlabs.org
Cc: Brad Bishop <bradleyb@us.ibm.com>
Subject: [PATCH pyphosphor 2/4] Add dictionary export to PathTree
Date: Fri, 15 Apr 2016 07:50:45 -0500	[thread overview]
Message-ID: <1460724647-4184-3-git-send-email-openbmc-patches@stwcx.xyz> (raw)
In-Reply-To: <1460724647-4184-1-git-send-email-openbmc-patches@stwcx.xyz>

From: Brad Bishop <bradleyb@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.7.1

  parent reply	other threads:[~2016-04-15 12:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15 12:50 [PATCH pyphosphor 0/4] Pull OpenBMC Patches
2016-04-15 12:50 ` [PATCH pyphosphor 1/4] Introducing pyobmc OpenBMC Patches
2016-04-15 12:50 ` OpenBMC Patches [this message]
2016-04-15 12:50 ` [PATCH pyphosphor 3/4] Added python to dts encoder OpenBMC Patches
2016-04-19  4:24   ` Andrew Jeffery
2016-04-15 12:50 ` [PATCH pyphosphor 4/4] Move common code from REST server OpenBMC Patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1460724647-4184-3-git-send-email-openbmc-patches@stwcx.xyz \
    --to=openbmc-patches@stwcx.xyz \
    --cc=bradleyb@us.ibm.com \
    --cc=openbmc@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.