[svn] commit: r399 - in /branches/parkinglot: ./ src/lib/bigtool/bigtool.py src/lib/bigtool/command.py src/lib/bigtool/moduleinfo.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 22 14:09:21 UTC 2009
Author: jelte
Date: Tue Dec 22 14:09:21 2009
New Revision: 399
Log:
add positional parameters in bigtool; merge back from jelte-datadef rev 342 and 386
Modified:
branches/parkinglot/ (props changed)
branches/parkinglot/src/lib/bigtool/bigtool.py
branches/parkinglot/src/lib/bigtool/command.py
branches/parkinglot/src/lib/bigtool/moduleinfo.py
Modified: branches/parkinglot/src/lib/bigtool/bigtool.py
==============================================================================
--- branches/parkinglot/src/lib/bigtool/bigtool.py (original)
+++ branches/parkinglot/src/lib/bigtool/bigtool.py Tue Dec 22 14:09:21 2009
@@ -60,13 +60,35 @@
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command,
list(params.keys())[0])
elif params:
+ param_name = None
+ index = 0
+ param_count = len(params)
for name in params:
- if not name in all_params:
+ # either the name of the parameter must be known, or
+ # the 'name' must be an integer (ie. the position of
+ # an unnamed argument
+ if type(name) == int:
+ # (-1, help is always in the all_params list)
+ if name >= len(all_params) - 1:
+ # add to last known param
+ if param_name:
+ cmd.params[param_name] += cmd.params[name]
+ else:
+ raise CmdUnknownParamSyntaxError(cmd.module, cmd.command, cmd.params[name])
+ else:
+ # replace the numbered items by named items
+ param_name = command_info.get_param_name_by_position(name+1, index, param_count)
+ cmd.params[param_name] = cmd.params[name]
+ del cmd.params[name]
+
+ elif not name in all_params:
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command, name)
+ param_nr = 0
for name in manda_params:
- if not name in params:
+ if not name in params and not param_nr in params:
raise CmdMissParamSyntaxError(cmd.module, cmd.command, name)
+ param_nr += 1
def _handle_cmd(self, cmd):
#to do, consist xml package and send to bind10
@@ -220,6 +242,64 @@
self.modules[cmd.module].command_help(cmd.command)
+ def apply_config_cmd(self, cmd):
+ identifier = self.location
+ try:
+ if 'identifier' in cmd.params:
+ 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:
+ line = value_map['name']
+ if value_map['type'] in [ 'module', 'map', 'list' ]:
+ line += "/"
+ else:
+ line += ":\t" + str(value_map['value'])
+ line += "\t" + value_map['type']
+ line += "\t"
+ if value_map['default']:
+ line += "(default)"
+ if value_map['modified']:
+ line += "(modified)"
+ print(line)
+ elif cmd.command == "add":
+ self.config_data.add(identifier, cmd.params['value'])
+ elif cmd.command == "remove":
+ self.config_data.remove(identifier, cmd.params['value'])
+ elif cmd.command == "set":
+ self.config_data.set(identifier, cmd.params['value'])
+ elif cmd.command == "unset":
+ self.config_data.unset(identifier)
+ elif cmd.command == "revert":
+ 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))
+ raise 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:
return
Modified: branches/parkinglot/src/lib/bigtool/command.py
==============================================================================
--- branches/parkinglot/src/lib/bigtool/command.py (original)
+++ branches/parkinglot/src/lib/bigtool/command.py Tue Dec 22 14:09:21 2009
@@ -72,7 +72,7 @@
if param and param.group('name') == "help":
self.params["help"] = "help"
return
-
+
while True:
if not param_text.strip():
break
@@ -80,9 +80,15 @@
groups = PARAM_PATTERN.match(param_text) or \
PARAM_WITH_QUOTA_PATTERN.match(param_text)
- if not groups:
- raise CmdParamFormatError(self.module, self.command)
- else:
+ if not groups:
+ # ok, fill in the params in the order entered
+ params = re.findall("([^\" ]+|\".*\")", param_text)
+ i = 0
+ for p in params:
+ self.params[i] = p
+ i += 1
+ break
+ else:
self.params[groups.group('param_name')] = groups.group('param_value')
param_text = groups.group('next_params')
if not param_text or (not param_text.strip()):
Modified: branches/parkinglot/src/lib/bigtool/moduleinfo.py
==============================================================================
--- branches/parkinglot/src/lib/bigtool/moduleinfo.py (original)
+++ branches/parkinglot/src/lib/bigtool/moduleinfo.py Tue Dec 22 14:09:21 2009
@@ -34,7 +34,7 @@
node = xmldoc.createElement(PARAM_NODE_NAME)
node.setAttribute('name', name)
node.setAttribute('value', value)
- return node
+ return node
class CommandInfo:
"""One command which provide by one bind10 module, it has zero or
@@ -81,7 +81,49 @@
return [name for name in all_names
if not self.params[name].is_optional]
-
+ def get_param_name_by_position(self, pos, index, param_count):
+ # count mandatories back from the last
+ # from the last mandatory; see the number of mandatories before it
+ # and compare that to the number of positional arguments left to do
+ # if the number of lefts is higher than the number of mandatories,
+ # use the first optional. Otherwise, use the first unhandled mandatory
+ # (and update the location accordingly?)
+ # (can this be done in all cases? this is certainly not the most efficient method;
+ # one way to make the whole of this more consistent is to always set mandatories first, but
+ # that would make some commands less nice to use ("config set value location" instead of "config set location value")
+ if type(pos) == int:
+ if param_count == len(self.params) - 1:
+ i = 0
+ for k in self.params.keys():
+ if i == pos:
+ return k
+ i += 1
+ raise KeyError(str(pos) + " out of range")
+ elif param_count <= len(self.params):
+ mandatory_count = 0
+ for k in self.params.keys():
+ if not self.params[k].is_optional:
+ mandatory_count += 1
+ if param_count == mandatory_count:
+ # return the first mandatory from pos
+ i = 0
+ for k in self.params.keys():
+ if i >= pos and not self.params[k].is_optional:
+ return k
+ i += 1
+ raise KeyError(str(pos) + " out of range")
+ else:
+ i = 0
+ for k in self.params.keys():
+ if i == pos:
+ return k
+ i += 1
+ raise KeyError(str(pos) + " out of range")
+ else:
+ raise KeyError("Too many parameters")
+ else:
+ raise KeyError(str(pos) + " is not an integer")
+
def need_instance_param(self):
return self.need_inst_param
More information about the bind10-changes
mailing list