[master 6/11] Add a __str__ method to DeviceTree.

dwlehman installerbot-noreply at redhat.com
Tue Mar 17 20:07:33 UTC 2015


From: David Lehman <dlehman at redhat.com>

---
 blivet/devicetree.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index cd56be1..8e66c3e 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -970,3 +970,22 @@ def getActiveMounts(self):
                 device.format.mountpoint = mountpoint   # for future mounts
                 device.format._mountpoint = mountpoint  # active mountpoint
                 device.format.mountopts = options
+
+    def __str__(self):
+        done = []
+        def show_subtree(root, depth):
+            abbreviate_subtree = root in done
+            s = "%s%s\n" % ("  " * depth, root)
+            done.append(root)
+            if abbreviate_subtree:
+                s += "%s...\n" % ("  " * (depth+1),)
+            else:
+                for child in self.getChildren(root):
+                    s += show_subtree(child, depth + 1)
+            return s
+
+        roots = [d for d in self._devices if not d.parents]
+        tree = ""
+        for root in roots:
+            tree += show_subtree(root, 0)
+        return tree


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/1d230f875602f6500e8fbab9fe0a6053a6d6876f


More information about the anaconda-patches mailing list