annotate sat_frontends/jp/cmd_param.py @ 3035:25af53e2990a

install (setup.py): updated `python_requires`
author Goffi <goffi@goffi.org>
date Sun, 25 Aug 2019 09:53:03 +0200
parents ab2696e34d29
children fee60f17ebac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
3e168cde7a7d jp: fixed shebang python call
Goffi <goffi@goffi.org>
parents: 1864
diff changeset
1 #!/usr/bin/env python2
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
3
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # jp: a SAT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
5 # Copyright (C) 2009-2019 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
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from sat.core.i18n import _
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
24 __commands__ = ["Param"]
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
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
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
27 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
28 def __init__(self, host):
1594
313f2bb7841b jp: profile session can now be started without connection:
Goffi <goffi@goffi.org>
parents: 1593
diff changeset
29 super(Get, self).__init__(host, 'get', need_connect=False, help=_('Get a parameter value'))
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
30
b8ee774c12c8 jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
31 def add_parser_options(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
32 self.parser.add_argument("category", nargs='?', help=_("Category of the parameter"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
33 self.parser.add_argument("name", nargs='?', help=_("Name of the parameter"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 self.parser.add_argument("-a", "--attribute", type=str, default="value", help=_("Name of the attribute to get"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
35 self.parser.add_argument("--security-limit", type=int, default=-1, help=_("Security limit"))
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
36
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
37 def start(self):
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
38 if self.args.category is None:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
39 categories = self.host.bridge.getParamsCategories()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
40 print("\n".join(categories))
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
41 elif self.args.name is None:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
42 try:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
43 values_dict = self.host.bridge.asyncGetParamsValuesFromCategory(self.args.category, self.args.security_limit, self.profile)
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
44 except Exception as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
45 print("Can't find requested parameters: {}".format(e))
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
46 self.host.quit(1)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
47 for name, value in values_dict.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
48 print("{}\t{}".format(name, value))
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
49 else:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
50 try:
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
51 value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
52 self.args.security_limit, self.profile)
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
53 except Exception as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 print("Can't find requested parameter: {}".format(e))
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
55 self.host.quit(1)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
56 print(value)
1589
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
57
add1a6c8c594 jp: optional positional arguments on "param get" command
Goffi <goffi@goffi.org>
parents: 1545
diff changeset
58
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
59 class Set(base.CommandBase):
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
60 def __init__(self, host):
1594
313f2bb7841b jp: profile session can now be started without connection:
Goffi <goffi@goffi.org>
parents: 1593
diff changeset
61 super(Set, self).__init__(host, 'set', need_connect=False, help=_('Set a parameter value'))
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
62
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
63 def add_parser_options(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
64 self.parser.add_argument("category", help=_("Category of the parameter"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
65 self.parser.add_argument("name", help=_("Name of the parameter"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
66 self.parser.add_argument("value", help=_("Name of the parameter"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
67 self.parser.add_argument("--security-limit", type=int, default=-1, help=_("Security limit"))
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
68
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
69 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
70 try:
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
71 self.host.bridge.setParam(self.args.name, self.args.value, self.args.category, self.args.security_limit, self.profile)
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
72 except Exception as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
73 print("Can set requested parameter: {}".format(e))
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
74
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
75
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
76 class SaveTemplate(base.CommandBase):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
77 def __init__(self, host):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
78 super(SaveTemplate, self).__init__(host, 'save', use_profile=False, help=_('Save parameters template to xml file'))
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
79
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
80 def add_parser_options(self):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
81 self.parser.add_argument("filename", type=str, help=_("Output file"))
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
82
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
83 def start(self):
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
84 """Save parameters template to xml file"""
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
85 if self.host.bridge.saveParamsTemplate(self.args.filename):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
86 print(_("Parameters saved to file %s") % self.args.filename)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
87 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
88 print(_("Can't save parameters to file %s") % self.args.filename)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
89
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
90
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
91 class LoadTemplate(base.CommandBase):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
92
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
93 def __init__(self, host):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
94 super(LoadTemplate, self).__init__(host, 'load', use_profile=False, help=_('Load parameters template from xml file'))
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
95
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
96 def add_parser_options(self):
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
97 self.parser.add_argument("filename", type=str, help=_("Input file"))
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
98
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
99 def start(self):
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
100 """Load parameters template from xml file"""
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
101 if self.host.bridge.loadParamsTemplate(self.args.filename):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
102 print(_("Parameters loaded from file %s") % self.args.filename)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
103 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
104 print(_("Can't load parameters from file %s") % self.args.filename)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
105
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
106
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
107 class Param(base.CommandBase):
1593
791c45ed8659 jp: added param/set command
Goffi <goffi@goffi.org>
parents: 1589
diff changeset
108 subcommands = (Get, Set, SaveTemplate, LoadTemplate)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
109
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff changeset
110 def __init__(self, host):
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
111 super(Param, self).__init__(host, 'param', use_profile=False, help=_('Save/load parameters template'))