annotate libervia/cli/cmd_param.py @ 4219:1b5cf2ee1d86

plugin XEP-0384, XEP-0391: download missing devices list: when a peer jid was not in our roster, devices list was not retrieved, resulting in failed en/decryption. This patch does check it and download missing devices list in necessary. There is no subscription managed yet, so the list won't be updated in case of new devices, this should be addressed at some point.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:36 +0100
parents 47401850dec6
children 0d7bb4df2343
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
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1594
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
7
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
12
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
17
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
20
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
21
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
22 from . import base
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core.i18n import _
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
24 from .constants import Const as C
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
25
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
26 __commands__ = ["Param"]
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
27
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
28
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
29 class Get(base.CommandBase):
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
30 def __init__(self, host):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
31 super(Get, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
32 host, "get", need_connect=False, help=_("get a parameter value")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
33 )
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
34
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
35 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
36 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
37 "category", nargs="?", help=_("category of the parameter")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
38 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
39 self.parser.add_argument("name", nargs="?", help=_("name of the parameter"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
40 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
41 "-a",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
42 "--attribute",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
43 type=str,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
44 default="value",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
45 help=_("name of the attribute to get"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
46 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
47 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
48 "--security-limit", type=int, default=-1, help=_("security limit")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
49 )
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
50
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
51 async def start(self):
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
52 if self.args.category is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
53 categories = await self.host.bridge.params_categories_get()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 print("\n".join(categories))
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
55 elif self.args.name is None:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
56 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
57 values_dict = await self.host.bridge.params_values_from_category_get_async(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
58 self.args.category, self.args.security_limit, "", "", self.profile
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
59 )
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
60 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
61 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
62 _("can't find requested parameters: {e}").format(e=e), error=True
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
63 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 self.host.quit(C.EXIT_NOT_FOUND)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 for name, value in values_dict.items():
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 print(f"{name}\t{value}")
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
68 else:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
69 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
70 value = await self.host.bridge.param_get_a_async(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
71 self.args.name,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
72 self.args.category,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
73 self.args.attribute,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
74 self.args.security_limit,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
75 self.profile,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
76 )
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
77 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
78 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
79 _("can't find requested parameter: {e}").format(e=e), error=True
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
80 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 self.host.quit(C.EXIT_NOT_FOUND)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 print(value)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 self.host.quit()
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
85
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
86
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
87 class Set(base.CommandBase):
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
88 def __init__(self, host):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
89 super(Set, self).__init__(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 host, "set", need_connect=False, help=_("set a parameter value")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
91 )
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
92
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
93 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
94 self.parser.add_argument("category", help=_("category of the parameter"))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
95 self.parser.add_argument("name", help=_("name of the parameter"))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
96 self.parser.add_argument("value", help=_("name of the parameter"))
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 self.parser.add_argument(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
98 "--security-limit", type=int, default=-1, help=_("security limit")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 )
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
100
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
101 async def start(self):
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
102 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
103 await self.host.bridge.param_set(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 self.args.name,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
105 self.args.value,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 self.args.category,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 self.args.security_limit,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 self.profile,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
109 )
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
110 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 self.disp(_("can't set requested parameter: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
112 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
113 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
114 self.host.quit()
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
115
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
116
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
117 class SaveTemplate(base.CommandBase):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
118 # FIXME: this should probably be removed, it's not used and not useful for end-user
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
119
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
120 def __init__(self, host):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
121 super(SaveTemplate, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
123 "save",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
124 use_profile=False,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125 help=_("save parameters template to xml file"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
126 )
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
127
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
128 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
129 self.parser.add_argument("filename", type=str, help=_("output file"))
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
130
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
131 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
132 """Save parameters template to XML file"""
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
133 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
134 await self.host.bridge.params_template_save(self.args.filename)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
135 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
136 self.disp(_("can't save parameters to file: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
137 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
138 else:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
139 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
140 _("parameters saved to file {filename}").format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
141 filename=self.args.filename
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
142 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
144 self.host.quit()
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
145
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
146
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
147 class LoadTemplate(base.CommandBase):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 # FIXME: this should probably be removed, it's not used and not useful for end-user
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
149
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
150 def __init__(self, host):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
151 super(LoadTemplate, self).__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
152 host,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
153 "load",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
154 use_profile=False,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155 help=_("load parameters template from xml file"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
156 )
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
157
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
158 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 self.parser.add_argument("filename", type=str, help=_("input file"))
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
160
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 async def start(self):
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
162 """Load parameters template from xml file"""
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
163 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
164 self.host.bridge.params_template_load(self.args.filename)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
165 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
166 self.disp(_("can't load parameters from file: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
168 else:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
169 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
170 _("parameters loaded from file {filename}").format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 filename=self.args.filename
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
172 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
173 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
174 self.host.quit()
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
175
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
176
1545
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
177 class Param(base.CommandBase):
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
178 subcommands = (Get, Set, SaveTemplate, LoadTemplate)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
179
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
180 def __init__(self, host):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
181 super(Param, self).__init__(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
182 host, "param", use_profile=False, help=_("Save/load parameters template")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
183 )