comparison frontends/src/jp/cmd_param.py @ 1545:b8ee774c12c8

jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
author Goffi <goffi@goffi.org>
date Mon, 02 Nov 2015 22:02:41 +0100
parents frontends/src/jp/cmd_params.py@069ad98b360d
children add1a6c8c594
comparison
equal deleted inserted replaced
1544:3d5193b4c582 1545:b8ee774c12c8
1 #! /usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # jp: a SAT command line tool
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
6 # Copyright (C) 2013, 2014, 2015 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', help=_('Get a parameter value'))
30
31 def add_parser_options(self):
32 self.parser.add_argument("category", type=base.unicode_decoder, help=_(u"Category of the parameter"))
33 self.parser.add_argument("name", 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 connected(self):
38 super(Get, self).connected()
39 try:
40 value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
41 self.args.security_limit, self.profile)
42 except Exception:
43 print u"Can't find requested parameter"
44 self.host.quit(1)
45 print value
46
47
48 class SaveTemplate(base.CommandBase):
49 def __init__(self, host):
50 super(SaveTemplate, self).__init__(host, 'save', use_profile=False, help=_('Save parameters template to xml file'))
51
52 def add_parser_options(self):
53 self.parser.add_argument("filename", type=str, help=_("Output file"))
54
55 def run(self):
56 """Save parameters template to xml file"""
57 if self.host.bridge.saveParamsTemplate(self.args.filename):
58 print _("Parameters saved to file %s") % self.args.filename
59 else:
60 print _("Can't save parameters to file %s") % self.args.filename
61
62
63 class LoadTemplate(base.CommandBase):
64
65 def __init__(self, host):
66 super(LoadTemplate, self).__init__(host, 'load', use_profile=False, help=_('Load parameters template from xml file'))
67
68 def add_parser_options(self):
69 self.parser.add_argument("filename", type=str, help=_("Input file"))
70
71 def run(self):
72 """Load parameters template from xml file"""
73 if self.host.bridge.loadParamsTemplate(self.args.filename):
74 print _("Parameters loaded from file %s") % self.args.filename
75 else:
76 print _("Can't load parameters from file %s") % self.args.filename
77
78
79 class Param(base.CommandBase):
80 subcommands = (Get, SaveTemplate, LoadTemplate)
81
82 def __init__(self, host):
83 super(Param, self).__init__(host, 'param', use_profile=False, help=_('Save/load parameters template'))