Commit 572a0a4a authored by Frédéric Escudié's avatar Frédéric Escudié
Browse files

Keep parameters class in sub parameters fo MultipleParameter, MultipleParameterList.

Keep ParameterList, InputFileList instead simple list.
Todo keep MultipleParameter instead dict and MultipleParameterList instead list of dict.
parent 981f9413
......@@ -225,62 +225,61 @@ class Workflow(threading.Thread):
attribute_value.type.excludes[new_group] = flags2exclude
break
def _prepare_parameter(self, args, parameter):
new_param = None
# Retrieve value
if args.has_key(parameter.flag):
value = args[parameter.flag]
elif parameter != None:
value = parameter.default
else:
value = None
# Set new parameter
if parameter.__class__ == StrParameter or parameter.__class__ == IntParameter or parameter.__class__ == FloatParameter or parameter.__class__ == BoolParameter or parameter.__class__ == DateParameter:
new_param = ParameterFactory.factory( parameter.name, parameter.help, default=value, type=parameter.type, choices=parameter.choices,
required=parameter.required, flag=parameter.flag, group=parameter.group,
display_name=parameter.display_name )
elif parameter.__class__ == ParameterList:
new_param = ParameterList( parameter.name, parameter.help, default=value, type=parameter.type, choices=parameter.choices,
required=parameter.required, flag=parameter.flag, sub_parameters=parameter.sub_parameters,
group=parameter.group, display_name=parameter.display_name )
elif parameter.__class__ == InputFileList:
new_param = InputFileList( parameter.name, parameter.help, file_format=parameter.file_format, default=parameter.prepare_input_files(value),
type=parameter.type, choices=parameter.choices, required=parameter.required, flag=parameter.flag,
group=parameter.group, display_name=parameter.display_name, size_limit=parameter.size_limit )
elif parameter.__class__ == InputFile:
new_param = InputFile( parameter.name, parameter.help, file_format=parameter.file_format, default=parameter.prepare_input_file(value),
type=parameter.type, choices=parameter.choices, required=parameter.required, flag=parameter.flag,
group=parameter.group, display_name=parameter.display_name )
else:
raise Exception( "Unknown class '" + parameter.__class__.__name__ + "' for parameter.")
return new_param
def _set_parameters(self, args):
parameters = self.get_parameters()
for param in parameters:
try: args[param.name] = args[param.name].encode('ascii','ignore')
except: pass
if param.__class__ == StrParameter or param.__class__ == IntParameter or param.__class__ == FloatParameter or param.__class__ == BoolParameter or param.__class__ == DateParameter:
if args[param.name]: default = args[param.name]
else: default = param.default
new_param = ParameterFactory.factory(param.name, param.help, default=default, type=param.type, choices=param.choices,
required=param.required, flag=param.flag, group=param.group, display_name=param.display_name)
self.__setattr__(param.name, new_param)
elif param.__class__ == InputFile:
if args[param.name]:
default = param.prepare_input_file(args[param.name])
else:
default = param.default
new_param = InputFile(param.name, param.help, file_format=param.file_format, default=default, type=param.type,
choices=param.choices, required=param.required, flag=param.flag,
group=param.group, display_name=param.display_name)
self.__setattr__(param.name, new_param)
elif param.__class__ == InputFileList and args[param.name]:
self.__setattr__(param.name, param.prepare_input_files(args[param.name]))
elif param.__class__ == ParameterList and args[param.name]:
self.__setattr__(param.name, args[param.name])
elif param.__class__ == MultiParameter:
if param.__class__ == MultiParameter:
sub_args = {}
for sarg in args[param.name]:
sub_args[sarg[0]] = sarg[1]
for sub_param in param.sub_parameters:
if sub_args.has_key(sub_param.flag):
value = sub_args[sub_param.flag]
else:
value = sub_param.default
if sub_param.__class__ == InputFile:
value = sub_param.prepare_input_file(value)
elif sub_param.__class__ == InputFileList:
value = sub_param.prepare_input_files(value)
self.__getattribute__(param.name)[sub_param.name] = value
self.__getattribute__(param.name)[sub_param.name] = self._prepare_parameter( sub_args, sub_param )
elif param.__class__ == MultiParameterList:
final_vals = []
new_param = []
for sargs in args[param.name]:
sub_args, final_sub_args = {}, {}
new_multi_param = {}
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):
value = sub_args[sub_param.flag]
new_sub_param = self._prepare_parameter(sub_args, sub_param)
new_multi_param[new_sub_param.name] = new_sub_param
new_param.append(new_multi_param)
self.__setattr__(param.name, new_param)
else:
value = sub_param.default
if sub_param.__class__ == InputFile:
value = sub_param.prepare_input_file(value)
elif sub_param.__class__ == InputFileList:
value = sub_param.prepare_input_files(value)
final_sub_args[sub_param.name] = value
final_vals.append(final_sub_args)
self.__setattr__(param.name, final_vals)
self.__setattr__(param.name, self._prepare_parameter(args, param ))
def get_execution_graph(self):
graph = Graph(graph_dict={})
......
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