comparison src/core/sat_main.py @ 972:07b817f5a197

core: better plugin initialisation sequence: - profileConnected are now executed in a deferredList, instead of one after the other - failure are collected, and a global message show which plugins failed and the failure message
author Goffi <goffi@goffi.org>
date Wed, 02 Apr 2014 12:31:23 +0200
parents 723f28cd15c7
children 3a96920c07b7
comparison
equal deleted inserted replaced
971:8ca5c990ed92 972:07b817f5a197
202 202
203 def asyncConnect(self, profile_key=C.PROF_KEY_NONE): 203 def asyncConnect(self, profile_key=C.PROF_KEY_NONE):
204 """Connect to jabber server with asynchronous reply 204 """Connect to jabber server with asynchronous reply
205 @param profile_key: %(doc_profile)s 205 @param profile_key: %(doc_profile)s
206 """ 206 """
207
208 profile = self.memory.getProfileName(profile_key) 207 profile = self.memory.getProfileName(profile_key)
209 if not profile: 208 if not profile:
210 error(_('Trying to connect a non-exsitant profile')) 209 error(_('Trying to connect a non-exsitant profile'))
211 raise exceptions.ProfileUnknownError(profile_key) 210 raise exceptions.ProfileUnknownError(profile_key)
212 211
253 for plugin in self.plugins.iteritems(): 252 for plugin in self.plugins.iteritems():
254 if plugin[1].is_handler: 253 if plugin[1].is_handler:
255 plugin[1].getHandler(profile).setHandlerParent(current) 254 plugin[1].getHandler(profile).setHandlerParent(current)
256 connected_cb = getattr(plugin[1], "profileConnected", None) 255 connected_cb = getattr(plugin[1], "profileConnected", None)
257 if connected_cb: 256 if connected_cb:
258 plugin_conn_cb.append(connected_cb) 257 plugin_conn_cb.append((plugin[0], connected_cb))
259 258
260 current.startService() 259 current.startService()
261 260
262 d = current.getConnectionDeferred() 261 d = current.getConnectionDeferred()
263 d.addCallback(lambda dummy: current.roster.got_roster) # we want to be sure that we got the roster 262 d.addCallback(lambda dummy: current.roster.got_roster) # we want to be sure that we got the roster
264 for callback in plugin_conn_cb: 263
265 d.addCallback(lambda dummy, callback=callback: callback(profile)) 264 def pluginsConnection(dummy):
265 """Call profileConnected callback for all plugins, and print error message if any of them fails"""
266 conn_cb_list = []
267 for dummy, callback in plugin_conn_cb:
268 conn_cb_list.append(defer.maybeDeferred(callback, profile))
269 list_d = defer.DeferredList(conn_cb_list)
270
271 def logPluginResults(results):
272 all_succeed = all([success for success, result in results])
273 if not all_succeed:
274 error(_("Plugins initialisation error"))
275 for idx, (success, result) in enumerate(results):
276 if not success:
277 error("Error (plugin %(name)s): %(failure)s" % {'name': plugin_conn_cb[idx][0],
278 'failure': result})
279
280 list_d.addCallback(logPluginResults)
281 return list_d
282
283
284 d.addCallback(pluginsConnection)
266 return d 285 return d
267 286
268 self.memory.startProfileSession(profile) 287 self.memory.startProfileSession(profile)
269 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) 288 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
270 289