Esempio n. 1
0
def api_export():
    export_format = request.args.get('format')
    project = project_get_or_create()
    now = datetime.now()
    completion_dir = project.config['output_dir']
    export_dirname = now.strftime('%Y-%m-%d-%H-%M-%S')
    with get_temp_dir() as temp_dir:
        export_dirpath = os.path.join(temp_dir, export_dirname)
        project.converter.convert(completion_dir, export_dirpath, format=export_format)
        shutil.make_archive(export_dirpath, 'zip', export_dirpath)
        export_zipfile = export_dirpath + '.zip'
        response = send_file(export_zipfile, as_attachment=True)
        response.headers['filename'] = os.path.basename(export_zipfile)
        project.analytics.send(getframeinfo(currentframe()).function)
        return response
Esempio n. 2
0
 def _read_tasks(self, num_tasks=None):
     request_files = {}
     for filename in self.filelist:
         request_files[filename] = open(self.project.upload_dir + '/' +
                                        filename,
                                        mode='rb')
     with get_temp_dir() as tmpdir:
         files = aggregate_files(request_files, tmpdir,
                                 self.project.upload_dir)
         tasks, found_formats, data_keys = aggregate_tasks(
             files, self.project, self.selected_formats,
             self.files_as_tasks_list['selected'], num_tasks)
         for file in files.values():
             try:
                 file.close()
             except:
                 pass
     return tasks, found_formats, data_keys