changeset 2114:dc5d214f0a3b

jp (info/session): added a command to get data on current session
author Goffi <goffi@goffi.org>
date Thu, 05 Jan 2017 22:22:26 +0100 (2017-01-05)
parents 9c861d07b5b6
children 3435e8d2e8e4
files frontends/src/jp/base.py frontends/src/jp/cmd_info.py
diffstat 2 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/base.py	Thu Jan 05 22:22:13 2017 +0100
+++ b/frontends/src/jp/base.py	Thu Jan 05 22:22:26 2017 +0100
@@ -512,7 +512,7 @@
         @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)
--- a/frontends/src/jp/cmd_info.py	Thu Jan 05 22:22:13 2017 +0100
+++ b/frontends/src/jp/cmd_info.py	Thu Jan 05 22:22:26 2017 +0100
@@ -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 @@
 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 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 @@
         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'))