diff src/core/sat_main.py @ 2088:c02f96756d5c

core: bridge can now be changed in conf by default DBus bridge is used, but this can be changed in sat.conf's DEFAULT section using "bridge" option. bridge can be "dbus" (or equivalent "dbus_bridge") or embedded at the moment. Bridge name used is saved in SAT.bridge_name, and load_bridge method can be used by frontends.
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 18:16:37 +0100
parents 4633cfcbcccb
children 0931b5a6213c
line wrap: on
line diff
--- a/src/core/sat_main.py	Wed Oct 05 22:07:51 2016 +0200
+++ b/src/core/sat_main.py	Sun Dec 04 18:16:37 2016 +0100
@@ -25,7 +25,6 @@
 from twisted.words.xish import domish
 from twisted.internet import reactor
 from wokkel.xmppim import RosterItem
-from sat.bridge.dbus_bridge import Bridge
 from sat.core import xmpp
 from sat.core import exceptions
 from sat.core.log import getLogger
@@ -34,6 +33,7 @@
 from sat.memory.memory import Memory
 from sat.tools import trigger
 from sat.tools import utils
+from sat.tools.common import dynamic_import
 from sat.stdui import ui_contact_list, ui_profile_manager
 from glob import glob
 from uuid import uuid4
@@ -60,8 +60,15 @@
         self.memory = Memory(self)
         self.trigger = trigger.TriggerManager()  # trigger are used to change SàT behaviour
 
+        bridge_name = self.memory.getConfig('', 'bridge', 'dbus')
+
+        bridge_module = dynamic_import.bridge(bridge_name)
+        if bridge_module is None:
+            log.error(u"Can't find bridge module of name {}".format(bridge_name))
+            sys.exit(1)
+        log.info(u"using {} bridge".format(bridge_name))
         try:
-            self.bridge = Bridge()
+            self.bridge = bridge_module.Bridge()
         except exceptions.BridgeInitError:
             log.error(u"Bridge can't be initialised, can't start SàT core")
             sys.exit(1)
@@ -132,6 +139,10 @@
         else:
             return version
 
+    @property
+    def bridge_name(self):
+        return os.path.splitext(os.path.basename(self.bridge.__file__))[0]
+
     def _postMemoryInit(self, ignore):
         """Method called after memory initialization is done"""
         log.info(_("Memory initialised"))