Mercurial > libervia-backend
annotate libervia/cli/cmd_info.py @ 4272:89a0999884ac
cli (list/set): add "--comments" argument.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 20 Jun 2024 14:46:55 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
966 | 3 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
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 | |
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 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
22 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.tools.common import data_format, date_utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.tools.common.ansi import ANSI as A |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
25 from libervia.cli import common |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
26 from libervia.cli.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 | 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 | 32 |
33 class Disco(base.CommandBase): | |
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 | 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 | 43 |
44 def add_parser_options(self): | |
3028 | 45 self.parser.add_argument("jid", help=_("entity to discover")) |
3040 | 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 | 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 | 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 | 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 | 113 |
3040 | 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 | 118 template = [] |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
119 fmt_kwargs = {} |
966 | 120 if features: |
3028 | 121 template.append(A.color(C.A_HEADER, _("Features")) + "\n\n{features}") |
966 | 122 if identities: |
3028 | 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 | 125 template.append(A.color(C.A_HEADER, _("Extensions")) + "\n\n{extensions}") |
966 | 126 if items: |
3028 | 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") |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
134 fmt_lines.append( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
135 A.color( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
136 "\t", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
137 C.A_SUBHEADER, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
138 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
139 " ", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
140 A.RESET, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
141 "[", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
142 C.A_LEVEL_COLORS[1], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
143 type_, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
144 A.RESET, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
145 "]", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
146 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
147 ) |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
148 extended = data.pop("extended", None) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
149 for key, value in data.items(): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
150 fmt_lines.append( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
151 A.color( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
152 "\t\t", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
153 C.A_LEVEL_COLORS[2], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
154 f"{key}: ", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
155 C.A_LEVEL_COLORS[3], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
156 str(value), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
157 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
158 ) |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
159 if extended: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
160 fmt_lines.append( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
161 A.color( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
162 "\t\t", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
163 C.A_HEADER, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
164 "extended", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
165 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
166 ) |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
167 nb_extended = len(extended) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
168 for idx, form_data in enumerate(extended): |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
169 namespace = form_data.get("namespace") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
170 if namespace: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
171 fmt_lines.append( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
172 A.color( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
173 "\t\t", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
174 C.A_LEVEL_COLORS[2], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
175 "namespace: ", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
176 C.A_LEVEL_COLORS[3], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
177 A.BOLD, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
178 namespace, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
179 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
180 ) |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
181 for field_data in form_data["fields"]: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
182 name = field_data.get("name") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
183 if not name: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
184 continue |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
185 field_type = field_data.get("type") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
186 if "multi" in field_type: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
187 value = ", ".join(field_data.get("values") or []) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
188 else: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
189 value = field_data.get("value") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
190 if value is None: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
191 continue |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
192 if field_type == "boolean": |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
193 value = C.bool(value) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
194 fmt_lines.append( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
195 A.color( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
196 "\t\t", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
197 C.A_LEVEL_COLORS[2], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
198 f"{name}: ", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
199 C.A_LEVEL_COLORS[3], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
200 A.BOLD, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
201 str(value), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
202 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
203 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
204 if nb_extended > 1 and idx < nb_extended - 1: |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
205 fmt_lines.append("\n") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
206 |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
207 fmt_lines.append("\n") |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
208 |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
209 template.append( |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
210 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
|
211 ) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
212 fmt_kwargs["external_formatted"] = "\n".join(fmt_lines) |
966 | 213 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 print( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
215 "\n\n".join(template).format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
216 features="\n".join(features), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
217 identities=identities_table.display().string, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
218 extensions="\n".join(extensions_tpl), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 items=items_table.display().string, |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
220 **fmt_kwargs, |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
221 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
222 ) |
3040 | 223 |
224 async def start(self): | |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 if self.args.node: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
229 if self.args.type == "external": |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
230 self.parser.error( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
231 "--node can't be used with discovery of external services " |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
232 '(--type="external")' |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
233 ) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
234 else: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
235 exter_requested = False |
3040 | 236 jids = await self.host.check_jids([self.args.jid]) |
237 jid = jids[0] | |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
238 data = {} |
3040 | 239 |
240 # infos | |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
241 if infos_requested: |
3040 | 242 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4035
diff
changeset
|
243 infos = await self.host.bridge.disco_infos( |
3040 | 244 jid, |
245 node=self.args.node, | |
246 use_cache=self.args.use_cache, | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
247 profile_key=self.host.profile, |
3040 | 248 ) |
249 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
250 self.disp(_("error while doing discovery: {e}").format(e=e), error=True) |
3040 | 251 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
|
252 |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
253 else: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
254 features, identities, extensions = infos |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
255 features.sort() |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
256 identities.sort(key=lambda identity: identity[2]) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
257 data.update( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
258 { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
259 "features": features, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
260 "identities": identities, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
261 "extensions": extensions, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
262 } |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
263 ) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
264 |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
265 # items |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
266 if items_requested: |
3040 | 267 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4035
diff
changeset
|
268 items = await self.host.bridge.disco_items( |
3040 | 269 jid, |
270 node=self.args.node, | |
271 use_cache=self.args.use_cache, | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
272 profile_key=self.host.profile, |
3040 | 273 ) |
274 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
275 self.disp(_("error while doing discovery: {e}").format(e=e), error=True) |
3040 | 276 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
|
277 else: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
278 items.sort(key=lambda item: item[2]) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
279 data["items"] = items |
3040 | 280 |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
281 # external |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
282 if exter_requested: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
283 try: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
284 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
|
285 jid, |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
286 self.host.profile, |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
287 ) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
288 except Exception as e: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
289 self.disp( |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
290 _("error while doing external service discovery: {e}").format(e=e), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
291 error=True, |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
292 ) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
293 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
294 else: |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
295 data["external"] = data_format.deserialise( |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
296 ext_services_s, type_check=list |
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
297 ) |
3040 | 298 |
4035
9c76678a39e2
cli (info/disco): Add external services in results:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
299 # output |
3040 | 300 await self.output(data) |
301 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
|
302 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
303 |
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
|
304 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
|
305 def __init__(self, host): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
306 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
|
307 |
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
|
308 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
|
309 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
|
310 |
3040 | 311 async def start(self): |
312 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
|
313 jid = jids[0] |
3040 | 314 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4035
diff
changeset
|
315 data = await self.host.bridge.software_version_get(jid, self.host.profile) |
3040 | 316 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
317 self.disp(_("error while trying to get version: {e}").format(e=e), error=True) |
3040 | 318 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
319 else: | |
320 infos = [] | |
321 name, version, os = data | |
322 if name: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
323 infos.append(_("Software name: {name}").format(name=name)) |
3040 | 324 if version: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
325 infos.append(_("Software version: {version}").format(version=version)) |
3040 | 326 if os: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
327 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
|
328 |
3040 | 329 print("\n".join(infos)) |
330 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
|
331 |
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
|
332 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
333 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
|
334 def __init__(self, host): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
335 extra_outputs = {"default": self.default_output} |
3040 | 336 super(Session, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
337 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
338 "session", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
339 use_output="dict", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
340 extra_outputs=extra_outputs, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
341 help=_("running session"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
342 ) |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
343 |
3040 | 344 def add_parser_options(self): |
345 pass | |
346 | |
347 async def default_output(self, data): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
348 started = data["started"] |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
349 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
|
350 short=date_utils.date_fmt(started), |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
351 relative=date_utils.date_fmt(started, "relative"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
352 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
353 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
|
354 |
3040 | 355 async def start(self): |
356 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4035
diff
changeset
|
357 data = await self.host.bridge.session_infos_get(self.host.profile) |
3040 | 358 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
359 self.disp(_("Error getting session infos: {e}").format(e=e), error=True) |
3040 | 360 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
361 else: | |
362 await self.output(data) | |
363 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
|
364 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
365 |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
366 class Devices(base.CommandBase): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
367 def __init__(self, host): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
368 super(Devices, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
369 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
|
370 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
371 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
372 def add_parser_options(self): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
373 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
374 "jid", type=str, nargs="?", default="", help=_("Entity to request") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
375 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
376 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
377 async def start(self): |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
378 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4035
diff
changeset
|
379 data = await self.host.bridge.devices_infos_get( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
380 self.args.jid, self.host.profile |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
381 ) |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
382 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
383 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
|
384 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
385 else: |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
386 data = data_format.deserialise(data, type_check=list) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
387 await self.output(data) |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
388 self.host.quit() |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
389 |
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
390 |
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
|
391 class Info(base.CommandBase): |
3207
a10e12dfbda8
jp(info): `devices` command first draft:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
392 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
|
393 |
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
|
394 def __init__(self, host): |
3040 | 395 super(Info, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
396 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
397 "info", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
398 use_profile=False, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
399 help=_("Get various pieces of information on entities"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
400 ) |