Skip to content

Commit

Permalink
Add a __str__ method to DeviceTree.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwlehman committed Mar 19, 2015
1 parent bf390e6 commit d1f2264
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions blivet/devicetree.py
Expand Up @@ -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

0 comments on commit d1f2264

Please sign in to comment.