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

better handle of inputdirectory

parent 954672ca
...@@ -744,24 +744,37 @@ class DateParameter(datetime.datetime, AbstractParameter): ...@@ -744,24 +744,37 @@ class DateParameter(datetime.datetime, AbstractParameter):
return (DateParameter, (self.name, self.help, self.default, date, self.choices, self.required, return (DateParameter, (self.name, self.help, self.default, date, self.choices, self.required,
self.flag, self.sub_parameters, self.group, self.display_name), None, None, None) self.flag, self.sub_parameters, self.group, self.display_name), None, None, None)
def input_directory_get_files_fn(input):
return os.listdir(input)
class InputDirectory(StrParameter, LinkTraceback): class InputDirectory(StrParameter, LinkTraceback):
def __new__(self, name, help, default="", choices=None, required=False, flag=None, def __new__(self, name, help, default="", choices=None, required=False, flag=None,
group="default", display_name=None, cmd_format="", argpos=-1): group="default", display_name=None, get_files_fn=None, cmd_format="", argpos=-1):
return StrParameter.__new__(self, name, help, flag=flag, default=default, type="inputdirectory", choices=choices, return StrParameter.__new__(self, name, help, flag=flag, default=default, type="inputdirectory", choices=choices,
required=required, group=group, display_name=display_name, cmd_format=cmd_format, argpos=argpos) required=required, group=group, display_name=display_name, cmd_format=cmd_format, argpos=argpos)
def __init__(self, name, help, default="", choices=None, required=False, flag=None, def __init__(self, name, help, default="", choices=None, required=False, flag=None,
group="default", display_name=None, cmd_format="", argpos=-1): group="default", display_name=None, get_files_fn=None, cmd_format="", argpos=-1):
LinkTraceback.__init__(self) LinkTraceback.__init__(self)
StrParameter.__init__(self, name, help, flag=flag, default=default, type="inputdirectory", choices=choices, StrParameter.__init__(self, name, help, flag=flag, default=default, type="inputdirectory", choices=choices,
required=required, group=group, display_name=display_name, cmd_format=cmd_format, argpos=argpos) required=required, group=group, display_name=display_name, cmd_format=cmd_format, argpos=argpos)
if hasattr(get_files_fn, "__call__"):
self.get_files_fn = get_files_fn
else:
self.get_files_fn = input_directory_get_files_fn
def prepare(self, input): def prepare(self, input):
if input == None: if input == None:
return None return None
return os.path.abspath(input) return os.path.abspath(input)
def get_files(self):
files = []
for file in self.get_files_fn(self):
files.append( IOFile(os.path.join(self, file), "any", self.linkTrace_nameid, None) )
return files
class AbstractInputFile(AbstractIOFile): class AbstractInputFile(AbstractIOFile):
""" """
@summary : Parent of all InputFile(s) parameters. @summary : Parent of all InputFile(s) parameters.
......
...@@ -159,9 +159,9 @@ class Workflow(threading.Thread): ...@@ -159,9 +159,9 @@ class Workflow(threading.Thread):
self.comp_pckg = self._import_components() self.comp_pckg = self._import_components()
def add_input_directory(self, name, help, default=None, required=False, flag=None, def add_input_directory(self, name, help, default=None, required=False, flag=None,
group="default", display_name=None, add_to=None): group="default", display_name=None, get_files_fn=None, add_to=None):
new_param = InputDirectory(name, help, flag=flag, default=default, new_param = InputDirectory(name, help, flag=flag, default=default, required=required,
required=required, group=group, display_name=display_name) group=group, display_name=display_name, get_files_fn=get_files_fn)
new_param.linkTrace_nameid = name new_param.linkTrace_nameid = name
# if this input should be added to a particular parameter # if this input should be added to a particular parameter
if add_to: if add_to:
...@@ -326,7 +326,7 @@ class Workflow(threading.Thread): ...@@ -326,7 +326,7 @@ class Workflow(threading.Thread):
prepared_directory = parameter.prepare(value) prepared_directory = parameter.prepare(value)
new_param = InputDirectory( parameter.name, parameter.help, default=prepared_directory, choices=parameter.choices, new_param = InputDirectory( parameter.name, parameter.help, default=prepared_directory, choices=parameter.choices,
required=parameter.required, flag=parameter.flag, group=parameter.group, required=parameter.required, flag=parameter.flag, group=parameter.group,
display_name=parameter.display_name ) display_name=parameter.display_name, get_files_fn=parameter.get_files_fn)
new_param.linkTrace_nameid = parameter.linkTrace_nameid new_param.linkTrace_nameid = parameter.linkTrace_nameid
else: else:
raise Exception( "Unknown class '" + parameter.__class__.__name__ + "' for parameter.") raise Exception( "Unknown class '" + parameter.__class__.__name__ + "' for parameter.")
......
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