File: 0003-Gracefully-handle-dbus-exception.patch

package info (click to toggle)
python-networkmanager 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 336 kB
  • sloc: python: 1,806; makefile: 116
file content (49 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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