comparison frontends/src/jp/cmd_param.py @ 1589:add1a6c8c594

jp: optional positional arguments on "param get" command category and name are both optionals: - if nothing is given, categories list is printed - if only a category is given, a list of params and their values is printed - if both category and name are given, the requested param is printed
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2015 19:18:10 +0100
parents b8ee774c12c8
children 791c45ed8659
comparison
equal deleted inserted replaced
1588:823a385235ef 1589:add1a6c8c594
27 class Get(base.CommandBase): 27 class Get(base.CommandBase):
28 def __init__(self, host): 28 def __init__(self, host):
29 super(Get, self).__init__(host, 'get', help=_('Get a parameter value')) 29 super(Get, self).__init__(host, 'get', help=_('Get a parameter value'))
30 30
31 def add_parser_options(self): 31 def add_parser_options(self):
32 self.parser.add_argument("category", type=base.unicode_decoder, help=_(u"Category of the parameter")) 32 self.parser.add_argument("category", nargs='?', 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")) 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")) 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")) 35 self.parser.add_argument("--security-limit", type=int, default=-1, help=_(u"Security limit"))
36 36
37 def connected(self): 37 def connected(self):
38 super(Get, self).connected() 38 super(Get, self).connected()
39 if self.args.category is None:
40 categories = self.host.bridge.getParamsCategories()
41 print u"\n".join(categories)
42 elif self.args.name is None:
43 try:
44 values_dict = self.host.bridge.asyncGetParamsValuesFromCategory(self.args.category, self.args.security_limit, self.profile)
45 except Exception as e:
46 print u"Can't find requested parameters: {}".format(e)
47 self.host.quit(1)
48 for name, value in values_dict.iteritems():
49 print u"{}\t{}".format(name, value)
50 else:
51 try:
52 value = self.host.bridge.asyncGetParamA(self.args.name, self.args.category, self.args.attribute,
53 self.args.security_limit, self.profile)
54 except Exception as e:
55 print u"Can't find requested parameter: {}".format(e)
56 self.host.quit(1)
57 print value
58
59
39 try: 60 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 61
47 62
48 class SaveTemplate(base.CommandBase): 63 class SaveTemplate(base.CommandBase):
49 def __init__(self, host): 64 def __init__(self, host):
50 super(SaveTemplate, self).__init__(host, 'save', use_profile=False, help=_('Save parameters template to xml file')) 65 super(SaveTemplate, self).__init__(host, 'save', use_profile=False, help=_('Save parameters template to xml file'))