def download_support_file(self, id, module, filename): """Download a support file. .. :quickref: Analysis; Download a support file. :param id: id of the analysis. :param module: name of the module. :param filename: name of the file to download. """ analysis = get_or_404(current_user.analyses, _id=id) filepath = os.path.join(fame_config.storage_path, 'support_files', module, str(analysis['_id']), secure_filename(filename)) if os.path.isfile(filepath): return file_download(filepath) else: # This code is here for compatibility # with older analyses filepath = os.path.join(fame_config.storage_path, 'support_files', str(analysis['_id']), secure_filename(filename)) if os.path.isfile(filepath): return file_download(filepath) else: abort(404)
def get_file(self, id, filehash): analysis = Analysis(get_or_404(current_user.analyses, _id=id)) for file_type in analysis['generated_files']: for filepath in analysis['generated_files'][file_type]: filepath = filepath.encode('utf-8') if filehash == md5(filepath).hexdigest(): return file_download(filehash) filepath = analysis._file['filepath'].encode('utf-8') if filehash == md5(filepath).hexdigest(): return file_download(analysis.get_main_file()) return abort(404)
def download(self, id): """Download the file with `id`. .. :quickref: File; Download a file :param id: id of the file to download. """ f = File(get_or_404(current_user.files, _id=id)) return file_download(f['filepath'])
def download_support_file(self, id, filename): """Download a support file. .. :quickref: Analysis; Download a support file. :param id: id of the analysis. :param filename: name of the file to download. """ analysis = get_or_404(current_user.analyses, _id=id) filepath = os.path.join(fame_config.storage_path, 'support_files', str(analysis['_id']), secure_filename(filename)) return file_download(filepath)
def download(self): # First, create a zip file with the modules path = os.path.join(tempdir(), 'modules.zip') with ZipFile(path, 'w') as zipf: for root, dirs, files in os.walk(MODULES_ROOT): for filename in files: # Ignore pyc files if not filename.endswith('.pyc'): filepath = os.path.join(root, filename) zipf.write(filepath, os.path.relpath(filepath, MODULES_ROOT)) # Return the zip file response = file_download(path) # Delete it os.remove(path) return response