# HG changeset patch # User Goffi # Date 1510732472 -3600 # Node ID a9fac72825a253d4577dd0815d60b53bb179fd30 # Parent 3faf18111d61b2f98856cf4cb1afed5f5a848945 memory (disco): added findServiceEntity helper method to get first service of a kind diff -r 3faf18111d61 -r a9fac72825a2 src/core/sat_main.py --- a/src/core/sat_main.py Sat Nov 11 18:39:26 2017 +0100 +++ b/src/core/sat_main.py Wed Nov 15 08:54:32 2017 +0100 @@ -604,6 +604,9 @@ def getDiscoItems(self, *args, **kwargs): return self.memory.disco.getItems(*args, **kwargs) + def findServiceEntity(self, *args, **kwargs): + return self.memory.disco.findServiceEntity(*args, **kwargs) + def findServiceEntities(self, *args, **kwargs): return self.memory.disco.findServiceEntities(*args, **kwargs) diff -r 3faf18111d61 -r a9fac72825a2 src/memory/disco.py --- a/src/memory/disco.py Sat Nov 11 18:39:26 2017 +0100 +++ b/src/memory/disco.py Wed Nov 15 08:54:32 2017 +0100 @@ -230,6 +230,16 @@ log.warning(_(u"Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(), 'error': failure_.getErrorMessage()}) + def findServiceEntity(self, client, category, type_, jid_=None): + """Helper method to find first available entity from findServiceEntities + + args are the same as for [findServiceEntities] + @return (jid.JID, None): found entity + """ + d = self.host.findServiceEntities(client, "pubsub", "service") + d.addCallback(lambda entities: entities.pop() if entities else None) + return d + def findServiceEntities(self, client, category, type_, jid_=None): """Return all available items of an entity which correspond to (category, type_)