Mercurial > libervia-backend
changeset 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 | 8ca5c990ed92 |
children | 4a8903021fda |
files | src/core/sat_main.py |
diffstat | 1 files changed, 23 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/sat_main.py Wed Apr 02 12:31:15 2014 +0200 +++ b/src/core/sat_main.py Wed Apr 02 12:31:23 2014 +0200 @@ -204,7 +204,6 @@ """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 @@ 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)