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
This commit is contained in:
Goffi 2014-04-02 12:31:23 +02:00
commit 44d8f99b7d

View file

@ -204,7 +204,6 @@ class SAT(service.Service):
"""Connect to jabber server with asynchronous reply
@param profile_key: %(doc_profile)s
"""
profile = self.memory.getProfileName(profile_key)
if not profile:
error(_('Trying to connect a non-exsitant profile'))
@ -255,14 +254,34 @@ class SAT(service.Service):
plugin[1].getHandler(profile).setHandlerParent(current)
connected_cb = getattr(plugin[1], "profileConnected", None)
if connected_cb:
plugin_conn_cb.append(connected_cb)
plugin_conn_cb.append((plugin[0], connected_cb))
current.startService()
d = current.getConnectionDeferred()
d.addCallback(lambda dummy: current.roster.got_roster) # we want to be sure that we got the roster
for callback in plugin_conn_cb:
d.addCallback(lambda dummy, callback=callback: callback(profile))
def pluginsConnection(dummy):
"""Call profileConnected callback for all plugins, and print error message if any of them fails"""
conn_cb_list = []
for dummy, callback in plugin_conn_cb:
conn_cb_list.append(defer.maybeDeferred(callback, profile))
list_d = defer.DeferredList(conn_cb_list)
def logPluginResults(results):
all_succeed = all([success for success, result in results])
if not all_succeed:
error(_("Plugins initialisation error"))
for idx, (success, result) in enumerate(results):
if not success:
error("Error (plugin %(name)s): %(failure)s" % {'name': plugin_conn_cb[idx][0],
'failure': result})
list_d.addCallback(logPluginResults)
return list_d
d.addCallback(pluginsConnection)
return d
self.memory.startProfileSession(profile)