comparison frontends/src/jp/cmd_info.py @ 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
parents 3e168cde7a7d
children fff88c33442f
comparison
equal deleted inserted replaced
2113:9c861d07b5b6 2114:dc5d214f0a3b
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
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 import base 20 import base
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from sat_frontends.jp.constants import Const as C
22 23
23 __commands__ = ["Info"] 24 __commands__ = ["Info"]
24 25
25 26
26 class Disco(base.CommandBase): 27 class Disco(base.CommandBase):
27 28
28 def __init__(self, host): 29 def __init__(self, host):
29 super(Disco, self).__init__(host, 'disco', help=_('Service discovery')) 30 super(Disco, self).__init__(host, 'disco', help=_('service discovery'))
30 self.need_loop=True 31 self.need_loop=True
31 32
32 def add_parser_options(self): 33 def add_parser_options(self):
33 self.parser.add_argument("jid", type=str, help=_("Entity to discover")) 34 self.parser.add_argument("jid", type=str, help=_("entity to discover"))
34 35
35 def start(self): 36 def start(self):
36 jids = self.host.check_jids([self.args.jid]) 37 jids = self.host.check_jids([self.args.jid])
37 jid = jids[0] 38 jid = jids[0]
38 self.host.bridge.discoInfos(jid, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=self.error) 39 self.host.bridge.discoInfos(jid, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=self.error)
102 103
103 104
104 class Version(base.CommandBase): 105 class Version(base.CommandBase):
105 106
106 def __init__(self, host): 107 def __init__(self, host):
107 super(Version, self).__init__(host, 'version', help=_('Client version')) 108 super(Version, self).__init__(host, 'version', help=_('running session'))
108 self.need_loop=True 109 self.need_loop=True
109 110
110 def add_parser_options(self): 111 def add_parser_options(self):
111 self.parser.add_argument("jid", type=str, help=_("Entity to request")) 112 self.parser.add_argument("jid", type=str, help=_("Entity to request"))
112 113
131 132
132 print "\n".join(infos) 133 print "\n".join(infos)
133 self.host.quit() 134 self.host.quit()
134 135
135 136
137 class Session(base.CommandBase):
138
139 def __init__(self, host):
140 super(Session, self).__init__(host, 'session', use_output='dict', help=_('client version'))
141 self.need_loop=True
142
143 def add_parser_options(self):
144 pass
145
146 def start(self):
147 self.host.bridge.sessionInfosGet(self.host.profile, callback=self._sessionInfoGetCb, errback=self._sessionInfoGetEb)
148
149 def _sessionInfoGetCb(self, data):
150 self.output(data)
151 self.host.quit()
152
153 def _sessionInfoGetEb(self, error_data):
154 self.disp(_(u'Error getting session infos: {}').format(error_data), error=True)
155 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
156
157
136 class Info(base.CommandBase): 158 class Info(base.CommandBase):
137 subcommands = (Disco, Version) 159 subcommands = (Disco, Version, Session)
138 160
139 def __init__(self, host): 161 def __init__(self, host):
140 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities')) 162 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities'))