[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 748949c4c3ae7e0c5cea446f901699fe172975d8
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Sun Aug 17 19:03:54 2008 +0200

    mickeydbus: add prettyprinting

diff --git a/mickeydbus/TODO b/mickeydbus/TODO
index 86ad758..64149a4 100644
--- a/mickeydbus/TODO
+++ b/mickeydbus/TODO
@@ -1,5 +1,5 @@
 for 1.0:
- * pretty printing results
+ * fix bugs
  * before starting to listen, check out whether the requested busname/objname actually exists
 
 for 1.1:
diff --git a/mickeydbus/mdbus b/mickeydbus/mdbus
index f8dd950..7c17247 100755
--- a/mickeydbus/mdbus
+++ b/mickeydbus/mdbus
@@ -7,7 +7,7 @@ Mickey's own dbus introspection utility.
 GPLv2 or later
 """
 
-__version__ = "0.9.9.2"
+__version__ = "0.9.9.3"
 
 from xml.parsers.expat import ExpatError, ParserCreate
 from dbus.exceptions import IntrospectionParserException
@@ -163,6 +163,53 @@ def process_introspection_data(data):
         raise IntrospectionParserException('%s: %s' % (e.__class__, e))
 
 #----------------------------------------------------------------------------#
+def prettyPrint( expression ):
+#----------------------------------------------------------------------------#
+    """
+    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
+
+    else:
+        try:
+            return "%s" % expression
+        except ( TypeError, UnicodeDecodeError, UnicodeEncodeError ):
+            return repr(expression)
+
+#----------------------------------------------------------------------------#
 class Commands( object ):
 #----------------------------------------------------------------------------#
     """
@@ -213,11 +260,8 @@ class Commands( object ):
             except TypeError, e:
                 pass # python will emit its own error here
             else:
-                print "%s: %s -> " % ( objname, methodname ),
                 if result is not None:
-                    self._prettyPrint( result )
-                else:
-                    print
+                    print prettyPrint( result )
 
     def monitorBus( self ):
         self._runMainloop()
@@ -346,6 +390,7 @@ if __name__ == "__main__":
     import dbus
     import sys
     import time
+    import inspect
 
     argv = sys.argv[::-1]
     execname = argv.pop()
@@ -421,6 +466,8 @@ if __name__ == "__main__":
                 continue
             try:
                 parameter = eval( string )
+                if type( parameter ) == type( all ): # must be an error, we don't want FunctionOrMethod
+                    raise SyntaxError
             except ( NameError, SyntaxError ): # treat as string
                 parameter = eval( '"""%s"""' % string )
                 if escape:

-- 
Various useful tools for an FSO installation



More information about the pkg-fso-commits mailing list