changeset 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 ae09989e9feb
children 4f00fdf11445
files CHANGELOG sat_frontends/jp/cmd_info.py
diffstat 2 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Fri Mar 06 18:19:03 2020 +0100
+++ b/CHANGELOG	Fri Mar 06 18:19:03 2020 +0100
@@ -58,6 +58,7 @@
         - background colour detection
         - new debug/theme command
         - new file/get command (supports aesgcm scheme)
+        - new info/devices command
         - file/upload handle encryption
         - various improvments
         - (blog) added --language to common publish arguments
--- a/sat_frontends/jp/cmd_info.py	Fri Mar 06 18:19:03 2020 +0100
+++ b/sat_frontends/jp/cmd_info.py	Fri Mar 06 18:19:03 2020 +0100
@@ -20,7 +20,7 @@
 from . import base
 from sat.core.i18n import _
 from sat.tools.common.ansi import ANSI as A
-from sat.tools.common import date_utils
+from sat.tools.common import date_utils, data_format
 from sat_frontends.jp.constants import Const as C
 from sat_frontends.jp import common
 
@@ -225,8 +225,32 @@
             self.host.quit()
 
 
+class Devices(base.CommandBase):
+
+    def __init__(self, host):
+        super(Devices, self).__init__(
+            host, 'devices', use_output=C.OUTPUT_LIST_DICT,
+            help=_('devices of an entity'))
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "jid", type=str, nargs='?', default='', help=_("Entity to request"))
+
+    async def start(self):
+        try:
+            data = await self.host.bridge.devicesInfosGet(
+                self.args.jid, self.host.profile)
+        except Exception as e:
+            self.disp(_(f'Error getting devices infos: {e}'), error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            data = data_format.deserialise(data, type_check=list)
+            await self.output(data)
+            self.host.quit()
+
+
 class Info(base.CommandBase):
-    subcommands = (Disco, Version, Session)
+    subcommands = (Disco, Version, Session, Devices)
 
     def __init__(self, host):
         super(Info, self).__init__(