diff src/bridge/bridge_constructor/dbus_core_template.py @ 627:d207c2186519

core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised: - new BridgeInitError and BridgeExceptionNoService are in core.exceptions - D-Bus NotSupported is catched in bridge, and launch a BridgeInitError - BridgeInitError stop SàT core, jp, and quick_frontends with an explanation message. fix bug 27
author Goffi <goffi@goffi.org>
date Fri, 21 Jun 2013 02:00:37 +0200
parents 84a6e83157c2
children 1def5b7edf9f
line wrap: on
line diff
--- a/src/bridge/bridge_constructor/dbus_core_template.py	Thu Jun 20 17:44:27 2013 +0200
+++ b/src/bridge/bridge_constructor/dbus_core_template.py	Fri Jun 21 02:00:37 2013 +0200
@@ -24,6 +24,7 @@
 import inspect
 from logging import debug, info, error
 from twisted.internet.defer import Deferred
+from sat.core.exceptions import BridgeInitError
 
 const_INT_PREFIX = "org.goffi.SAT"  # Interface prefix
 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
@@ -204,7 +205,12 @@
         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
         Bridge.__init__(self)
         info("Init DBus...")
-        self.session_bus = dbus.SessionBus()
+        try:
+            self.session_bus = dbus.SessionBus()
+        except dbus.DBusException as e:
+            if e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
+                print u"D-Bus is not launched, please see README to see instructions on how to launch it"
+            raise BridgeInitError
         self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
         self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH)