diff options
author | Pekka Pessi <Pekka.Pessi@nokia.com> | 2010-08-25 14:57:01 +0300 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-08-25 11:39:06 -0500 |
commit | f24a5d7b182cb082faf0d99a671f77ba25613fe7 (patch) | |
tree | 13959d7b907b65c432fa78c675dda135a365cd14 /test/monitor-ofono | |
parent | 74a88dda8136d94c508840289e65b747b44a85c4 (diff) | |
download | ofono-f24a5d7b182cb082faf0d99a671f77ba25613fe7.tar.bz2 |
monitor-ofono: deep pretty-print
Diffstat (limited to 'test/monitor-ofono')
-rwxr-xr-x | test/monitor-ofono | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/test/monitor-ofono b/test/monitor-ofono index a441d5df..94febac2 100755 --- a/test/monitor-ofono +++ b/test/monitor-ofono @@ -5,22 +5,54 @@ import gobject import dbus import dbus.mainloop.glib +_dbus2py = { + dbus.String : unicode, + dbus.UInt32 : int, + dbus.Int32 : int, + dbus.Int16 : int, + dbus.UInt16 : int, + dbus.UInt64 : int, + dbus.Int64 : int, + dbus.Byte : int, + dbus.Boolean : bool, + dbus.ByteArray : str, + dbus.ObjectPath : str + } + +def dbus2py(d): + t = type(d) + if t in _dbus2py: + return _dbus2py[t](d) + if t is dbus.Dictionary: + return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()]) + if t is dbus.Array and d.signature == "y": + return "".join([chr(b) for b in d]) + if t is dbus.Array or t is list: + return [dbus2py(v) for v in d] + if t is dbus.Struct or t is tuple: + return tuple([dbus2py(v) for v in d]) + return d + +def pretty(d): + d = dbus2py(d) + t = type(d) + + if t in (dict, tuple, list) and len(d) > 0: + if t is dict: + d = ", ".join(["%s = %s" % (k, pretty(v)) + for k, v in d.items()]) + return "{ %s }" % d + + d = " ".join([pretty(e) for e in d]) + + if t is tuple: + return "( %s )" % d + + return str(d) + def property_changed(name, value, path, interface): iface = interface[interface.rfind(".") + 1:] - if name in ["Modems", "Interfaces", "Features", - "Technologies", - "SubscriberNumbers", - "EmergencyNumbers", - "PreferredLanguages"]: - val = "" - for i in value: - val += i + " " - elif name in ["MobileNetworkCodeLength", - "VoicemailMessageCount"]: - val = int(value) - else: - val = str(value) - print "{%s} [%s] %s = %s" % (iface, path, name, val) + print "{%s} [%s] %s = %s" % (iface, path, name, pretty(value)) if __name__ == '__main__': dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |