[pkg-fso-commits] [SCM] Various useful tools for an FSO installation branch, master, updated. debian/0.git20080812.2-32-gb5a13bb

Michael 'Mickey' Lauer mickey at vanille-media.de
Sun Sep 27 16:11:39 UTC 2009


The following commit has been merged in the master branch:
commit 19de58bbe1c80a547be35f86d315ac78a75cea2a
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Wed Oct 8 18:58:55 2008 +0800

    mdbus uses pprint to show its results now

diff --git a/mickeydbus/mdbus b/mickeydbus/mdbus
index 9ed6b25..b18db80 100755
--- a/mickeydbus/mdbus
+++ b/mickeydbus/mdbus
@@ -7,7 +7,7 @@ Mickey's own dbus introspection utility.
 GPLv2 or later
 """
 
-__version__ = "0.9.9.4"
+__version__ = "0.9.9.5"
 
 from xml.parsers.expat import ExpatError, ParserCreate
 from dbus.exceptions import IntrospectionParserException
@@ -163,51 +163,27 @@ def process_introspection_data(data):
         raise IntrospectionParserException('%s: %s' % (e.__class__, e))
 
 #----------------------------------------------------------------------------#
-def prettyPrint( expression ):
+def dbus_to_python(v):
 #----------------------------------------------------------------------------#
-    """
-    Pretty-print a dbus expression.
-
-    v0.8.0
-    """
-
-    def indent( contents, t = 0 ):
-        calldepth = len( inspect.stack() ) - 4
-        return "%s%s" % ( " "*calldepth*4, contents )
-
-    if type( expression ) == dbus.types.Struct:
-        result = ""
-        for val in expression:
-            result += "%s, " % prettyPrint(val)
-        return "( %s )" % result[:-2]
-
-    if type( expression ) == dbus.types.Array:
-        result = indent( "[\n" )
-        for val in expression:
-            result += indent( "    %s\n" % prettyPrint(val) )
-        result += indent( "]" )
-        return result
-
-    elif type( expression ) == dbus.types.Dictionary:
-        result = indent( "{\n" )
-        for key, val in expression.items():
-            result += indent( "    %s:%s\n" % ( prettyPrint(key), prettyPrint(val) ) )
-        result += indent( "}" )
-        return result
-
-    elif type( expression ) == dbus.types.String:
-        try:
-            printable = expression.decode( "ascii" )
-        except ( LookupError, UnicodeDecodeError, UnicodeEncodeError ):
-            return repr(expression)
-        else:
-            return "'%s'" % expression
-
+    if isinstance(v, dbus.Int32):
+        return int(v)
+    elif isinstance(v, dbus.String):
+        return str(v)
+    elif isinstance(v, dbus.Dictionary):
+        return dict( (dbus_to_python(k), dbus_to_python(v)) for k,v in v.iteritems() )
+    elif isinstance(v, dbus.Array):
+        return [dbus_to_python(x) for x in v]
+    elif isinstance(v, dbus.Struct):
+        return tuple(dbus_to_python(x) for x in v)
     else:
-        try:
-            return "%s" % expression
-        except ( TypeError, UnicodeDecodeError, UnicodeEncodeError ):
-            return repr(expression)
+        raise TypeError("Can't convert type %s to python object" % type(v))
+
+#----------------------------------------------------------------------------#
+def prettyPrint( expression ):
+#----------------------------------------------------------------------------#
+    from pprint import PrettyPrinter
+    pp = PrettyPrinter( indent=4 )
+    pp.pprint( dbus_to_python(expression) )
 
 #----------------------------------------------------------------------------#
 class Commands( object ):
@@ -261,7 +237,7 @@ class Commands( object ):
                 pass # python will emit its own error here
             else:
                 if result is not None:
-                    print prettyPrint( result )
+                    prettyPrint( result )
 
     def monitorBus( self ):
         self._runMainloop()

-- 
Various useful tools for an FSO installation



More information about the pkg-fso-commits mailing list