[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XenPPC] [xenppc-unstable] [XEND][POWERPC] nicely display flat device tree



# HG changeset patch
# User Hollis Blanchard <hollisb@xxxxxxxxxx>
# Node ID 7a77cf4a7428fff092aa94226ed29a6e333c56e7
# Parent  6eccd4911e6c084bcc3d8bc1de8bbdb6e343f132
[XEND][POWERPC] nicely display flat device tree
Signed-off-by: Hollis Blanchard <hollisb@xxxxxxxxxx>
---
 tools/python/xen/xend/FlatDeviceTree.py |   35 ++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+)

diff -r 6eccd4911e6c -r 7a77cf4a7428 tools/python/xen/xend/FlatDeviceTree.py
--- a/tools/python/xen/xend/FlatDeviceTree.py   Tue Aug 22 11:17:09 2006 -0400
+++ b/tools/python/xen/xend/FlatDeviceTree.py   Tue Aug 22 14:43:22 2006 -0500
@@ -20,6 +20,7 @@ import os
 import os
 import sys
 import struct
+import re
 
 _OF_DT_HEADER = 0xd00dfeed
 _OF_DT_BEGIN_NODE = 0x1
@@ -50,12 +51,40 @@ def _pad(buf, alignment):
     # not present in Python 2.3:
     #return buf.ljust(_padlen, '\0')
 
+def _indent(item):
+    indented = []
+    for line in str(item).splitlines(True):
+        indented.append('    ' + line)
+    return ''.join(indented)
+
 class _Property:
+    _nonprint = re.compile('[\000-\037\200-\377]')
     def __init__(self, node, name, value):
         self.node = node
         self.value = value
         self.name = name
         self.node.tree.stradd(name)
+
+    def __str__(self):
+        result = self.name
+        if self.value:
+            searchtext = self.value
+            # it's ok for a string to end in NULL
+            if searchtext.find('\000') == len(searchtext)-1:
+                searchtext = searchtext[:-1]
+            m = self._nonprint.search(searchtext)
+            if m:
+                bytes = struct.unpack("B" * len(self.value), self.value)
+                hexbytes = [ '%02x' % b for b in bytes ]
+                words = []
+                for i in range(0, len(self.value), 4):
+                    words.append(''.join(hexbytes[i:i+4]))
+                v = '<' + ' '.join(words) + '>'
+            else:
+                v = '"%s"' % self.value
+            result += ': ' + v
+        return result
+
     def to_bin(self):
         offset = self.node.tree.stroffset(self.name)
         return struct.pack('>III', _OF_DT_PROP, len(self.value), offset) \
@@ -68,6 +97,12 @@ class _Node:
         self.props = {}
         self.children = {}
         self.phandle = 0
+
+    def __str__(self):
+        propstrs = [ _indent(prop) for prop in self.props.values() ]
+        childstrs = [ _indent(child) for child in self.children.values() ]
+        return '%s:\n%s\n%s' % (self.name, '\n'.join(propstrs),
+            '\n'.join(childstrs))
 
     def to_bin(self):
         name = _pad(self.name + '\0', 4)

_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.