comparison src/core/sat_main.py @ 1482:80cd55dd5b04

core, bridge: added getFeatures method: this async method indicate which plugins are activated, and add an additional data dictionary with plugin specific data. The result can be general (if profile==C.PROF_KEY_NONE) or specific to profile.
author Goffi <goffi@goffi.org>
date Fri, 21 Aug 2015 17:08:26 +0200
parents 8bfbf5cb0e28
children 704ca56f5ca9
comparison
equal deleted inserted replaced
1481:621b045cd284 1482:80cd55dd5b04
85 except exceptions.BridgeInitError: 85 except exceptions.BridgeInitError:
86 log.error(u"Bridge can't be initialised, can't start SàT core") 86 log.error(u"Bridge can't be initialised, can't start SàT core")
87 sys.exit(1) 87 sys.exit(1)
88 self.bridge.register("getReady", lambda: self._initialised) 88 self.bridge.register("getReady", lambda: self._initialised)
89 self.bridge.register("getVersion", lambda: self.full_version) 89 self.bridge.register("getVersion", lambda: self.full_version)
90 self.bridge.register("getFeatures", self.getFeatures)
90 self.bridge.register("getProfileName", self.memory.getProfileName) 91 self.bridge.register("getProfileName", self.memory.getProfileName)
91 self.bridge.register("getProfilesList", self.memory.getProfilesList) 92 self.bridge.register("getProfilesList", self.memory.getProfilesList)
92 self.bridge.register("getEntityData", lambda jid_, keys, profile: self.memory.getEntityData(jid.JID(jid_), keys, profile)) 93 self.bridge.register("getEntityData", lambda jid_, keys, profile: self.memory.getEntityData(jid.JID(jid_), keys, profile))
93 self.bridge.register("getEntitiesData", self.memory._getEntitiesData) 94 self.bridge.register("getEntitiesData", self.memory._getEntitiesData)
94 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) 95 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
338 for plugin in self.plugins.iteritems(): 339 for plugin in self.plugins.iteritems():
339 disconnected_cb = getattr(plugin[1], "profileDisconnected", None) 340 disconnected_cb = getattr(plugin[1], "profileDisconnected", None)
340 if disconnected_cb: 341 if disconnected_cb:
341 disconnected_cb(profile) 342 disconnected_cb(profile)
342 343
344 def getFeatures(self, profile_key=C.PROF_KEY_NONE):
345 """Get available features
346
347 Return list of activated plugins and plugin specific data
348 @param profile_key: %(doc_profile_key)s
349 C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile dependent)
350 @return (dict)[Deferred]: features data where:
351 - key is plugin import name, present only for activated plugins
352 - value is a an other dict, when meaning is specifif to each plugin.
353 this dict is return by plugin's getFeature method.
354 If this method doesn't exists, an empty dict is returned.
355 """
356 try:
357 # FIXME: there is no method yet to check profile session
358 # as soon as one is implemented, it should be used here
359 self.getClient(profile_key)
360 except KeyError:
361 log.warning("Requesting features for a profile outside a session")
362 profile_key = C.PROF_KEY_NONE
363 except exceptions.ProfileNotSetError:
364 pass
365
366 features = []
367 for import_name, plugin in self.plugins.iteritems():
368 try:
369 features_d = defer.maybeDeferred(plugin.getFeatures, profile_key)
370 except AttributeError:
371 features_d = defer.succeed({})
372 features.append(features_d)
373
374 d_list = defer.DeferredList(features)
375 def buildFeatures(result, import_names):
376 assert len(result) == len(import_names)
377 ret = {}
378 for name, (success, data) in zip (import_names, result):
379 if success:
380 ret[name] = data
381 else:
382 log.warning(u"Error while getting features for {name}: {failure}".format(
383 name=name, failure=data))
384 ret[name] = {}
385 return ret
386
387 d_list.addCallback(buildFeatures, self.plugins.keys())
388 return d_list
389
343 def getContacts(self, profile_key): 390 def getContacts(self, profile_key):
344 client = self.getClient(profile_key) 391 client = self.getClient(profile_key)
345 def got_roster(dummy): 392 def got_roster(dummy):
346 ret = [] 393 ret = []
347 for item in client.roster.getItems(): # we get all items for client's roster 394 for item in client.roster.getItems(): # we get all items for client's roster