diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0092.py	Wed Apr 02 12:11:07 2014 +0200
+++ b/src/plugins/plugin_xep_0092.py	Wed Apr 02 12:31:15 2014 +0200
@@ -20,6 +20,7 @@
 from sat.core.i18n import _
 from sat.core.constants import Const as C
 from twisted.internet import reactor, defer
+from twisted.words.protocols.jabber import jid
 from wokkel import compat
 from sat.core import exceptions
 from logging import debug, info, warning, error
@@ -45,16 +46,25 @@
     def __init__(self, host):
         info(_("Plugin XEP_0092 initialization"))
         self.host = host
+        host.bridge.addMethod("getSoftwareVersion", ".plugin", in_sign='ss', out_sign='(sss)', method=self._getVersion, async=True)
         try:
             self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50)
         except KeyError:
             info(_("Text commands not available"))
 
+    def _getVersion(self, entity_jid_s, profile_key):
+        def prepareForBridge(data):
+            name, version, os = data
+            return (name or '', version or '', os or '')
+        d = self.getVersion(jid.JID(entity_jid_s), profile_key)
+        d.addCallback(prepareForBridge)
+        return d
+
     def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE):
         """ Ask version of the client that jid_ is running
         @param jid_: jid from who we want to know client's version
         @param profile_key: %(doc_profile_key)s
-        @return: a defered which fire tuple with the following data (None if not available):
+        @return (tuple): a defered which fire a tuple with the following data (None if not available):
                  - name: Natural language name of the software
                  - version: specific version of the software
                  - os: operating system of the queried entity