[svn] commit: r342 - in /branches/jelte-datadef/src/lib/bigtool: bigtool.py command.py moduleinfo.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 3 10:56:56 UTC 2009
Author: jelte
Date: Thu Dec 3 10:56:56 2009
New Revision: 342
Log:
positional arguments for bigtool; if the command arguments are not in 'name = value' pairs, the arguments are parsed based on their position. The parser then adds the names again (so for the application the params is still a {name:value} dict
Modified:
branches/jelte-datadef/src/lib/bigtool/bigtool.py
branches/jelte-datadef/src/lib/bigtool/command.py
branches/jelte-datadef/src/lib/bigtool/moduleinfo.py
Modified: branches/jelte-datadef/src/lib/bigtool/bigtool.py
==============================================================================
--- branches/jelte-datadef/src/lib/bigtool/bigtool.py (original)
+++ branches/jelte-datadef/src/lib/bigtool/bigtool.py Thu Dec 3 10:56:56 2009
@@ -60,13 +60,33 @@
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command,
list(params.keys())[0])
elif params:
+ param_name = None
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)
+ 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
Modified: branches/jelte-datadef/src/lib/bigtool/command.py
==============================================================================
--- branches/jelte-datadef/src/lib/bigtool/command.py (original)
+++ branches/jelte-datadef/src/lib/bigtool/command.py Thu Dec 3 10:56:56 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,16 @@
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:
+ #raise CmdParamFormatError(self.module, self.command)
+ # 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/jelte-datadef/src/lib/bigtool/moduleinfo.py
==============================================================================
--- branches/jelte-datadef/src/lib/bigtool/moduleinfo.py (original)
+++ branches/jelte-datadef/src/lib/bigtool/moduleinfo.py Thu Dec 3 10:56:56 2009
@@ -81,7 +81,17 @@
return [name for name in all_names
if not self.params[name].is_optional]
-
+ def get_param_name_by_position(self, pos):
+ if type(pos) == int:
+ 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(str(pos) + " is not an integer")
+
def need_instance_param(self):
return self.need_inst_param
More information about the bind10-changes
mailing list