jp (info/session): added a command to get data on current session

This commit is contained in:
Goffi 2017-01-05 22:22:26 +01:00
commit 1e09016747
2 changed files with 27 additions and 5 deletions

View file

@ -512,7 +512,7 @@ class CommandBase(object):
@param host: Jp instance
@param name(unicode): name of the new command
@param use_profile(bool): if True, add profile selection/connection commands
@param use_output(bool, dict): if not False, add --output option
@param use_output(bool, unicode): if not False, add --output option
@param need_connect(bool, None): True if profile connection is needed
False else (profile session must still be started)
None to set auto value (i.e. True if use_profile is set)

View file

@ -19,6 +19,7 @@
import base
from sat.core.i18n import _
from sat_frontends.jp.constants import Const as C
__commands__ = ["Info"]
@ -26,11 +27,11 @@ __commands__ = ["Info"]
class Disco(base.CommandBase):
def __init__(self, host):
super(Disco, self).__init__(host, 'disco', help=_('Service discovery'))
super(Disco, self).__init__(host, 'disco', help=_('service discovery'))
self.need_loop=True
def add_parser_options(self):
self.parser.add_argument("jid", type=str, help=_("Entity to discover"))
self.parser.add_argument("jid", type=str, help=_("entity to discover"))
def start(self):
jids = self.host.check_jids([self.args.jid])
@ -104,7 +105,7 @@ class Disco(base.CommandBase):
class Version(base.CommandBase):
def __init__(self, host):
super(Version, self).__init__(host, 'version', help=_('Client version'))
super(Version, self).__init__(host, 'version', help=_('running session'))
self.need_loop=True
def add_parser_options(self):
@ -133,8 +134,29 @@ class Version(base.CommandBase):
self.host.quit()
class Session(base.CommandBase):
def __init__(self, host):
super(Session, self).__init__(host, 'session', use_output='dict', help=_('client version'))
self.need_loop=True
def add_parser_options(self):
pass
def start(self):
self.host.bridge.sessionInfosGet(self.host.profile, callback=self._sessionInfoGetCb, errback=self._sessionInfoGetEb)
def _sessionInfoGetCb(self, data):
self.output(data)
self.host.quit()
def _sessionInfoGetEb(self, error_data):
self.disp(_(u'Error getting session infos: {}').format(error_data), error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
class Info(base.CommandBase):
subcommands = (Disco, Version)
subcommands = (Disco, Version, Session)
def __init__(self, host):
super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities'))