comparison sat_frontends/jp/cmd_info.py @ 3207:a10e12dfbda8

jp(info): `devices` command first draft: this command gather data on known devices of an entity.
author Goffi <goffi@goffi.org>
date Fri, 06 Mar 2020 18:19:03 +0100
parents 559a625a236b
children be6d91572633
comparison
equal deleted inserted replaced
3206:ae09989e9feb 3207:a10e12dfbda8
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 from . import base 20 from . import base
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from sat.tools.common.ansi import ANSI as A 22 from sat.tools.common.ansi import ANSI as A
23 from sat.tools.common import date_utils 23 from sat.tools.common import date_utils, data_format
24 from sat_frontends.jp.constants import Const as C 24 from sat_frontends.jp.constants import Const as C
25 from sat_frontends.jp import common 25 from sat_frontends.jp import common
26 26
27 __commands__ = ["Info"] 27 __commands__ = ["Info"]
28 28
223 else: 223 else:
224 await self.output(data) 224 await self.output(data)
225 self.host.quit() 225 self.host.quit()
226 226
227 227
228 class Devices(base.CommandBase):
229
230 def __init__(self, host):
231 super(Devices, self).__init__(
232 host, 'devices', use_output=C.OUTPUT_LIST_DICT,
233 help=_('devices of an entity'))
234
235 def add_parser_options(self):
236 self.parser.add_argument(
237 "jid", type=str, nargs='?', default='', help=_("Entity to request"))
238
239 async def start(self):
240 try:
241 data = await self.host.bridge.devicesInfosGet(
242 self.args.jid, self.host.profile)
243 except Exception as e:
244 self.disp(_(f'Error getting devices infos: {e}'), error=True)
245 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
246 else:
247 data = data_format.deserialise(data, type_check=list)
248 await self.output(data)
249 self.host.quit()
250
251
228 class Info(base.CommandBase): 252 class Info(base.CommandBase):
229 subcommands = (Disco, Version, Session) 253 subcommands = (Disco, Version, Session, Devices)
230 254
231 def __init__(self, host): 255 def __init__(self, host):
232 super(Info, self).__init__( 256 super(Info, self).__init__(
233 host, 'info', use_profile=False, 257 host, 'info', use_profile=False,
234 help=_('Get various pieces of information on entities')) 258 help=_('Get various pieces of information on entities'))