Merge lp:~veebers/autopilot/get_session_gloop_fix into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 187
Merged at revision: 188
Proposed branch: lp:~veebers/autopilot/get_session_gloop_fix
Merge into: lp:autopilot
Diff against target: 116 lines (+44/-17)
2 files modified
autopilot/dbus_handler.py (+34/-10)
autopilot/introspection/backends.py (+10/-7)
To merge this branch: bzr merge lp:~veebers/autopilot/get_session_gloop_fix
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+162146@code.launchpad.net

Commit message

Fixes expceptions thrown due to dbuss sessions created before gobject main loop

Description of the change

Fixes expceptions thrown due to dbuss sessions created before gobject main loop

To post a comment you must log in.
187. By Christopher Lee

Oops missed one. Also whitespace/order fix

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/dbus_handler.py'
2--- autopilot/dbus_handler.py 2013-04-30 16:30:25 +0000
3+++ autopilot/dbus_handler.py 2013-05-02 16:31:28 +0000
4@@ -22,23 +22,47 @@
5
6 from __future__ import absolute_import
7
8+from dbus._dbus import BusConnection
9 import dbus
10 from dbus.mainloop.glib import DBusGMainLoop
11
12 _glib_loop_set = False
13
14-def get_session_bus():
15- """This function returns a session bus that has had the DBus GLib main loop
16- initialised.
17-
18- """
19+# DBus has an annoying bug where we need to initialise it with the gobject main
20+# loop *before* it's initialised anywhere else. This module exists so we can
21+# initialise the dbus module once, and once only.
22+
23+
24+def _ensure_glib_loop_set():
25 global _glib_loop_set
26 if not _glib_loop_set:
27- #
28- # DBus has an annoying bug where we need to initialise it with the gobject main
29- # loop *before* it's initialised anywhere else. This module exists so we can
30- # initialise the dbus module once, and once only.
31 DBusGMainLoop(set_as_default=True)
32 _glib_loop_set = True
33- # create a global session bus object:
34+
35+
36+def get_session_bus():
37+ """This function returns a session bus that has had the DBus GLib main loop
38+ initialised.
39+
40+ """
41+ _ensure_glib_loop_set()
42 return dbus.SessionBus()
43+
44+
45+def get_system_bus():
46+ """This function returns a system bus that has had the DBus GLib main loop
47+ initialised.
48+
49+ """
50+ _ensure_glib_loop_set()
51+ return dbus.SystemBus()
52+
53+
54+def get_custom_bus(bus_address):
55+ """This function returns a custom bus that has had the DBus GLib main loop
56+ initialised.
57+
58+ """
59+ _ensure_glib_loop_set()
60+ return BusConnection(bus_address)
61+
62
63=== modified file 'autopilot/introspection/backends.py'
64--- autopilot/introspection/backends.py 2013-04-30 16:21:30 +0000
65+++ autopilot/introspection/backends.py 2013-05-02 16:31:28 +0000
66@@ -20,9 +20,12 @@
67 "Backend interface for autopilot."
68 from __future__ import absolute_import
69
70-from dbus._dbus import BusConnection
71 import dbus
72-
73+from autopilot.dbus_handler import (
74+ get_session_bus,
75+ get_system_bus,
76+ get_custom_bus,
77+ )
78 from autopilot.introspection.constants import (
79 AP_INTROSPECTION_IFACE,
80 DBUS_INTROSPECTION_IFACE,
81@@ -37,12 +40,12 @@
82 @staticmethod
83 def SessionBus(connection, object_path):
84 """Construct a DBusAddress that backs on to the session bus."""
85- return DBusAddress(dbus.SessionBus(), connection, object_path)
86+ return DBusAddress(get_session_bus(), connection, object_path)
87
88 @staticmethod
89 def SystemBus(connection, object_path):
90 """Construct a DBusAddress that backs on to the system bus."""
91- return DBusAddress(dbus.SystemBus(), connection, object_path)
92+ return DBusAddress(get_system_bus(), connection, object_path)
93
94 @staticmethod
95 def CustomBus(bus_address, connection, object_path):
96@@ -52,7 +55,7 @@
97 connect to.
98
99 """
100- return DBusAddress(BusConnection(bus_address), connection, object_path)
101+ return DBusAddress(get_custom_bus(bus_address), connection, object_path)
102
103 def __init__(self, bus, connection, object_path):
104 """Construct a DBusAddress instance.
105@@ -108,9 +111,9 @@
106 return repr(self)
107
108 def __repr__(self):
109- if self._bus_type == dbus.Bus.TYPE_SESSION:
110+ if self._bus._bus_type == dbus.Bus.TYPE_SESSION:
111 name = "session"
112- elif self._bus_type == dbus.Bus.TYPE_SYSTEM:
113+ elif self._bus._bus_type == dbus.Bus.TYPE_SYSTEM:
114 name = "system"
115 else:
116 name = "custom"

Subscribers

People subscribed via source and target branches