Commit 548ea197 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add output directory for components #TODO: take input/output directories in account on process

parent 8536ddb2
......@@ -236,6 +236,17 @@ class Component(object):
# add it to the class itself
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_output_directory(self, name, help, dirname=None, group="default", display_name=None,
cmd_format="", argpos=-1):
dirname = os.path.basename(dirname)
new_param = OutputDirectory(name, help, default=os.path.join(self.output_directory, dirname),
group=group, display_name=display_name, cmd_format=cmd_format, argpos=argpos)
# store where the parameter is coming from
new_param.linkTrace_nameid = self.get_nameid()
# add it to the class itself
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_output_file(self, name, help, file_format="any", filename=None, group="default", display_name=None,
cmd_format="", argpos=-1):
......
......@@ -57,6 +57,12 @@ def browsefile(file):
# from the gui, this will not been tested this way
return localfile(file)
def localdirectory(directory):
if os.path.isdir(directory):
return directory
else:
raise argparse.ArgumentTypeError("'" + directory + "' is not a valid directory!")
def localfile(file):
if os.path.isfile(file):
return file
......@@ -991,6 +997,27 @@ class InputFile(StrParameter, AbstractInputFile):
return new_path
class OutputDirectory(StrParameter, LinkTraceback):
def __new__(self, name, help, default="", choices=None, required=False, flag=None, group="default",
display_name=None, cmd_format="", argpos=-1):
return StrParameter.__new__(self, name, help, flag=flag, default=default, type="localdirectory", choices=choices,
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, group="default",
display_name=None, cmd_format="", argpos=-1):
if issubclass(default.__class__, list):
raise Exception("The parameter '" + name + "' cannot be set with a list.")
StrParameter.__init__(self, name, help, flag=flag, default=default, type="localdirectory", choices=choices,
required=required, group=group, display_name=display_name, cmd_format=cmd_format,
argpos=argpos)
LinkTraceback.__init__(self)
def __getnewargs__(self):
return (self.name, self.help, self.default, self.choices, self.required,
self.flag, self.group, self.display_name, self.cmd_format, self.argpos)
class OutputFile(StrParameter, AbstractOutputFile):
def __new__(self, name, help, file_format="any", default="", choices=None,
......
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