Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add debugging functionality

  • Loading branch information...
commit ab4a6e778fe41e299c36f89dc1a81f85de00533b 1 parent 9fc5872
@seveas authored
Showing with 23 additions and 12 deletions.
  1. +21 −10 NetworkManager.py
  2. +2 −2 examples/connection_detail.py
View
31 NetworkManager.py
@@ -5,6 +5,7 @@
# License: GPL3+
import dbus
+import os
import socket
import struct
import sys
@@ -16,6 +17,14 @@
elif not hasattr(__builtins__, 'bytes'):
bytes = lambda x, y=None: chr(x[0]) if x else x
+try:
+ debuglevel = int(os.environ['NM_DEBUG'])
+ def debug(msg, data):
+ sys.stderr.write(msg + "\n")
+ sys.stderr.write(repr(data)+"\n")
+except:
+ debug = lambda *args: None
+
class NMDbusInterface(object):
bus = dbus.SystemBus()
dbus_service = 'org.freedesktop.NetworkManager'
@@ -42,13 +51,13 @@ def __init__(self, object_path=None):
def _make_property(self, name):
def get(self):
- data = self.unwrap(self.proxy.Get(self.interface_name, name,
- dbus_interface='org.freedesktop.DBus.Properties'))
- return self.postprocess(name, data)
+ data = self.proxy.Get(self.interface_name, name, dbus_interface='org.freedesktop.DBus.Properties')
+ debug("Received property %s.%s" % (self.interface_name, name), data)
+ return self.postprocess(name, self.unwrap(data))
def set(self, value):
- data = self.preprocess(name, data)
- return self.proxy.Set(self.interface_name, name, self.wrap(value),
- dbus_interface='org.freedesktop.DBus.Properties')
+ data = self.wrap(self.preprocess(name, data))
+ debug("Setting property %s.%s" % (self.interface_name, name), value)
+ return self.proxy.Set(self.interface_name, name, value, dbus_interface='org.freedesktop.DBus.Properties')
return property(get, set)
def unwrap(self, val):
@@ -99,11 +108,13 @@ def __getattr__(self, name):
def make_proxy_call(self, name):
def proxy_call(*args, **kwargs):
func = getattr(self.interface, name)
+ args, kwargs = self.preprocess(name, args, kwargs)
args = self.wrap(args)
kwargs = self.wrap(kwargs)
- args, kwargs = self.preprocess(name, args, kwargs)
- ret = self.unwrap(func(*args, **kwargs))
- return self.postprocess(name, ret)
+ debug("Calling function %s.%s" % (self.interface_name, name), (args, kwargs))
+ ret = func(*args, **kwargs)
+ debug("Received return value for %s.%s" % (self.interface_name, name), ret)
+ return self.postprocess(name, self.unwrap(ret))
return proxy_call
def connect_to_signal(self, signal, handler, *args, **kwargs):
@@ -254,7 +265,7 @@ def postprocess(self, name, val):
if name == 'Routes':
return [fixups.route_to_python(route) for route in val]
if name in ('Nameservers', 'WinsServers'):
- return [fixups.add_to_python(addr) for addr in val]
+ return [fixups.addr_to_python(addr) for addr in val]
return val
class IP6Config(NMDbusInterface):
View
4 examples/connection_detail.py
@@ -36,10 +36,10 @@
print(" IPv4 config")
print(" Addresses")
for addr in dev.Ip4Config.Addresses:
- print(" %s/%d -> %s" % addr)
+ print(" %s/%d -> %s" % tuple(addr))
print(" Routes")
for route in dev.Ip4Config.Routes:
- print(" %s/%d -> %s (%d)" % route)
+ print(" %s/%d -> %s (%d)" % tuple(route))
print(" Nameservers")
for ns in dev.Ip4Config.Nameservers:
print(" %s" % ns)
Please sign in to comment.
Something went wrong with that request. Please try again.