# HG changeset patch # User Goffi # Date 1396434683 -7200 # Node ID 07b817f5a197b2dfbc8e04378b3a96d7d9b03c78 # Parent 8ca5c990ed92ba29b143ba6142e6df71ad60f228 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 diff -r 8ca5c990ed92 -r 07b817f5a197 src/core/sat_main.py --- 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)