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
=== modified file 'autopilot/dbus_handler.py'
--- autopilot/dbus_handler.py 2013-04-30 16:30:25 +0000
+++ autopilot/dbus_handler.py 2013-05-02 16:31:28 +0000
@@ -22,23 +22,47 @@
2222
23from __future__ import absolute_import23from __future__ import absolute_import
2424
25from dbus._dbus import BusConnection
25import dbus26import dbus
26from dbus.mainloop.glib import DBusGMainLoop27from dbus.mainloop.glib import DBusGMainLoop
2728
28_glib_loop_set = False29_glib_loop_set = False
2930
30def get_session_bus():31# DBus has an annoying bug where we need to initialise it with the gobject main
31 """This function returns a session bus that has had the DBus GLib main loop32# loop *before* it's initialised anywhere else. This module exists so we can
32 initialised.33# initialise the dbus module once, and once only.
3334
34 """35
36def _ensure_glib_loop_set():
35 global _glib_loop_set37 global _glib_loop_set
36 if not _glib_loop_set:38 if not _glib_loop_set:
37 #
38 # DBus has an annoying bug where we need to initialise it with the gobject main
39 # loop *before* it's initialised anywhere else. This module exists so we can
40 # initialise the dbus module once, and once only.
41 DBusGMainLoop(set_as_default=True)39 DBusGMainLoop(set_as_default=True)
42 _glib_loop_set = True40 _glib_loop_set = True
43 # create a global session bus object:41
42
43def get_session_bus():
44 """This function returns a session bus that has had the DBus GLib main loop
45 initialised.
46
47 """
48 _ensure_glib_loop_set()
44 return dbus.SessionBus()49 return dbus.SessionBus()
50
51
52def get_system_bus():
53 """This function returns a system bus that has had the DBus GLib main loop
54 initialised.
55
56 """
57 _ensure_glib_loop_set()
58 return dbus.SystemBus()
59
60
61def get_custom_bus(bus_address):
62 """This function returns a custom bus that has had the DBus GLib main loop
63 initialised.
64
65 """
66 _ensure_glib_loop_set()
67 return BusConnection(bus_address)
68
4569
=== modified file 'autopilot/introspection/backends.py'
--- autopilot/introspection/backends.py 2013-04-30 16:21:30 +0000
+++ autopilot/introspection/backends.py 2013-05-02 16:31:28 +0000
@@ -20,9 +20,12 @@
20"Backend interface for autopilot."20"Backend interface for autopilot."
21from __future__ import absolute_import21from __future__ import absolute_import
2222
23from dbus._dbus import BusConnection
24import dbus23import dbus
2524from autopilot.dbus_handler import (
25 get_session_bus,
26 get_system_bus,
27 get_custom_bus,
28 )
26from autopilot.introspection.constants import (29from autopilot.introspection.constants import (
27 AP_INTROSPECTION_IFACE,30 AP_INTROSPECTION_IFACE,
28 DBUS_INTROSPECTION_IFACE,31 DBUS_INTROSPECTION_IFACE,
@@ -37,12 +40,12 @@
37 @staticmethod40 @staticmethod
38 def SessionBus(connection, object_path):41 def SessionBus(connection, object_path):
39 """Construct a DBusAddress that backs on to the session bus."""42 """Construct a DBusAddress that backs on to the session bus."""
40 return DBusAddress(dbus.SessionBus(), connection, object_path)43 return DBusAddress(get_session_bus(), connection, object_path)
4144
42 @staticmethod45 @staticmethod
43 def SystemBus(connection, object_path):46 def SystemBus(connection, object_path):
44 """Construct a DBusAddress that backs on to the system bus."""47 """Construct a DBusAddress that backs on to the system bus."""
45 return DBusAddress(dbus.SystemBus(), connection, object_path)48 return DBusAddress(get_system_bus(), connection, object_path)
4649
47 @staticmethod50 @staticmethod
48 def CustomBus(bus_address, connection, object_path):51 def CustomBus(bus_address, connection, object_path):
@@ -52,7 +55,7 @@
52 connect to.55 connect to.
5356
54 """57 """
55 return DBusAddress(BusConnection(bus_address), connection, object_path)58 return DBusAddress(get_custom_bus(bus_address), connection, object_path)
5659
57 def __init__(self, bus, connection, object_path):60 def __init__(self, bus, connection, object_path):
58 """Construct a DBusAddress instance.61 """Construct a DBusAddress instance.
@@ -108,9 +111,9 @@
108 return repr(self)111 return repr(self)
109112
110 def __repr__(self):113 def __repr__(self):
111 if self._bus_type == dbus.Bus.TYPE_SESSION:114 if self._bus._bus_type == dbus.Bus.TYPE_SESSION:
112 name = "session"115 name = "session"
113 elif self._bus_type == dbus.Bus.TYPE_SYSTEM:116 elif self._bus._bus_type == dbus.Bus.TYPE_SYSTEM:
114 name = "system"117 name = "system"
115 else:118 else:
116 name = "custom"119 name = "custom"

Subscribers

People subscribed via source and target branches