Description: Gracefully handle dbus exception, e.g. for testing in chroot
Author: Ana Rodriguez Lopez <arl@ammonit.com>
Origin: other
Bug: https://github.com/seveas/python-networkmanager/issues/57
Bug-Debian: https://bugs.debian.org/896281
Last-Update: 2018-08-31
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: python-networkmanager/NetworkManager.py
===================================================================
--- python-networkmanager.orig/NetworkManager.py
+++ python-networkmanager/NetworkManager.py
@@ -101,7 +101,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):
@@ -134,9 +137,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:
@@ -762,7 +767,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
 
