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

Fix bug with URL file.

Add regexp files in input file selection on GUI and command line.
parent b3664434
......@@ -72,7 +72,11 @@ def inputfile(file):
uri_object = urlparse(file)
# check the file
if uri_object.scheme == '':
return localfile(file)
try:
regexpfiles(file)
return file
except:
return localfile(file)
else:
return urlfile(file)
......@@ -103,12 +107,23 @@ def create_test_function(itype):
# first test the size of the file
uri_object = urlparse(ifile)
if uri_object.scheme == '':
isize = os.path.getsize(ifile)
isize = 0
try:
regexpfiles(ifile)
if ':' in returned_value:
folder, pattern = returned_value.rsplit(':')
else:
folder, pattern = os.path.split(returned_value)
for item in os.listdir(folder):
if os.path.isfile(os.path.join(folder, item)) and fnmatch.fnmatch(item, pattern):
isize += os.path.getsize(os.path.abspath(os.path.join(folder, item)))
except:
isize = os.path.getsize(ifile)
if isize > int(get_nb_octet(csizel)):
raise argparse.ArgumentTypeError("File '" + ifile + "' (size=" + get_octet_string_representation(isize) + ") exceeds size limits: " + csizel + ".")
else:
try:
opener = urllib2.urlopen(file)
opener = urllib2.urlopen(ifile)
metadata = opener.info()
isize = int(metadata.getheaders("Content-Length")[0])
if isize > int(get_nb_octet(csizel)):
......@@ -856,40 +871,28 @@ class InputFileList(ParameterList, AbstractInputFile):
def prepare_input_files(self, inputs):
path2test = _copy.deepcopy(inputs)
new_vals = list()
if not path2test.__class__.__name__ == "list":
path2test = [path2test]
# handle regexp files
new_vals = list()
if self.type.__name__ == "regexpfiles":
for files_pattern in path2test:
if ':' in files_pattern:
folder, pattern = files_pattern.rsplit(':')
else:
folder, pattern = os.path.split(files_pattern)
for item in os.listdir(folder):
if os.path.isfile(os.path.join(folder, item)) and fnmatch.fnmatch(item, pattern):
new_vals.append( os.path.abspath(os.path.join(folder, item)) )
path2test = new_vals
new_vals, done = [], []
# handle url inputs
for path in path2test:
new_url, is_uri = self._download_urlfile(path)
if is_uri:
if is_uri: # handle url inputs
new_vals.append(new_url)
done.append(path)
for d in done: path2test.remove(d)
done = []
# handle localfile
for path in path2test:
if os.path.isfile(path):
new_vals.append(path)
done.append(path)
for d in done: path2test.remove(d)
# handle upload inputs
if self.type.__name__ == "inputfile" or self.type.__name__ == "browsefile":
for path in path2test:
jflow_config_reader = JFlowConfigReader()
new_vals.append(os.path.join(jflow_config_reader.get_tmp_directory(), path))
elif os.path.isfile(path): # handle localfile
new_vals.append(localfile(path))
else:
try: # handle regexp files
regexpfiles(path)
if ':' in path:
folder, pattern = path.rsplit(':')
else:
folder, pattern = os.path.split(path)
for item in sorted(os.listdir(folder)):
if os.path.isfile(os.path.join(folder, item)) and fnmatch.fnmatch(item, pattern):
new_vals.append( localfile(os.path.join(folder, item)) )
except: # handle upload inputs
jflow_config_reader = JFlowConfigReader()
new_vals.append(os.path.join(jflow_config_reader.get_tmp_directory(), path))
# now that all files are downloaded and ok, check the format
for cfile in new_vals:
self.check(cfile)
......
......@@ -348,31 +348,27 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
if ($("#"+tid).data("data2upload")) {
$("#"+tid).removeData( "data2upload" );
}
if ($(this).html() == "url") {
$("#"+tid).rules('add', {
remote: {
url: $this.options.serverURL + '/validate_field?callback=?',
type: "post",
data: {
type: "urlfile"+SIZE_LIMIT_SPLITER+size,
action: $("#"+tid).rules()["mparam"].action
}
}
});
// if server file
} else {
$("#"+tid).rules('add', {
remote: {
url: $this.options.serverURL + '/validate_field?callback=?',
type: "post",
data: {
type: "inputfile"+SIZE_LIMIT_SPLITER+size,
action: $("#"+tid).rules()["mparam"].action
}
}
});
}
}
// File type
var file_type = null ;
if ($(this).html() == "url") { // if url file
file_type = "urlfile" ;
} else if($(this).html() == "server regexp") { // if server regexp files
file_type = "regexpfiles" ;
} else {
file_type = "inputfile" ;
}
// Validate
$("#"+tid).rules('add', {
remote: {
url: $this.options.serverURL + '/validate_field?callback=?',
type: "post",
data: {
type: file_type+SIZE_LIMIT_SPLITER+size,
action: $("#"+tid).rules()["mparam"].action
}
}
});
}
});
$("[id^=urlfile_btn_]").click(function(){
var parts = $(this).attr("id").split("_"),
......@@ -562,6 +558,7 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
' <span class="caret"></span>',
' </button>',
' <ul class="dropdown-menu" role="menu">',
' <li><a class="inputfile_${param.name}" href="#">server regexp</a></li>',
' <li><a class="inputfile_${param.name}" href="#">server file</a></li>',
' <li><a class="inputfile_${param.name}" href="#">local file</a></li>',
' <li><a class="inputfile_${param.name}" href="#">url</a></li>',
......
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