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

Add possibility to merge several OutpuFilelist.

parent 5c10bd42
......@@ -68,15 +68,11 @@ class Component(object):
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
new_param.component_nameid = self.get_nameid()
# store where the parameter is coming from
if issubclass( default.__class__, AbstractIOFile ):
new_param.parent_component_nameid.append(default.component_nameid)
elif issubclass( default.__class__, list ):
for val in default:
if issubclass( val.__class__, AbstractIOFile ):
new_param.parent_component_nameid.append(val.component_nameid)
# store where the parameter is coming from
if hasattr(default, "component_nameid"):
new_param.parent_component_nameid = default.component_nameid
# if this input should be added to a particular parameter
if add_to:
try:
......@@ -93,19 +89,21 @@ class Component(object):
def add_input_file_list(self, name, help, file_format="any", default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, add_to=None):
if default == None: default = []
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=default,
if default == None:
inputs = []
else:
inputs = [IOFile(file, self.get_nameid(), None, file_format) for file in default]
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=inputs,
type=type, required=required, group=group, display_name=display_name)
new_param.component_nameid = self.get_nameid()
# store where the parameter is coming from
if issubclass( default.__class__, AbstractIOFile ):
new_param.parent_component_nameid.append(default.component_nameid)
elif issubclass( default.__class__, list ):
for val in default:
if issubclass( val.__class__, AbstractIOFile ):
new_param.parent_component_nameid.append(val.component_nameid)
# store where the parameter is coming from
if issubclass( default.__class__, list ):
for idx, val in enumerate(default):
if hasattr( val, "component_nameid" ):
new_param[idx].parent_component_nameid = val.component_nameid
elif hasattr( default, "component_nameid" ):
new_param.parent_component_nameid = default.component_nameid
# if this input should be added to a particular parameter
if add_to:
try:
......@@ -162,9 +160,8 @@ class Component(object):
def add_output_file_list(self, name, help, file_format="any", pattern='{basename_woext}.out',
items=None, group="default", display_name=None, add_to=None):
new_param = OutputFileList(name, help, default=self.get_outputs(pattern, items),
file_format=file_format, group=group, display_name=display_name)
new_param.component_nameid = self.get_nameid()
default = [IOFile(file, self.get_nameid(), None, file_format) for file in self.get_outputs(pattern, items)]
new_param = OutputFileList(name, help, default=default, file_format=file_format, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
......@@ -179,7 +176,6 @@ class Component(object):
group="default", display_name=None, add_to=None):
new_param = OutputFilesEndsWith(name, help, self.output_directory, pattern, include=(behaviour == "include"),
file_format=file_format, group=group, display_name=display_name)
new_param.component_nameid = self.get_nameid()
# if this input should be added to a particular parameter
if add_to:
try:
......@@ -194,7 +190,6 @@ class Component(object):
group="default", display_name=None, add_to=None):
new_param = OutputFilesPattern(name, help, self.output_directory, pattern, include=(behaviour == "exclude"),
file_format=file_format, group=group, display_name=display_name)
new_param.component_nameid = self.get_nameid()
# if this input should be added to a particular parameter
if add_to:
try:
......
......@@ -371,12 +371,23 @@ class AbstractParameter(object):
def get_test_function(self):
return create_test_function(self.type)
class AbstractIOFile(object):
def __init__(self, file_format="any"):
self.file_format = file_format
self.component_nameid = None
self.parent_component_nameid = []
self.parent_component_nameid = None
class IOFile(str):
def __new__(self, val="", component_nameid=None, parent_component_nameid=[], file_format="any"):
return str.__new__(self, val)
def __init__(self, val, component_nameid=None, parent_component_nameid=[], file_format="any"):
self.component_nameid = component_nameid
self.parent_component_nameid = parent_component_nameid
self.file_format = file_format
class MultiParameter(dict, AbstractParameter):
......@@ -967,9 +978,9 @@ class OutputFilesEndsWith(DynamicOutput):
output_files = list()
for file in os.listdir( self.output_directory ):
if file.endswith( self.end_str ) and self.include :
output_files.append( os.path.join(self.output_directory, file) )
output_files.append( IOFile(os.path.join(self.output_directory, file), None, None, self.file_format) )
elif not file.endswith( self.end_str ) and not self.include:
output_files.append( os.path.join(self.output_directory, file) )
output_files.append( IOFile(os.path.join(self.output_directory, file), None, None, self.file_format) )
list.__init__(self, output_files)
......@@ -997,7 +1008,7 @@ class OutputFilesPattern(DynamicOutput):
output_files = list()
for file in os.listdir( self.output_directory ):
if self.include and re.search( self.pattern, file ) is not None:
output_files.append( os.path.join(self.output_directory, file) )
output_files.append( IOFile(os.path.join(self.output_directory, file), None, None,self.file_format) )
elif not self.include and re.search( self.pattern, file ) is None:
output_files.append( os.path.join(self.output_directory, file) )
output_files.append( IOFile(os.path.join(self.output_directory, file), None, None,self.file_format) )
return list.__init__(self, output_files)
\ No newline at end of file
......@@ -338,10 +338,14 @@ class Workflow(threading.Thread):
gr.add_node_attribute(cpt.get_nameid(), self.COMPONENT_GRAPH_LABEL)
for cpt in self.components:
for ioparameter in cpt.__dict__.values():
if ( issubclass( ioparameter.__class__, InputFile ) or issubclass( ioparameter.__class__, InputFileList)):
for pc_nameid in ioparameter.parent_component_nameid:
try: gr.add_edge((pc_nameid, ioparameter.component_nameid))
except: pass
if issubclass( ioparameter.__class__, InputFile ) and hasattr(ioparameter, "component_nameid"):
try: gr.add_edge((ioparameter.parent_component_nameid, ioparameter.component_nameid))
except: pass
if issubclass( ioparameter.__class__, InputFileList):
for io in ioparameter:
if hasattr(io, "component_nameid"):
try: gr.add_edge((io.parent_component_nameid, io.component_nameid))
except: pass
return gr
def set_stderr(self):
......@@ -616,6 +620,8 @@ class Workflow(threading.Thread):
# update outputs
for output in cmpt_object.get_dynamic_outputs():
output.update()
for file in output:
file.component_id = cmpt_object.get_nameid()
else:
if self._component_is_duplicated(cmpt_object):
raise ValueError("Component " + cmpt_object.__class__.__name__ + " with prefix " +
......
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