comparison src/plugins/plugin_xep_0092.py @ 971:8ca5c990ed92

jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
author Goffi <goffi@goffi.org>
date Wed, 02 Apr 2014 12:31:15 +0200
parents 91836a647515
children 301b342c697a
comparison
equal deleted inserted replaced
970:2e052998c7eb 971:8ca5c990ed92
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from twisted.internet import reactor, defer 22 from twisted.internet import reactor, defer
23 from twisted.words.protocols.jabber import jid
23 from wokkel import compat 24 from wokkel import compat
24 from sat.core import exceptions 25 from sat.core import exceptions
25 from logging import debug, info, warning, error 26 from logging import debug, info, warning, error
26 27
27 NS_VERSION = "jabber:iq:version" 28 NS_VERSION = "jabber:iq:version"
43 class XEP_0092(object): 44 class XEP_0092(object):
44 45
45 def __init__(self, host): 46 def __init__(self, host):
46 info(_("Plugin XEP_0092 initialization")) 47 info(_("Plugin XEP_0092 initialization"))
47 self.host = host 48 self.host = host
49 host.bridge.addMethod("getSoftwareVersion", ".plugin", in_sign='ss', out_sign='(sss)', method=self._getVersion, async=True)
48 try: 50 try:
49 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50) 51 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50)
50 except KeyError: 52 except KeyError:
51 info(_("Text commands not available")) 53 info(_("Text commands not available"))
52 54
55 def _getVersion(self, entity_jid_s, profile_key):
56 def prepareForBridge(data):
57 name, version, os = data
58 return (name or '', version or '', os or '')
59 d = self.getVersion(jid.JID(entity_jid_s), profile_key)
60 d.addCallback(prepareForBridge)
61 return d
62
53 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): 63 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE):
54 """ Ask version of the client that jid_ is running 64 """ Ask version of the client that jid_ is running
55 @param jid_: jid from who we want to know client's version 65 @param jid_: jid from who we want to know client's version
56 @param profile_key: %(doc_profile_key)s 66 @param profile_key: %(doc_profile_key)s
57 @return: a defered which fire tuple with the following data (None if not available): 67 @return (tuple): a defered which fire a tuple with the following data (None if not available):
58 - name: Natural language name of the software 68 - name: Natural language name of the software
59 - version: specific version of the software 69 - version: specific version of the software
60 - os: operating system of the queried entity 70 - os: operating system of the queried entity
61 """ 71 """
62 client = self.host.getClient(profile_key) 72 client = self.host.getClient(profile_key)