With the attached patch, it is possible to import the module without dbus (e.g. in chroot).
Ana
From 1740799d3b710d640abc97a2b0cda2e5c9e23d6a Mon Sep 17 00:00:00 2001 From: Ana Rodriguez <[email protected]> Date: Thu, 23 Aug 2018 13:15:34 +0200 Subject: [PATCH] See #57: gracefully handle dbus exception --- NetworkManager.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/NetworkManager.py b/NetworkManager.py index 28a0d0e..7301e00 100644 --- a/NetworkManager.py +++ b/NetworkManager.py @@ -96,7 +96,10 @@ SignalDispatcher = SignalDispatcher() # We completely dynamically generate all classes using introspection data. As # this is done at import time, use a special dbus connection that does not get # in the way of setting a mainloop and doing async stuff later. -init_bus = dbus.SystemBus(private=True) +try: + init_bus = dbus.SystemBus(private=True) +except dbus.exceptions.DBusException: + init_bus = None xml_cache = {} class NMDbusInterfaceType(type): @@ -129,9 +132,11 @@ class NMDbusInterfaceType(type): # If we know where to find this object, let's introspect it and # generate properties and methods if 'object_path' in attrs and attrs['object_path']: - proxy = init_bus.get_object(type_.dbus_service, attrs['object_path']) - attrs['introspection_data'] = proxy.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable') - root = etree.fromstring(attrs['introspection_data']) + root = [] + if init_bus is not None: + proxy = init_bus.get_object(type_.dbus_service, attrs['object_path']) + attrs['introspection_data'] = proxy.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable') + root = etree.fromstring(attrs['introspection_data']) for element in root: if element.tag == 'interface' and element.attrib['name'] in attrs['interface_names']: for item in element: @@ -711,7 +716,8 @@ class fixups(object): NetworkManager = NetworkManager() Settings = Settings() AgentManager = AgentManager() -init_bus.close() +if init_bus is not None: + init_bus.close() del init_bus del xml_cache -- 2.18.0
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Python-modules-team mailing list [email protected] https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/python-modules-team
