annotate sat_frontends/jp/cmd_info.py @ 4056:1c4f4aa36d98

plugin XEP-0167: Jingle RTP Sessions implementation: rel 420
author Goffi <goffi@goffi.org>
date Mon, 29 May 2023 13:38:10 +0200
parents 524856bd7b19
children 4b842c1fb686
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
3
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SAT command line tool
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3207
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
6
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
11
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
16
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
20 from pprint import pformat
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
21
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
23 from sat.tools.common import data_format, date_utils
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
24 from sat.tools.common.ansi import ANSI as A
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
25 from sat_frontends.jp import common
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
26 from sat_frontends.jp.constants import Const as C
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
27
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
28 from . import base
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
29
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
30 __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
31
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
32
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
33 class Disco(base.CommandBase):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
34 def __init__(self, host):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
35 extra_outputs = {"default": self.default_output}
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
36 super(Disco, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
37 host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
38 "disco",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
39 use_output="complex",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
40 extra_outputs=extra_outputs,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
41 help=_("service discovery"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
42 )
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
43
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def add_parser_options(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
45 self.parser.add_argument("jid", help=_("entity to discover"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
46 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
47 "-t",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
48 "--type",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
49 type=str,
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
50 choices=("infos", "items", "both", "external", "all"),
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
51 default="all",
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
52 help=_("type of data to discover"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
53 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
54 self.parser.add_argument("-n", "--node", default="", help=_("node to use"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
55 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
56 "-C",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
57 "--no-cache",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
58 dest="use_cache",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
59 action="store_false",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
60 help=_("ignore cache"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
61 )
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
62
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
63 def default_output(self, data):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
64 features = data.get("features", [])
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
65 identities = data.get("identities", [])
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
66 extensions = data.get("extensions", {})
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
67 items = data.get("items", [])
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
68 external = data.get("external", [])
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
69
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
70 identities_table = common.Table(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
71 self.host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
72 identities,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
73 headers=(_("category"), _("type"), _("name")),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
74 use_buffer=True,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
75 )
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
76
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
77 extensions_tpl = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
78 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
79 extensions_types.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
80 for type_ in extensions_types:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
81 fields = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
82 for field in extensions[type_]:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
83 field_lines = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
84 data, values = field
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
85 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
86 data_keys.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
87 for key in data_keys:
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("\t", C.A_SUBHEADER, key, A.RESET, ": ", data[key])
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 )
2710
b6e16a89311b jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents: 2681
diff changeset
91 if len(values) == 1:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
92 field_lines.append(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 A.color(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 "\t",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
95 C.A_SUBHEADER,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
96 "value",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 A.RESET,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
98 ": ",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 values[0] or (A.BOLD + "UNSET"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
100 )
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 elif len(values) > 1:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
103 field_lines.append(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 A.color("\t", C.A_SUBHEADER, "values", A.RESET, ": ")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
105 )
2710
b6e16a89311b jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents: 2681
diff changeset
106
b6e16a89311b jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents: 2681
diff changeset
107 for value in values:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 field_lines.append(A.color("\t - ", A.BOLD, value))
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
109 fields.append("\n".join(field_lines))
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
110 extensions_tpl.append(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 "{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
112 )
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
113
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
114 items_table = common.Table(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
115 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
116 )
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
117
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
118 template = []
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
119 fmt_kwargs = {}
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
120 if features:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
121 template.append(A.color(C.A_HEADER, _("Features")) + "\n\n{features}")
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
122 if identities:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 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
124 if extensions:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
125 template.append(A.color(C.A_HEADER, _("Extensions")) + "\n\n{extensions}")
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
126 if items:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
127 template.append(A.color(C.A_HEADER, _("Items")) + "\n\n{items}")
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
128 if external:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
129 fmt_lines = []
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
130 for e in external:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
131 data = {k: e[k] for k in sorted(e)}
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
132 host = data.pop("host")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
133 type_ = data.pop("type")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
134 fmt_lines.append(A.color(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
135 "\t",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
136 C.A_SUBHEADER,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
137 host,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
138 " ",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
139 A.RESET,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
140 "[",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
141 C.A_LEVEL_COLORS[1],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
142 type_,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
143 A.RESET,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
144 "]",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
145 ))
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
146 extended = data.pop("extended", None)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
147 for key, value in data.items():
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
148 fmt_lines.append(A.color(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
149 "\t\t",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
150 C.A_LEVEL_COLORS[2],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
151 f"{key}: ",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
152 C.A_LEVEL_COLORS[3],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
153 str(value)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
154 ))
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
155 if extended:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
156 fmt_lines.append(A.color(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
157 "\t\t",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
158 C.A_HEADER,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
159 "extended",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
160 ))
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
161 nb_extended = len(extended)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
162 for idx, form_data in enumerate(extended):
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
163 namespace = form_data.get("namespace")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
164 if namespace:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
165 fmt_lines.append(A.color(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
166 "\t\t",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
167 C.A_LEVEL_COLORS[2],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
168 "namespace: ",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
169 C.A_LEVEL_COLORS[3],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
170 A.BOLD,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
171 namespace
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
172 ))
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
173 for field_data in form_data["fields"]:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
174 name = field_data.get("name")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
175 if not name:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
176 continue
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
177 field_type = field_data.get("type")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
178 if "multi" in field_type:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
179 value = ", ".join(field_data.get("values") or [])
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
180 else:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
181 value = field_data.get("value")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
182 if value is None:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
183 continue
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
184 if field_type == "boolean":
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
185 value = C.bool(value)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
186 fmt_lines.append(A.color(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
187 "\t\t",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
188 C.A_LEVEL_COLORS[2],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
189 f"{name}: ",
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
190 C.A_LEVEL_COLORS[3],
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
191 A.BOLD,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
192 str(value)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
193 ))
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
194 if nb_extended>1 and idx < nb_extended-1:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
195 fmt_lines.append("\n")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
196
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
197 fmt_lines.append("\n")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
198
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
199 template.append(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
200 A.color(C.A_HEADER, _("External")) + "\n\n{external_formatted}"
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
201 )
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
202 fmt_kwargs["external_formatted"] = "\n".join(fmt_lines)
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
203
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 print(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
205 "\n\n".join(template).format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
206 features="\n".join(features),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
207 identities=identities_table.display().string,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
208 extensions="\n".join(extensions_tpl),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
209 items=items_table.display().string,
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
210 **fmt_kwargs,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
211 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
212 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
213
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
214 async def start(self):
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
215 infos_requested = self.args.type in ("infos", "both", "all")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
216 items_requested = self.args.type in ("items", "both", "all")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
217 exter_requested = self.args.type in ("external", "all")
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
218 if self.args.node:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
219 if self.args.type == "external":
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
220 self.parser.error(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
221 '--node can\'t be used with discovery of external services '
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
222 '(--type="external")'
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
223 )
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
224 else:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
225 exter_requested = False
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
226 jids = await self.host.check_jids([self.args.jid])
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
227 jid = jids[0]
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
228 data = {}
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
229
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
230 # infos
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
231 if infos_requested:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
232 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4035
diff changeset
233 infos = await self.host.bridge.disco_infos(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
234 jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
235 node=self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
236 use_cache=self.args.use_cache,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
237 profile_key=self.host.profile,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
238 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
239 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
240 self.disp(_("error while doing discovery: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
241 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
242
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
243 else:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
244 features, identities, extensions = infos
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
245 features.sort()
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
246 identities.sort(key=lambda identity: identity[2])
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
247 data.update(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
248 {"features": features, "identities": identities, "extensions": extensions}
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
249 )
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
250
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
251 # items
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
252 if items_requested:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
253 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4035
diff changeset
254 items = await self.host.bridge.disco_items(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
255 jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
256 node=self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
257 use_cache=self.args.use_cache,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
258 profile_key=self.host.profile,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
259 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
260 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
261 self.disp(_("error while doing discovery: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
262 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
263 else:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
264 items.sort(key=lambda item: item[2])
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
265 data["items"] = items
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
266
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
267 # external
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
268 if exter_requested:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
269 try:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
270 ext_services_s = await self.host.bridge.external_disco_get(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
271 jid,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
272 self.host.profile,
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
273 )
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
274 except Exception as e:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
275 self.disp(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
276 _("error while doing external service discovery: {e}").format(e=e),
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
277 error=True
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
278 )
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
279 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
280 else:
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
281 data["external"] = data_format.deserialise(
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
282 ext_services_s, type_check=list
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
283 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
284
4035
9c76678a39e2 cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
285 # output
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
286 await self.output(data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
287 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
288
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
289
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
290 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
291 def __init__(self, host):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
292 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
293
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
294 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
295 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
296
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
297 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
298 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
299 jid = jids[0]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
300 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4035
diff changeset
301 data = await self.host.bridge.software_version_get(jid, self.host.profile)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
302 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
303 self.disp(_("error while trying to get version: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
304 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
305 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
306 infos = []
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
307 name, version, os = data
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
308 if name:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
309 infos.append(_("Software name: {name}").format(name=name))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
310 if version:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
311 infos.append(_("Software version: {version}").format(version=version))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
312 if os:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
313 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
314
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
315 print("\n".join(infos))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
316 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
317
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
318
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
319 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
320 def __init__(self, host):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
321 extra_outputs = {"default": self.default_output}
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
322 super(Session, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
323 host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
324 "session",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
325 use_output="dict",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
326 extra_outputs=extra_outputs,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
327 help=_("running session"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
328 )
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
329
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
330 def add_parser_options(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
331 pass
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
332
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
333 async def default_output(self, data):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
334 started = data["started"]
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
335 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
336 short=date_utils.date_fmt(started),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
337 relative=date_utils.date_fmt(started, "relative"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
338 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
339 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
340
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
341 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
342 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4035
diff changeset
343 data = await self.host.bridge.session_infos_get(self.host.profile)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
344 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
345 self.disp(_("Error getting session infos: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
346 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
347 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
348 await self.output(data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
349 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
350
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
351
3207
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
352 class Devices(base.CommandBase):
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
353 def __init__(self, host):
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
354 super(Devices, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
355 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
356 )
3207
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
357
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
358 def add_parser_options(self):
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
359 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
360 "jid", type=str, nargs="?", default="", help=_("Entity to request")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
361 )
3207
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
362
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
363 async def start(self):
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
364 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4035
diff changeset
365 data = await self.host.bridge.devices_infos_get(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
366 self.args.jid, self.host.profile
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
367 )
3207
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
368 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
369 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
370 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
371 else:
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
372 data = data_format.deserialise(data, type_check=list)
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
373 await self.output(data)
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
374 self.host.quit()
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
375
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
376
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
377 class Info(base.CommandBase):
3207
a10e12dfbda8 jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
378 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
379
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
380 def __init__(self, host):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
381 super(Info, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
382 host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
383 "info",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
384 use_profile=False,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
385 help=_("Get various pieces of information on entities"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
386 )