Commit 16bcd9fd authored by Jelte Jansen's avatar Jelte Jansen
Browse files

config 'go' command, keep track of location within the configuration


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@345 e5f2f494-b856-4b98-b285-d166d9295462
parent d4a6b8a6
......@@ -59,7 +59,7 @@ def prepare_config_commands(bigtool):
cmd = CommandInfo(name = "add", desc = "Add entry to configuration list", need_inst_param = False)
param = ParamInfo(name = "identifier", type = "string", optional=True)
cmd.add_param(param)
param = ParamInfo(name = "value", type = "string", optional=True)
param = ParamInfo(name = "value", type = "string", optional=False)
cmd.add_param(param)
module.add_command(cmd)
......@@ -88,6 +88,11 @@ def prepare_config_commands(bigtool):
cmd = CommandInfo(name = "commit", desc = "Commit all local changes", need_inst_param = False)
module.add_command(cmd)
cmd = CommandInfo(name = "go", desc = "Go to a specific configuration part", need_inst_param = False)
param = ParamInfo(name = "identifier", type="string", optional=False)
cmd.add_param(param)
module.add_command(cmd)
bigtool.add_module_info(module)
......
......@@ -30,13 +30,19 @@ class BigTool(Cmd):
def __init__(self, session = None):
Cmd.__init__(self)
self.prompt = '> '
self.location = ""
self.prompt_end = '> '
self.prompt = self.prompt_end
self.ruler = '-'
self.modules = OrderedDict()
self.add_module_info(ModuleInfo("help", desc = "Get help for bigtool"))
self.cc = session
self.config_data = ISC.CC.data.UIConfigData("", session)
def postcmd(self, stop, line):
self.prompt = self.location + self.prompt_end
return stop
def validate_cmd(self, cmd):
if not cmd.module in self.modules:
raise CmdUnknownModuleSyntaxError(cmd.module)
......@@ -124,7 +130,7 @@ class BigTool(Cmd):
def onecmd(self, line):
if line == 'EOF'or line.lower() == "quit":
if line == 'EOF' or line.lower() == "quit":
return True
if line == 'h':
......@@ -146,7 +152,7 @@ class BigTool(Cmd):
text)
if cmd.module == "config":
# grm text has been stripped of slashes...
my_text = cur_line.rpartition(" ")[2]
my_text = self.location + "/" + cur_line.rpartition(" ")[2]
list = self.config_data.config.get_item_list(my_text.rpartition("/")[0])
hints.extend([val for val in list if val.startswith(text)])
except CmdModuleNameFormatError:
......@@ -249,10 +255,15 @@ class BigTool(Cmd):
def apply_config_cmd(self, cmd):
identifier = ""
identifier = self.location
try:
if 'identifier' in cmd.params:
identifier = cmd.params['identifier']
if not identifier.endswith("/"):
identifier += "/"
if cmd.params['identifier'].startswith("/"):
identifier = cmd.params['identifier']
else:
identifier += cmd.params['identifier']
if cmd.command == "show":
values = self.config_data.get_value_maps(identifier)
for value_map in values:
......@@ -280,10 +291,25 @@ class BigTool(Cmd):
self.config_data.revert()
elif cmd.command == "commit":
self.config_data.commit(self.cc)
elif cmd.command == "go":
self.go(identifier)
except ISC.CC.data.DataTypeError as dte:
print("Error: " + str(dte))
except ISC.CC.data.DataNotFoundError as dnfe:
print("Error: " + identifier + " not found")
except KeyError as ke:
print("Error: missing " + str(ke))
def go(self, identifier):
# just to see if it exists
self.config_data.get_value(identifier)
# some sanitizing
identifier = identifier.replace("//", "/")
if not identifier.startswith("/"):
identifier = "/" + identifier
if identifier.endswith("/"):
identifier = identifier[:-1]
self.location = identifier
def apply_cmd(self, cmd):
if not self.cc:
......
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