3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-24 23:42:42 +01:00

test: Use python3 coding style in monitor-iwd

This commit is contained in:
Denis Kenzior 2016-09-13 21:38:34 -05:00
parent f77d363840
commit e14045442a

View File

@ -6,67 +6,66 @@ import dbus
import dbus.mainloop.glib import dbus.mainloop.glib
_dbus2py = { _dbus2py = {
dbus.String : str, dbus.String : str,
dbus.UInt32 : int, dbus.UInt32 : int,
dbus.Int32 : int, dbus.Int32 : int,
dbus.Int16 : int, dbus.Int16 : int,
dbus.UInt16 : int, dbus.UInt16 : int,
dbus.UInt64 : int, dbus.UInt64 : int,
dbus.Int64 : int, dbus.Int64 : int,
dbus.Byte : int, dbus.Byte : int,
dbus.Boolean : bool, dbus.Boolean : bool,
dbus.ByteArray : str, dbus.ByteArray : str,
dbus.ObjectPath : str dbus.ObjectPath : str
} }
def dbus2py(d): def dbus2py(d):
t = type(d) t = type(d)
if t in _dbus2py: if t in _dbus2py:
return _dbus2py[t](d) return _dbus2py[t](d)
if t is dbus.Dictionary: if t is dbus.Dictionary:
return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()]) return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
if t is dbus.Array and d.signature == "y": if t is dbus.Array and d.signature == "y":
return "".join([chr(b) for b in d]) return "".join([chr(b) for b in d])
if t is dbus.Array or t is list: if t is dbus.Array or t is list:
return [dbus2py(v) for v in d] return [dbus2py(v) for v in d]
if t is dbus.Struct or t is tuple: if t is dbus.Struct or t is tuple:
return tuple([dbus2py(v) for v in d]) return tuple([dbus2py(v) for v in d])
return d return d
def pretty(d): def pretty(d):
d = dbus2py(d) d = dbus2py(d)
t = type(d) t = type(d)
if t in (dict, tuple, list) and len(d) > 0: if t in (dict, tuple, list) and len(d) > 0:
if t is dict: if t is dict:
d = ", ".join(["%s = %s" % (k, pretty(v)) d = ", ".join(["%s = %s" % (k, pretty(v)) for k, v in d.items()])
for k, v in d.items()]) return "{ %s }" % d
return "{ %s }" % d
d = " ".join([pretty(e) for e in d]) d = " ".join([pretty(e) for e in d])
if t is tuple: if t is tuple:
return "( %s )" % d return "( %s )" % d
if t is str: if t is str:
return "%s" % d return "%s" % d
return str(d) return str(d)
def property_changed(name, value, path, interface): def property_changed(name, value, path, interface):
iface = interface[interface.rfind(".") + 1:] iface = interface[interface.rfind(".") + 1:]
print("{%s} [%s] %s = %s" % (iface, path, name, pretty(value))) print("{%s} [%s] %s = %s" % (iface, path, name, pretty(value)))
if __name__ == '__main__': if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus() bus = dbus.SystemBus()
bus.add_signal_receiver(property_changed, bus.add_signal_receiver(property_changed,
bus_name="net.connman.iwd", bus_name="net.connman.iwd",
signal_name = "PropertyChanged", signal_name = "PropertyChanged",
path_keyword="path", path_keyword="path",
interface_keyword="interface") interface_keyword="interface")
mainloop = GLib.MainLoop() mainloop = GLib.MainLoop()
mainloop.run() mainloop.run()