def _prepare_job(request, candidates): """ Creates a temporary directory, move uploaded files there and select the job file by looking at the candidate names. :returns: full path of the job_file """ temp_dir = tempfile.mkdtemp() inifiles = [] arch = request.FILES.get('archive') if arch is None: # move each file to a new temp dir, using the upload file names, # not the temporary ones for each_file in request.FILES.values(): new_path = os.path.join(temp_dir, each_file.name) shutil.move(each_file.temporary_file_path(), new_path) if each_file.name in candidates: inifiles.append(new_path) return inifiles # else extract the files from the archive into temp_dir return readinput.extract_from_zip(arch, candidates)
def store(request_files, ini, calc_id): """ Store the uploaded files in calc_dir and select the job file by looking at the .ini extension. :returns: full path of the ini file """ tmp = config.directory.custom_tmp or tempfile.mkdtemp() calc_dir = os.path.join(tmp, 'calc_%d' % calc_id) os.mkdir(calc_dir) arch = request_files.get('archive') if arch is None: # move each file to calc_dir using the upload file names inifiles = [] for each_file in sorted(request_files.values()): new_path = os.path.join(calc_dir, each_file.name) shutil.move(each_file.temporary_file_path(), new_path) if each_file.name.endswith(ini): inifiles.append(new_path) else: # extract the files from the archive into calc_dir inifiles = readinput.extract_from_zip(arch, ini, calc_dir) if not inifiles: raise NotFound('There are no %s files in the archive' % ini) return inifiles[0]