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

Fix bugs with regexp files.

parent 53456423
......@@ -39,6 +39,7 @@ from workflows.formats import *
# define all input type available
INPUTFILE_TYPES = ["inputfile", "localfile", "urlfile", "browsefile"]
INPUTFILES_TYPES = ["inputfiles", "localfile", "urlfile", "browsefile", "regexpfiles"]
def browsefile(file):
# browsefile are not available from command line, considere it as a localfile
......@@ -68,6 +69,15 @@ def urlfile(file):
raise argparse.ArgumentTypeError("URL '" + file + "' does not contain any file name!")
def inputfile(file):
# test the format
uri_object = urlparse(file)
# check the file
if uri_object.scheme == '':
return localfile(file)
else:
return urlfile(file)
def inputfiles(file):
# test the format
uri_object = urlparse(file)
# check the file
......@@ -87,11 +97,19 @@ def regexpfiles(files_pattern):
else:
folder, pattern = os.path.split(files_pattern)
except:
raise argparse.ArgumentTypeError("Pattern '" + file + "' is invalid!")
raise argparse.ArgumentTypeError("Regexp '" + files_pattern + "' is invalid!")
if not pattern:
raise argparse.ArgumentTypeError("Regexp '" + files_pattern + "' is invalid!")
if not os.path.exists(folder):
raise argparse.ArgumentTypeError("The folder '" + folder + "' doesn't exist!")
if not os.access(folder, os.R_OK):
raise argparse.ArgumentTypeError("You do not have permission to read '" + folder + "'!")
nb_files = 0
for item in sorted(os.listdir(folder)):
if os.path.isfile(os.path.join(folder, item)) and fnmatch.fnmatch(item, pattern):
nb_files += 1
if nb_files == 0:
raise argparse.ArgumentTypeError("0 file selected by the regexp!")
return files_pattern
def create_test_function(itype):
......@@ -796,7 +814,7 @@ class InputFile(StrParameter, AbstractInputFile):
if not is_uri and not is_local and self.type.__name__ == "inputfile" or self.type.__name__ == "browsefile":
jflow_config_reader = JFlowConfigReader()
new_path = os.path.join(jflow_config_reader.get_tmp_directory(), input)
if is_local: new_path = input
if is_local: new_path = localfile(input)
self.check(new_path)
return new_path
......@@ -833,12 +851,16 @@ class InputFileList(ParameterList, AbstractInputFile):
def __init__(self, name, help, file_format="any", default=None, type="localfile", choices=None,
required=False, flag=None, group="default", display_name=None, size_limit="0"):
if default == None: default = []
if default == None: default = []
if hasattr(type, '__call__'):
if type.__name__ == "inputfile":
type = inputfiles
type2test = type.__name__
else: type2test = type
if type2test not in INPUTFILE_TYPES + ["regexpfiles"]:
else:
if type == "inputfile":
type = "inputfiles"
type2test = type
if type2test not in INPUTFILES_TYPES:
raise ValueError("InputFile.__new__: wrong type provided: '"+type2test+"', this should be choosen between '"
+ "', '".join(INPUTFILE_TYPES)+"'")
......
......@@ -378,7 +378,11 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
} else if($(this).html() == "server regexp") { // if server regexp files
file_type = "regexpfiles" ;
} else {
file_type = "inputfile" ;
if( $("#"+tid).is("input") ){ // single file
file_type = "inputfile" ;
} else { // multiple files
file_type = "inputfiles" ;
}
}
// Validate
$("#"+tid).rules('add', {
......
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