comparison sat_frontends/jp/cmd_param.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/jp/cmd_param.py@0046283a285d
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # jp: a SAT command line tool
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
7
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
17
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22 import base
23 from sat.core.i18n import _
24 __commands__ = ["Param"]
25
26
27 class Get(base.CommandBase):
28 def __init__(self, host):
29 super(Get, self).__init__(host, 'get', need_connect=False, help=_('Get a parameter value'))
30
31 def add_parser_options(self):
32 self.parser.add_argument("category", nargs='?', type=base.unicode_decoder, help=_(u"Category of the parameter"))
33 self.parser.add_argument("name", nargs='?', type=base.unicode_decoder, help=_(u"Name of the parameter"))
34 self.parser.add_argument("-a", "--attribute", type=str, default="value", help=_(u"Name of the attribute to get"))
35 self.parser.add_argument("--security-limit", type=int, default=-1, help=_(u"Security limit"))
36
37 def start(self):
38 if self.args.category is None:
39 categories = self.host.bridge.getParamsCategories()
40 print u"\n".join(categories)
41 elif self.args.name is None:
42 try:
43 values_dict = self.host.bridge.asyncGetParamsValuesFromCategory(self.args.category, self.args.security_limit, self.profile)
44 except Exception as e:
45 print u"Can't find requested parameters: {}".format(e)
46 self.host.quit(1)
47 for name, value in values_dict.iteritems():
48 print u"{}\t{}".format(name, value)
49 else:
50 try:
51 value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
52 self.args.security_limit, self.profile)
53 except Exception as e:
54 print u"Can't find requested parameter: {}".format(e)
55 self.host.quit(1)
56 print value
57
58
59 class Set(base.CommandBase):
60 def __init__(self, host):
61 super(Set, self).__init__(host, 'set', need_connect=False, help=_('Set a parameter value'))
62
63 def add_parser_options(self):
64 self.parser.add_argument("category", type=base.unicode_decoder, help=_(u"Category of the parameter"))
65 self.parser.add_argument("name", type=base.unicode_decoder, help=_(u"Name of the parameter"))
66 self.parser.add_argument("value", type=base.unicode_decoder, help=_(u"Name of the parameter"))
67 self.parser.add_argument("--security-limit", type=int, default=-1, help=_(u"Security limit"))
68
69 def start(self):
70 try:
71 self.host.bridge.setParam(self.args.name, self.args.value, self.args.category, self.args.security_limit, self.profile)
72 except Exception as e:
73 print u"Can set requested parameter: {}".format(e)
74
75
76 class SaveTemplate(base.CommandBase):
77 def __init__(self, host):
78 super(SaveTemplate, self).__init__(host, 'save', use_profile=False, help=_('Save parameters template to xml file'))
79
80 def add_parser_options(self):
81 self.parser.add_argument("filename", type=str, help=_("Output file"))
82
83 def start(self):
84 """Save parameters template to xml file"""
85 if self.host.bridge.saveParamsTemplate(self.args.filename):
86 print _("Parameters saved to file %s") % self.args.filename
87 else:
88 print _("Can't save parameters to file %s") % self.args.filename
89
90
91 class LoadTemplate(base.CommandBase):
92
93 def __init__(self, host):
94 super(LoadTemplate, self).__init__(host, 'load', use_profile=False, help=_('Load parameters template from xml file'))
95
96 def add_parser_options(self):
97 self.parser.add_argument("filename", type=str, help=_("Input file"))
98
99 def start(self):
100 """Load parameters template from xml file"""
101 if self.host.bridge.loadParamsTemplate(self.args.filename):
102 print _("Parameters loaded from file %s") % self.args.filename
103 else:
104 print _("Can't load parameters from file %s") % self.args.filename
105
106
107 class Param(base.CommandBase):
108 subcommands = (Get, Set, SaveTemplate, LoadTemplate)
109
110 def __init__(self, host):
111 super(Param, self).__init__(host, 'param', use_profile=False, help=_('Save/load parameters template'))