Mercurial > libervia-backend
annotate frontends/src/jp/cmd_param.py @ 1549:e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Nov 2015 22:02:41 +0100 |
parents | b8ee774c12c8 |
children | add1a6c8c594 |
rev | line source |
---|---|
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #! /usr/bin/python |
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 |
1396 | 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) | |
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 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 import base |
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): |
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 super(Get, self).__init__(host, 'get', help=_('Get a parameter value')) |
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): |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
32 self.parser.add_argument("category", type=base.unicode_decoder, help=_(u"Category of the parameter")) |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
33 self.parser.add_argument("name", type=base.unicode_decoder, help=_(u"Name of the parameter")) |
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 self.parser.add_argument("-a", "--attribute", type=str, default="value", help=_(u"Name of the attribute to get")) |
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 self.parser.add_argument("--security-limit", type=int, default=-1, help=_(u"Security limit")) |
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 |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
37 def connected(self): |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
38 super(Get, self).connected() |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
39 try: |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
40 value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute, |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
41 self.args.security_limit, self.profile) |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
42 except Exception: |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
43 print u"Can't find requested parameter" |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
44 self.host.quit(1) |
b8ee774c12c8
jp: renamed “params” command to “param” for consistency with other commands + added a “get” subcommand
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
45 print value |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 class SaveTemplate(base.CommandBase): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 def __init__(self, host): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 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
|
51 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 def add_parser_options(self): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 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
|
54 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 def run(self): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 """Save parameters template to xml file""" |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 if self.host.bridge.saveParamsTemplate(self.args.filename): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 print _("Parameters saved to file %s") % self.args.filename |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 else: |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 print _("Can't save parameters to file %s") % self.args.filename |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 class LoadTemplate(base.CommandBase): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 def __init__(self, host): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 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
|
67 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 def add_parser_options(self): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 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
|
70 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 def run(self): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 """Load parameters template from xml file""" |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 if self.host.bridge.loadParamsTemplate(self.args.filename): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 print _("Parameters loaded from file %s") % self.args.filename |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 else: |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 print _("Can't load parameters from file %s") % self.args.filename |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 |
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
|
79 class Param(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
|
80 subcommands = (Get, SaveTemplate, LoadTemplate) |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 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
|
83 super(Param, self).__init__(host, 'param', use_profile=False, help=_('Save/load parameters template')) |