Commit 823b8139 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

multiplelist ok

parent b5c53008
......@@ -237,6 +237,20 @@ class AbstractParameter(object):
def get_type(self):
return self.type.__name__
class AbstractFile(object):
def __init__(self, file_format="any"):
self.file_format = file_format
self.parent_component_nameid = None
class MultiParameter(dict, AbstractParameter):
def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag, group=group,
display_name=display_name)
return dict.__init__(self, {})
def add_sub_parameter(self, param):
param_flag = param.flag[2:]
if self.type == "multiple":
......@@ -251,7 +265,7 @@ class AbstractParameter(object):
self.action = MiltipleAction
self.global_help = self.help
self.help = self.global_help + " (" + param_flag + "=<" + param.type.__name__.upper() + ">)"
self.default = {param.name: param.default}
self.default = {}
self.nargs = "+"
elif self.type.__class__ == MultipleParameters:
self.type.types[param_flag] = param.type
......@@ -261,24 +275,9 @@ class AbstractParameter(object):
if param.required:
self.type.required.append(param_flag)
self.help = self.global_help + self.type.get_help()
self.default[param.name] = param.default
param.flag = param_flag
self.sub_parameters.append(param)
class AbstractFile(object):
def __init__(self, file_format="any"):
self.file_format = file_format
self.parent_component_nameid = None
class MultiParameter(dict, AbstractParameter):
def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag, group=group,
display_name=display_name)
return dict.__init__(self, {})
class MultiParameterList(list, AbstractParameter):
......@@ -287,6 +286,33 @@ class MultiParameterList(list, AbstractParameter):
action="append", group=group, display_name=display_name)
return list.__init__(self, [])
def add_sub_parameter(self, param):
param_flag = param.flag[2:]
if self.type == "multiple":
if param.required: req = [param_flag]
else: req = []
self.type = MultipleParameters({param_flag: param.type}, req,
{param_flag: param.choices}, {}, {param_flag: param.default},
{param_flag: param.action})
if self.action == "append":
self.action = MiltipleAppendAction
else:
self.action = MiltipleAction
self.global_help = self.help
self.help = self.global_help + " (" + param_flag + "=<" + param.type.__name__.upper() + ">)"
self.default = []
self.nargs = "+"
elif self.type.__class__ == MultipleParameters:
self.type.types[param_flag] = param.type
self.type.choices[param_flag] = param.choices
self.type.default[param_flag] = param.default
self.type.actions[param_flag] = param.action
if param.required:
self.type.required.append(param_flag)
self.help = self.global_help + self.type.get_help()
param.flag = param_flag
self.sub_parameters.append(param)
class Parameter(str, AbstractParameter):
......
......@@ -249,9 +249,18 @@ class Workflow(threading.Thread):
if sub_args.has_key(sub_param.flag):
self.__getattribute__(param.name)[sub_param.name] = sub_args[sub_param.flag]
else:
self.__getattribute__(param.name)[sub_param.name] = self.__getattribute__(param.name).default[sub_param.name]
self.__getattribute__(param.name)[sub_param.name] = sub_param.default
elif param.__class__ == MultiParameterList:
print args[param.name]
for sargs in args[param.name]:
sub_args, final_sub_args = {}, {}
for sarg in sargs:
sub_args[sarg[0]] = sarg[1]
for sub_param in param.sub_parameters:
if sub_args.has_key(sub_param.flag):
final_sub_args[sub_param.name] = sub_args[sub_param.flag]
else:
final_sub_args[sub_param.name] = sub_param.default
self.__getattribute__(param.name).append(sub_args)
def _download_urlfile(self, input):
try:
......
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