jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
This commit is contained in:
parent
647487fc1d
commit
ec08d50aba
4 changed files with 61 additions and 7 deletions
|
|
@ -223,8 +223,8 @@ class Jp(object):
|
|||
"""
|
||||
# FIXME: need better exit codes
|
||||
|
||||
def cant_connect():
|
||||
error(_(u"Can't connect profile"))
|
||||
def cant_connect(failure):
|
||||
error(_(u"Can't connect profile [%s]") % failure)
|
||||
self.quit(1)
|
||||
|
||||
self.profile = self.bridge.getProfileName(self.args.profile)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ from logging import debug, info, error, warning
|
|||
import base
|
||||
from sat.core.i18n import _
|
||||
|
||||
__commands__ = ["Disco"]
|
||||
__commands__ = ["Info"]
|
||||
|
||||
|
||||
class Disco(base.CommandBase):
|
||||
|
||||
|
|
@ -37,10 +38,14 @@ class Disco(base.CommandBase):
|
|||
self.need_loop=True
|
||||
jids = self.host.check_jids([self.args.jid])
|
||||
jid = jids[0]
|
||||
self.host.bridge.discoInfos(jid, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=lambda ignore: ignore)
|
||||
self.host.bridge.discoInfos(jid, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=self.error)
|
||||
|
||||
def error(self, failure):
|
||||
print (_("Error while doing discovery"))
|
||||
self.host.quit(1)
|
||||
|
||||
def gotInfos(self, infos, jid):
|
||||
self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=lambda ignore: ignore)
|
||||
self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=self.error)
|
||||
|
||||
def gotItems(self, infos, items):
|
||||
features, identities = infos
|
||||
|
|
@ -76,3 +81,43 @@ class Disco(base.CommandBase):
|
|||
'items': '\n'.join(items_lst),
|
||||
}
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class Version(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super(Version, self).__init__(host, 'version', help=_('Client version'))
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument("jid", type=str, help=_("Entity to request"))
|
||||
|
||||
def connected(self):
|
||||
self.need_loop=True
|
||||
super(Version, self).connected()
|
||||
jids = self.host.check_jids([self.args.jid])
|
||||
jid = jids[0]
|
||||
self.host.bridge.getSoftwareVersion(jid, self.host.profile, callback=self.gotVersion, errback=self.error)
|
||||
|
||||
def error(self, failure):
|
||||
print (_("Error while trying to get version [%s]") % failure)
|
||||
self.host.quit(1)
|
||||
|
||||
def gotVersion(self, data):
|
||||
infos = []
|
||||
name, version, os = data
|
||||
if name:
|
||||
infos.append(_("Client name: %s") % name)
|
||||
if version:
|
||||
infos.append(_("Client version: %s") % version)
|
||||
if os:
|
||||
infos.append(_("Operating System: %s") % os)
|
||||
|
||||
print "\n".join(infos)
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class Info(base.CommandBase):
|
||||
subcommands = (Disco, Version)
|
||||
|
||||
def __init__(self, host):
|
||||
super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various informations on entities'))
|
||||
|
|
@ -72,7 +72,6 @@ class Const(object):
|
|||
# names of widely used plugins
|
||||
TEXT_CMDS = 'TEXT-COMMANDS'
|
||||
|
||||
|
||||
## Misc ##
|
||||
SAVEFILE_DATABASE = "sat.db"
|
||||
IQ_SET = '/iq[@type="set"]'
|
||||
|
|
|
|||
|
|
@ -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 @@ class XEP_0092(object):
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue