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

handle choices from sub parameters

parent a321bd8b
......@@ -25,8 +25,9 @@ from workflows.types import *
class MiltipleParameters(object):
def __init__(self, types, required):
def __init__(self, types, required, choices):
self.types = types
self.choices = choices
self.index = None
self.required = required
self.__name__ = "MiltipleParameters"
......@@ -34,6 +35,9 @@ class MiltipleParameters(object):
parts = arg.split("=")
if not self.types.has_key(parts[0]):
raise argparse.ArgumentTypeError(parts[0] + " is an invalid flag! Available ones are: "+", ".join(self.types.keys()))
if self.choices[parts[0]] != None:
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]]) + "))")
try:
value = self.types[parts[0]](parts[1])
except:
......@@ -85,20 +89,26 @@ class Parameter(object):
self.display_name = name
else: self.display_name = display_name
self.required = str(required).lower() in ("yes", "y", "true", "t", "1")
self.choices = choices
if self.choices:
self.choices = choices.split("|")
if len(self.sub_parameters) > 0:
self.nargs = "+"
if type == "date":
self.type = date
elif type == "multiple":
sub_param_hash, sub_param_types, sub_param_names, sub_param_required = {}, [], [], []
sub_param_hash, sub_param_types, sub_param_names, sub_param_required, sub_param_choices = {}, [], [], [], {}
for sub_param in self.sub_parameters:
try: sub_type = sub_param.type
except: sub_type = types.StringType
sub_param_hash[sub_param.flag] = sub_type
sub_param_names.append(sub_param.flag)
sub_param_types.append(sub_type)
sub_param_choices[sub_param.flag] = sub_param.choices
if sub_param.required: sub_param_required.append(sub_param.flag)
self.type = MiltipleParameters(sub_param_hash, sub_param_required)
self.type = MiltipleParameters(sub_param_hash, sub_param_required, sub_param_choices)
if self.action == "append":
self.action = MiltipleAppendAction
else:
......@@ -109,11 +119,6 @@ class Parameter(object):
else:
try: self.type = eval(type)
except: self.type = types.StringType
self.required = str(required).lower() in ("yes", "y", "true", "t", "1")
self.choices = choices
if self.choices:
self.choices = choices.split("|")
self.default = default
if type == "date" and not self.default:
......
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