Commit bec26c61 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[master] Merge branch 'trac1172'

parents 91071d03 fda8ee0d
......@@ -319,6 +319,8 @@ class BindCmdInterpreter(Cmd):
param_spec = arg)
if ("item_default" in arg):
param.default = arg["item_default"]
if ("item_description" in arg):
param.desc = arg["item_description"]
cmd.add_param(param)
module.add_command(cmd)
self.add_module_info(module)
......@@ -361,12 +363,12 @@ class BindCmdInterpreter(Cmd):
if type(name) == int:
# lump all extraneous arguments together as one big final one
# todo: check if last param type is a string?
if (param_count > 2):
while (param_count > len(command_info.params) - 1):
params[param_count - 2] += params[param_count - 1]
del(params[param_count - 1])
param_count = len(params)
cmd.params = params.copy()
while (param_count > 2 and
param_count > len(command_info.params) - 1):
params[param_count - 2] += " " + params[param_count - 1]
del(params[param_count - 1])
param_count = len(params)
cmd.params = params.copy()
# (-1, help is always in the all_params list)
if name >= len(all_params) - 1:
......
......@@ -57,8 +57,12 @@ class ParamInfo:
def __str__(self):
return str("\t%s <type: %s> \t(%s)" % (self.name, self.type, self.desc))
def get_name(self):
return "%s <type: %s>" % (self.name, self.type)
def get_basic_info(self):
if self.is_optional:
opt_str = "optional"
else:
opt_str = "mandatory"
return "%s (%s, %s)" % (self.name, self.type, opt_str)
def get_desc(self):
return self.desc
......@@ -155,37 +159,24 @@ class CommandInfo:
"""Prints the help info for this command to stdout"""
print("Command ", self)
print("\t\thelp (Get help for command)")
params = self.params.copy()
del params["help"]
if len(params) == 0:
print("No parameters for the command")
print("This command has no parameters")
return
print("\nMandatory parameters:")
mandatory_infos = []
for info in params.values():
if not info.is_optional:
print(" %s" % info.get_name())
print(textwrap.fill(info.get_desc(),
initial_indent=" ",
subsequent_indent=" ",
width=70))
mandatory_infos.append(info)
optional_infos = [info for info in params.values()
if info not in mandatory_infos]
if len(optional_infos) > 0:
print("\nOptional parameters:")
for info in optional_infos:
print(" %s" % info.get_name())
print(textwrap.fill(info.get_desc(),
print("Parameters:")
for info in params.values():
print(" %s" % info.get_basic_info())
description = info.get_desc()
if description != "":
print(textwrap.fill(description,
initial_indent=" ",
subsequent_indent=" ",
width=70))
class ModuleInfo:
"""Define the information of one module, include module name,
module supporting commands.
......
......@@ -180,12 +180,10 @@ class TestCmdSyntax(unittest.TestCase):
self.my_assert_raise(isc.cc.data.DataTypeError, "zone set zone_name ='cn', port='cn'")
self.no_assert_raise("zone reload_all")
def testCmdUnknownModuleSyntaxError(self):
self.my_assert_raise(CmdUnknownModuleSyntaxError, "zoned d")
self.my_assert_raise(CmdUnknownModuleSyntaxError, "dd dd ")
def testCmdUnknownCmdSyntaxError(self):
self.my_assert_raise(CmdUnknownCmdSyntaxError, "zone dd")
......@@ -198,6 +196,7 @@ class TestCmdSyntax(unittest.TestCase):
def testCmdUnknownParamSyntaxError(self):
self.my_assert_raise(CmdUnknownParamSyntaxError, "zone load zone_d='cn'")
self.my_assert_raise(CmdUnknownParamSyntaxError, "zone reload_all zone_name = 'cn'")
self.my_assert_raise(CmdUnknownParamSyntaxError, "zone help a b c")
class TestModuleInfo(unittest.TestCase):
......
......@@ -109,14 +109,17 @@ def convert_type(spec_part, value):
return ret
elif data_type == "map":
map = ast.literal_eval(value)
if type(map) == dict:
# todo: check types of map contents too
return map
else:
raise isc.cc.data.DataTypeError(
"Value in convert_type not a string "
"specifying a dict")
try:
map = ast.literal_eval(value)
if type(map) == dict:
# todo: check types of map contents too
return map
else:
raise isc.cc.data.DataTypeError(
"Value in convert_type not a string "
"specifying a dict")
except SyntaxError as se:
raise isc.cc.data.DataTypeError("Error parsing map: " + str(se))
else:
return value
except ValueError as err:
......
......@@ -157,6 +157,7 @@ class TestConfigData(unittest.TestCase):
self.assertRaises(isc.cc.data.DataTypeError, convert_type, spec_part, [ "a", "b" ])
self.assertRaises(isc.cc.data.DataTypeError, convert_type, spec_part, [ "1", "b" ])
self.assertRaises(isc.cc.data.DataTypeError, convert_type, spec_part, { "a": 1 })
self.assertRaises(isc.cc.data.DataTypeError, convert_type, spec_part, "\"{ \"a\": 1 }\"")
spec_part = find_spec_part(config_spec, "value7")
self.assertEqual(['1', '2'], convert_type(spec_part, '1, 2'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment