Commit e42d9f1a authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix a bug with bool sub parameters type

parent d346f2dc
...@@ -25,26 +25,33 @@ from workflows.types import * ...@@ -25,26 +25,33 @@ from workflows.types import *
class MiltipleParameters(object): class MiltipleParameters(object):
def __init__(self, types, required, choices, excludes): def __init__(self, types, required, choices, excludes, default):
self.types = types self.types = types
self.choices = choices self.choices = choices
self.excludes = excludes self.excludes = excludes
self.default = default
self.index = None self.index = None
self.required = required self.required = required
self.__name__ = "MiltipleParameters" self.__name__ = "MiltipleParameters"
def __call__(self, arg): def __call__(self, arg):
parts = arg.split("=") parts = arg.split("=")
if not self.types.has_key(parts[0]): if not self.types.has_key(parts[0]):
raise argparse.ArgumentTypeError(parts[0] + " is an invalid flag! Available ones are: "+", ".join(self.types.keys())) raise argparse.ArgumentTypeError(parts[0] + " is an invalid flag! Available ones are: "+", ".join(self.types.keys()))
if self.choices[parts[0]] != None: if self.choices[parts[0]] != None:
if parts[1] not in self.choices[parts[0]]: if parts[1] not in self.choices[parts[0]]:
raise argparse.ArgumentTypeError("argument " + parts[0] + ": invalid choice: '" + parts[1] + "' (choose from " + ", ".join(self.choices[parts[0]]) + "))") raise argparse.ArgumentTypeError("argument " + parts[0] + ": invalid choice: '" + parts[1] + "' (choose from " + ", ".join(self.choices[parts[0]]) + "))")
try:
value = self.types[parts[0]](parts[1]) if self.types[parts[0]] == types.BooleanType:
except: return (parts[0], not self.default[parts[0]], self.required, self.excludes)
raise argparse.ArgumentTypeError("invalid " + self.types[parts[0]].__name__ + " value: '" + parts[1] + "' for sub parameter '" + parts[0] + "'") else:
self.index = parts[0] try:
return (parts[0], value, self.required, self.excludes) value = self.types[parts[0]](parts[1])
except:
raise argparse.ArgumentTypeError("invalid " + self.types[parts[0]].__name__ + " value: '" + parts[1] + "' for sub parameter '" + parts[0] + "'")
self.index = parts[0]
return (parts[0], value, self.required, self.excludes)
class MiltipleAction(argparse.Action): class MiltipleAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
...@@ -169,6 +176,7 @@ class Parameter(object): ...@@ -169,6 +176,7 @@ class Parameter(object):
self.type = date self.type = date
elif type == "multiple": elif type == "multiple":
sub_param_hash, sub_param_types, sub_param_names, sub_param_required, sub_param_choices, sub_param_excludes = {}, [], [], [], {}, {} sub_param_hash, sub_param_types, sub_param_names, sub_param_required, sub_param_choices, sub_param_excludes = {}, [], [], [], {}, {}
sub_param_default = {}
for sub_param in self.sub_parameters: for sub_param in self.sub_parameters:
try: sub_type = sub_param.type try: sub_type = sub_param.type
except: sub_type = types.StringType except: sub_type = types.StringType
...@@ -176,13 +184,14 @@ class Parameter(object): ...@@ -176,13 +184,14 @@ class Parameter(object):
sub_param_names.append(sub_param.flag) sub_param_names.append(sub_param.flag)
sub_param_types.append(sub_type) sub_param_types.append(sub_type)
sub_param_choices[sub_param.flag] = sub_param.choices sub_param_choices[sub_param.flag] = sub_param.choices
sub_param_default[sub_param.flag] = sub_param.default
if sub_param.group.startswith("exclude-"): if sub_param.group.startswith("exclude-"):
if sub_param.group in sub_param_excludes.keys(): if sub_param.group in sub_param_excludes.keys():
sub_param_excludes[sub_param.group].append(sub_param.flag) sub_param_excludes[sub_param.group].append(sub_param.flag)
else: else:
sub_param_excludes[sub_param.group] = [sub_param.flag] sub_param_excludes[sub_param.group] = [sub_param.flag]
if sub_param.required: sub_param_required.append(sub_param.flag) if sub_param.required: sub_param_required.append(sub_param.flag)
self.type = MiltipleParameters(sub_param_hash, sub_param_required, sub_param_choices, sub_param_excludes) self.type = MiltipleParameters(sub_param_hash, sub_param_required, sub_param_choices, sub_param_excludes, sub_param_default)
if self.action == "append": if self.action == "append":
self.action = MiltipleAppendAction self.action = MiltipleAppendAction
else: else:
......
Supports Markdown
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