Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_info.py @ 3622:d4cb99e7e838
misc: add a `dev-requirements.txt` file
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Aug 2021 21:52:17 +0200 |
parents | 04283582966f |
children | 9c76678a39e2 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
966 | 3 |
4 # jp: a SAT command line tool | |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
966 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
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/>. | |
19 | |
3028 | 20 from . import base |
966 | 21 from sat.core.i18n import _ |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
22 from sat.tools.common.ansi import ANSI as A |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
23 from sat.tools.common import date_utils, data_format |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
24 from sat_frontends.jp.constants import Const as C |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
25 from sat_frontends.jp import common |
966 | 26 |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
27 __commands__ = ["Info"] |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
28 |
966 | 29 |
30 class Disco(base.CommandBase): | |
31 def __init__(self, host): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
32 extra_outputs = {"default": self.default_output} |
3040 | 33 super(Disco, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
34 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
35 "disco", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
36 use_output="complex", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
37 extra_outputs=extra_outputs, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
38 help=_("service discovery"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
39 ) |
966 | 40 |
41 def add_parser_options(self): | |
3028 | 42 self.parser.add_argument("jid", help=_("entity to discover")) |
3040 | 43 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
44 "-t", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
45 "--type", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
46 type=str, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
47 choices=("infos", "items", "both"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
48 default="both", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
49 help=_("type of data to discover"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
50 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
51 self.parser.add_argument("-n", "--node", default="", help=_("node to use")) |
3040 | 52 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
53 "-C", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
54 "--no-cache", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
55 dest="use_cache", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
56 action="store_false", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
57 help=_("ignore cache"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
58 ) |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
59 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
60 def default_output(self, data): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
61 features = data.get("features", []) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
62 identities = data.get("identities", []) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
63 extensions = data.get("extensions", {}) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
64 items = data.get("items", []) |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
65 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
66 identities_table = common.Table( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
67 self.host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
68 identities, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
69 headers=(_("category"), _("type"), _("name")), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
70 use_buffer=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
71 ) |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
72 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
73 extensions_tpl = [] |
3028 | 74 extensions_types = list(extensions.keys()) |
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
75 extensions_types.sort() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
76 for type_ in extensions_types: |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
77 fields = [] |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
78 for field in extensions[type_]: |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
79 field_lines = [] |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
80 data, values = field |
3028 | 81 data_keys = list(data.keys()) |
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
82 data_keys.sort() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
83 for key in data_keys: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
84 field_lines.append( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
85 A.color("\t", C.A_SUBHEADER, key, A.RESET, ": ", data[key]) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
86 ) |
2710
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
87 if len(values) == 1: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
88 field_lines.append( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
89 A.color( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
90 "\t", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
91 C.A_SUBHEADER, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
92 "value", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
93 A.RESET, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
94 ": ", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
95 values[0] or (A.BOLD + "UNSET"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
96 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
97 ) |
2710
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
98 elif len(values) > 1: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
99 field_lines.append( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
100 A.color("\t", C.A_SUBHEADER, "values", A.RESET, ": ") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
101 ) |
2710
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
102 |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
103 for value in values: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
104 field_lines.append(A.color("\t - ", A.BOLD, value)) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
105 fields.append("\n".join(field_lines)) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
106 extensions_tpl.append( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
107 "{type_}\n{fields}".format(type_=type_, fields="\n\n".join(fields)) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
108 ) |
966 | 109 |
3040 | 110 items_table = common.Table( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
111 self.host, items, headers=(_("entity"), _("node"), _("name")), use_buffer=True |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
112 ) |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
113 |
966 | 114 template = [] |
115 if features: | |
3028 | 116 template.append(A.color(C.A_HEADER, _("Features")) + "\n\n{features}") |
966 | 117 if identities: |
3028 | 118 template.append(A.color(C.A_HEADER, _("Identities")) + "\n\n{identities}") |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
119 if extensions: |
3028 | 120 template.append(A.color(C.A_HEADER, _("Extensions")) + "\n\n{extensions}") |
966 | 121 if items: |
3028 | 122 template.append(A.color(C.A_HEADER, _("Items")) + "\n\n{items}") |
966 | 123 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
124 print( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
125 "\n\n".join(template).format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
126 features="\n".join(features), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 identities=identities_table.display().string, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 extensions="\n".join(extensions_tpl), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
129 items=items_table.display().string, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
130 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
131 ) |
3040 | 132 |
133 async def start(self): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
134 infos_requested = self.args.type in ("infos", "both") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
135 items_requested = self.args.type in ("items", "both") |
3040 | 136 jids = await self.host.check_jids([self.args.jid]) |
137 jid = jids[0] | |
138 | |
139 # infos | |
140 if not infos_requested: | |
141 infos = None | |
142 else: | |
143 try: | |
144 infos = await self.host.bridge.discoInfos( | |
145 jid, | |
146 node=self.args.node, | |
147 use_cache=self.args.use_cache, | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
148 profile_key=self.host.profile, |
3040 | 149 ) |
150 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
151 self.disp(_("error while doing discovery: {e}").format(e=e), error=True) |
3040 | 152 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
153 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
154 # items |
3040 | 155 if not items_requested: |
156 items = None | |
157 else: | |
158 try: | |
159 items = await self.host.bridge.discoItems( | |
160 jid, | |
161 node=self.args.node, | |
162 use_cache=self.args.use_cache, | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 profile_key=self.host.profile, |
3040 | 164 ) |
165 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
166 self.disp(_("error while doing discovery: {e}").format(e=e), error=True) |
3040 | 167 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
168 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
169 # output |
3040 | 170 data = {} |
171 | |
172 if infos_requested: | |
173 features, identities, extensions = infos | |
174 features.sort() | |
175 identities.sort(key=lambda identity: identity[2]) | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
176 data.update( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
177 {"features": features, "identities": identities, "extensions": extensions} |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
178 ) |
3040 | 179 |
180 if items_requested: | |
181 items.sort(key=lambda item: item[2]) | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
182 data["items"] = items |
3040 | 183 |
184 await self.output(data) | |
185 self.host.quit() | |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
186 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
187 |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
188 class Version(base.CommandBase): |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
189 def __init__(self, host): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
190 super(Version, self).__init__(host, "version", help=_("software version")) |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
191 |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
192 def add_parser_options(self): |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
193 self.parser.add_argument("jid", type=str, help=_("Entity to request")) |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
194 |
3040 | 195 async def start(self): |
196 jids = await self.host.check_jids([self.args.jid]) | |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
197 jid = jids[0] |
3040 | 198 try: |
199 data = await self.host.bridge.getSoftwareVersion(jid, self.host.profile) | |
200 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
201 self.disp(_("error while trying to get version: {e}").format(e=e), error=True) |
3040 | 202 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
203 else: | |
204 infos = [] | |
205 name, version, os = data | |
206 if name: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
207 infos.append(_("Software name: {name}").format(name=name)) |
3040 | 208 if version: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
209 infos.append(_("Software version: {version}").format(version=version)) |
3040 | 210 if os: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
211 infos.append(_("Operating System: {os}").format(os=os)) |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
212 |
3040 | 213 print("\n".join(infos)) |
214 self.host.quit() | |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
215 |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
216 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
217 class Session(base.CommandBase): |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
218 def __init__(self, host): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 extra_outputs = {"default": self.default_output} |
3040 | 220 super(Session, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
221 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
222 "session", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
223 use_output="dict", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
224 extra_outputs=extra_outputs, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
225 help=_("running session"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
226 ) |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
227 |
3040 | 228 def add_parser_options(self): |
229 pass | |
230 | |
231 async def default_output(self, data): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
232 started = data["started"] |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
233 data["started"] = "{short} (UTC, {relative})".format( |
2605
87f8cf51fca5
jp (info/session): show short + relative date by default for "started"
Goffi <goffi@goffi.org>
parents:
2600
diff
changeset
|
234 short=date_utils.date_fmt(started), |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
235 relative=date_utils.date_fmt(started, "relative"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
236 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
237 await self.host.output(C.OUTPUT_DICT, "simple", {}, data) |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
238 |
3040 | 239 async def start(self): |
240 try: | |
241 data = await self.host.bridge.sessionInfosGet(self.host.profile) | |
242 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
243 self.disp(_("Error getting session infos: {e}").format(e=e), error=True) |
3040 | 244 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
245 else: | |
246 await self.output(data) | |
247 self.host.quit() | |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
248 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
249 |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
250 class Devices(base.CommandBase): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
251 def __init__(self, host): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
252 super(Devices, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
253 host, "devices", use_output=C.OUTPUT_LIST_DICT, help=_("devices of an entity") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
254 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
255 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
256 def add_parser_options(self): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
257 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
258 "jid", type=str, nargs="?", default="", help=_("Entity to request") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
259 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
260 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
261 async def start(self): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
262 try: |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
263 data = await self.host.bridge.devicesInfosGet( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
264 self.args.jid, self.host.profile |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
265 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
266 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
267 self.disp(_("Error getting devices infos: {e}").format(e=e), error=True) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
268 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
269 else: |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
270 data = data_format.deserialise(data, type_check=list) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
271 await self.output(data) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
272 self.host.quit() |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
273 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
274 |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
275 class Info(base.CommandBase): |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
276 subcommands = (Disco, Version, Session, Devices) |
971
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
277 |
8ca5c990ed92
jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents:
966
diff
changeset
|
278 def __init__(self, host): |
3040 | 279 super(Info, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
280 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
281 "info", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
282 use_profile=False, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
283 help=_("Get various pieces of information on entities"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
284 ) |