comparison src/core/sat_main.py @ 1026:71fdc327b318

core: getReady and asyncConnect now wait full initialisation, not only memory
author Goffi <goffi@goffi.org>
date Thu, 15 May 2014 20:01:56 +0200
parents 8bae81e254a2
children ee46515a12f2
comparison
equal deleted inserted replaced
1025:24fe24cfb363 1026:71fdc327b318
80 80
81 def __init__(self): 81 def __init__(self):
82 self._cb_map = {} # map from callback_id to callbacks 82 self._cb_map = {} # map from callback_id to callbacks
83 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) 83 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary)
84 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed 84 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed
85 self._initialised = defer.Deferred()
85 self.profiles = {} 86 self.profiles = {}
86 self.plugins = {} 87 self.plugins = {}
87 88
88 self.memory = Memory(self) 89 self.memory = Memory(self)
89 self.trigger = TriggerManager() # trigger are used to change SàT behaviour 90 self.trigger = TriggerManager() # trigger are used to change SàT behaviour
91 try: 92 try:
92 self.bridge = DBusBridge() 93 self.bridge = DBusBridge()
93 except exceptions.BridgeInitError: 94 except exceptions.BridgeInitError:
94 log.error(u"Bridge can't be initialised, can't start SàT core") 95 log.error(u"Bridge can't be initialised, can't start SàT core")
95 sys.exit(1) 96 sys.exit(1)
96 self.bridge.register("getReady", lambda: self.memory.initialized) 97 self.bridge.register("getReady", lambda: self._initialized)
97 self.bridge.register("getVersion", lambda: C.APP_VERSION) 98 self.bridge.register("getVersion", lambda: C.APP_VERSION)
98 self.bridge.register("getProfileName", self.memory.getProfileName) 99 self.bridge.register("getProfileName", self.memory.getProfileName)
99 self.bridge.register("getProfilesList", self.memory.getProfilesList) 100 self.bridge.register("getProfilesList", self.memory.getProfilesList)
100 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) 101 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
101 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) 102 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
142 def _postMemoryInit(self, ignore): 143 def _postMemoryInit(self, ignore):
143 """Method called after memory initialization is done""" 144 """Method called after memory initialization is done"""
144 log.info(_("Memory initialised")) 145 log.info(_("Memory initialised"))
145 self._import_plugins() 146 self._import_plugins()
146 ui_contact_list.ContactList(self) 147 ui_contact_list.ContactList(self)
148 self._initialised.callback(None)
147 149
148 def _import_plugins(self): 150 def _import_plugins(self):
149 """Import all plugins found in plugins directory""" 151 """Import all plugins found in plugins directory"""
150 import sat.plugins 152 import sat.plugins
151 plugins_path = os.path.dirname(sat.plugins.__file__) 153 plugins_path = os.path.dirname(sat.plugins.__file__)
202 204
203 def asyncConnect(self, profile_key=C.PROF_KEY_NONE): 205 def asyncConnect(self, profile_key=C.PROF_KEY_NONE):
204 """Connect to jabber server with asynchronous reply 206 """Connect to jabber server with asynchronous reply
205 @param profile_key: %(doc_profile)s 207 @param profile_key: %(doc_profile)s
206 """ 208 """
207 def backend_initialized(ignore): 209 def backendInitialised(dummy):
208 profile = self.memory.getProfileName(profile_key) 210 profile = self.memory.getProfileName(profile_key)
209 if not profile: 211 if not profile:
210 log.error(_('Trying to connect a non-existant profile')) 212 log.error(_('Trying to connect a non-existant profile'))
211 raise exceptions.ProfileUnknownError(profile_key) 213 raise exceptions.ProfileUnknownError(profile_key)
212 214
285 d.addCallback(pluginsConnection) 287 d.addCallback(pluginsConnection)
286 return d 288 return d
287 289
288 self.memory.startProfileSession(profile) 290 self.memory.startProfileSession(profile)
289 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) 291 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
290 return self.memory.initialized.addCallback(backend_initialized) 292 return self._initialised.addCallback(backendInitialised)
291 293
292 def disconnect(self, profile_key): 294 def disconnect(self, profile_key):
293 """disconnect from jabber server""" 295 """disconnect from jabber server"""
294 if not self.isConnected(profile_key): 296 if not self.isConnected(profile_key):
295 log.info(_("not connected !")) 297 log.info(_("not connected !"))