comparison 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
comparison
equal deleted inserted replaced
2087:159250d66407 2088:c02f96756d5c
23 from twisted.internet import defer 23 from twisted.internet import defer
24 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
25 from twisted.words.xish import domish 25 from twisted.words.xish import domish
26 from twisted.internet import reactor 26 from twisted.internet import reactor
27 from wokkel.xmppim import RosterItem 27 from wokkel.xmppim import RosterItem
28 from sat.bridge.dbus_bridge import Bridge
29 from sat.core import xmpp 28 from sat.core import xmpp
30 from sat.core import exceptions 29 from sat.core import exceptions
31 from sat.core.log import getLogger 30 from sat.core.log import getLogger
32 log = getLogger(__name__) 31 log = getLogger(__name__)
33 from sat.core.constants import Const as C 32 from sat.core.constants import Const as C
34 from sat.memory.memory import Memory 33 from sat.memory.memory import Memory
35 from sat.tools import trigger 34 from sat.tools import trigger
36 from sat.tools import utils 35 from sat.tools import utils
36 from sat.tools.common import dynamic_import
37 from sat.stdui import ui_contact_list, ui_profile_manager 37 from sat.stdui import ui_contact_list, ui_profile_manager
38 from glob import glob 38 from glob import glob
39 from uuid import uuid4 39 from uuid import uuid4
40 import sys 40 import sys
41 import os.path 41 import os.path
58 self.plugins = {} 58 self.plugins = {}
59 59
60 self.memory = Memory(self) 60 self.memory = Memory(self)
61 self.trigger = trigger.TriggerManager() # trigger are used to change SàT behaviour 61 self.trigger = trigger.TriggerManager() # trigger are used to change SàT behaviour
62 62
63 try: 63 bridge_name = self.memory.getConfig('', 'bridge', 'dbus')
64 self.bridge = Bridge() 64
65 bridge_module = dynamic_import.bridge(bridge_name)
66 if bridge_module is None:
67 log.error(u"Can't find bridge module of name {}".format(bridge_name))
68 sys.exit(1)
69 log.info(u"using {} bridge".format(bridge_name))
70 try:
71 self.bridge = bridge_module.Bridge()
65 except exceptions.BridgeInitError: 72 except exceptions.BridgeInitError:
66 log.error(u"Bridge can't be initialised, can't start SàT core") 73 log.error(u"Bridge can't be initialised, can't start SàT core")
67 sys.exit(1) 74 sys.exit(1)
68 self.bridge.register_method("getReady", lambda: self.initialised) 75 self.bridge.register_method("getReady", lambda: self.initialised)
69 self.bridge.register_method("getVersion", lambda: self.full_version) 76 self.bridge.register_method("getVersion", lambda: self.full_version)
130 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat)) 137 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat))
131 return self._version_cache 138 return self._version_cache
132 else: 139 else:
133 return version 140 return version
134 141
142 @property
143 def bridge_name(self):
144 return os.path.splitext(os.path.basename(self.bridge.__file__))[0]
145
135 def _postMemoryInit(self, ignore): 146 def _postMemoryInit(self, ignore):
136 """Method called after memory initialization is done""" 147 """Method called after memory initialization is done"""
137 log.info(_("Memory initialised")) 148 log.info(_("Memory initialised"))
138 self._import_plugins() 149 self._import_plugins()
139 ui_contact_list.ContactList(self) 150 ui_contact_list.ContactList(self)