Commit 3f2567d5 authored by Frédéric Escudié's avatar Frédéric Escudié
Browse files

Keep MultipleParameter instead dict and MultipleParameterList instead list of dict.

parent 572a0a4a
......@@ -67,6 +67,8 @@ def urlfile(file):
raise argparse.ArgumentTypeError("URL '" + file + "' does not contain any file name!")
def inputfile(file):
if file == None:
return None
# test the format
uri_object = urlparse(file)
# check the file
......@@ -363,6 +365,7 @@ class MultiParameter(dict, AbstractParameter):
self.type.required.append(param_flag)
self.help = self.global_help + self.type.get_help()
param.flag = param_flag
self[param.name] = param
self.sub_parameters.append(param)
......@@ -398,6 +401,7 @@ class MultiParameterList(list, AbstractParameter):
self.type.required.append(param_flag)
self.help = self.global_help + self.type.get_help()
param.flag = param_flag
self.append(param)
self.sub_parameters.append(param)
......@@ -432,9 +436,9 @@ class BoolParameter(int, AbstractParameter):
val.is_None = False
if default == None:
val.is_None = True
for attr in val.__dict__:
value = getattr(val, attr)
if callable(value) and attr not in ["__new__", "__init__", "__int__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
for attr in bool.__dict__:
value = getattr(bool, attr)
if callable(value) and attr not in ["__new__", "__str__", "__init__", "__int__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
setattr(val, attr, noneException)
return val
......@@ -445,7 +449,7 @@ class BoolParameter(int, AbstractParameter):
def __str__(self):
if self.is_None:
noneException()
return str(None)
return str(bool(self))
def __eq__(self, other):
......@@ -475,9 +479,9 @@ class IntParameter(int, AbstractParameter):
val.is_None = False
if default == None:
val.is_None = True
for attr in val.__dict__:
value = getattr(val, attr)
if callable(value) and attr not in ["__new__", "__init__", "__int__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
for attr in int.__dict__:
value = getattr(int, attr)
if callable(value) and attr not in ["__new__", "__init__", "__str__", "__int__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
setattr(val, attr, noneException)
return val
......@@ -486,6 +490,11 @@ class IntParameter(int, AbstractParameter):
AbstractParameter.__init__(self, name, help, flag=flag, default=default, type=type, choices=choices, required=required,
action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
def __str__(self):
if self.is_None:
return str(None)
return str(int(self))
def __eq__(self, other):
if other.__class__.__name__ == "NoneType":
return self.is_None
......@@ -513,9 +522,9 @@ class FloatParameter(float, AbstractParameter):
val.is_None = False
if default == None:
val.is_None = True
for attr in val.__dict__:
value = getattr(val, attr)
if callable(value) and attr not in ["__new__", "__init__", "__float__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
for attr in float.__dict__:
value = getattr(float, attr)
if callable(value) and attr not in ["__new__", "__init__", "__str__", "__float__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
setattr(val, attr, noneException)
return val
......@@ -524,6 +533,11 @@ class FloatParameter(float, AbstractParameter):
AbstractParameter.__init__(self, name, help, flag=flag, default=default, type=type, choices=choices, required=required,
action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
def __str__(self):
if self.is_None:
return str(None)
return str(float(self))
def __eq__(self, other):
if other.__class__.__name__ == "NoneType":
return self.is_None
......@@ -551,8 +565,8 @@ class StrParameter(str, AbstractParameter):
val.is_None = False
if default == None:
val.is_None = True
for attr in val.__dict__:
value = getattr(val, attr)
for attr in str.__dict__:
value = getattr(str, attr)
if callable(value) and attr not in ["__new__", "__init__", "__str__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
setattr(val, attr, noneException)
return val
......@@ -562,6 +576,11 @@ class StrParameter(str, AbstractParameter):
AbstractParameter.__init__(self, name, help, flag=flag, default=default, type=type, choices=choices, required=required,
action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
def __str__(self):
if self.is_None:
return str(None)
return str.__str__(self)
def __eq__(self, other):
if other.__class__.__name__ == "NoneType":
return self.is_None
......@@ -595,9 +614,9 @@ class DateParameter(datetime.datetime, AbstractParameter):
val.is_None = False
else:
val.is_None = True
for attr in val.__dict__:
value = getattr(val, attr)
if callable(value) and attr not in ["__new__", "__init__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
for attr in datetime.datetime.__dict__:
value = getattr(datetime.datetime, attr)
if callable(value) and attr not in ["__new__", "__init__", "__str__", "__getattribute__", "__eq__", "__ne__", "__nonzero__"]:
setattr(val, attr, noneException)
return val
......@@ -609,6 +628,11 @@ class DateParameter(datetime.datetime, AbstractParameter):
AbstractParameter.__init__(self, name, help, flag=flag, default=default, type=type, choices=choices, required=required,
action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
def __str__(self):
if self.is_None:
return str(None)
return datetime.datetime.__str__(self)
def __eq__(self, other):
if other.__class__.__name__ == "NoneType":
return self.is_None
......@@ -697,7 +721,6 @@ class InputFile(StrParameter, AbstractInputFile):
def __new__(self, name, help, file_format="any", default="", type="localfile", choices=None,
required=False, flag=None, group="default", display_name=None, size_limit="0"):
if hasattr(type, '__call__'):
type2test = type.__name__
else: type2test = type
......@@ -724,6 +747,8 @@ class InputFile(StrParameter, AbstractInputFile):
return create_test_function(ctype)
def prepare_input_file(self, input):
if input == None:
return None
# handle url inputs
new_path, is_uri = self._download_urlfile(input)
# handle upload inputs
......
......@@ -260,26 +260,28 @@ class Workflow(threading.Thread):
for param in parameters:
try: args[param.name] = args[param.name].encode('ascii','ignore')
except: pass
new_param = None
if param.__class__ == MultiParameter:
new_param = MultiParameter(param.name, param.help, required=param.required, flag=param.flag, group=param.group, display_name=param.display_name)
sub_args = {}
for sarg in args[param.name]:
sub_args[sarg[0]] = sarg[1]
for sub_param in param.sub_parameters:
self.__getattribute__(param.name)[sub_param.name] = self._prepare_parameter( sub_args, sub_param )
new_param.add_sub_parameter(self._prepare_parameter(sub_args, sub_param))
elif param.__class__ == MultiParameterList:
new_param = []
for sargs in args[param.name]:
new_multi_param = {}
new_param = MultiParameterList(param.name, param.help, required=param.required, flag=param.flag, group=param.group, display_name=param.display_name)
for idx, sargs in enumerate(args[param.name]):
new_multi_param = MultiParameter(param.name + '_' + str(idx), '', required=False, flag=None, group="default", display_name=None)
sub_args = {}
for sarg in sargs:
sub_args[sarg[0]] = sarg[1]
for sub_param in param.sub_parameters:
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)
new_multi_param.add_sub_parameter(sub_param)
new_param.add_sub_parameter(new_multi_param)
else:
self.__setattr__(param.name, self._prepare_parameter(args, param ))
new_param = self._prepare_parameter(args, param )
self.__setattr__(param.name, new_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