def getZip(self, pzip): try: path_zip = archives_path() + "/" + pzip extension = "zip" filename = pzip.split("/")[1] file_size = os.path.getsize(path_zip) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_zip response.headers['Content-Disposition'] = 'attachement; filename=%s' % (filename) response.content_length = '%s' % (file_size) return None except: flash("Impossible to download the zip", "error") print_traceback() raise abort(403)
def getZip(self, pzip): try: path_zip = archives_path() + "/" + pzip extension = "zip" filename = pzip.split("/")[1] file_size = os.path.getsize(path_zip) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_zip response.headers[ 'Content-Disposition'] = 'attachement; filename=%s' % ( filename) response.content_length = '%s' % (file_size) return None except: flash("Impossible to download the zip", "error") print_traceback() raise abort(403)
def public_link(self, sha1, *args, **kw): #get the measurements selected id m_id = kw.get('m_id', None) f = DBSession.query(Files_up).filter(Files_up.sha1 == sha1).first() #if used with BAM_visualisation if f is None: try: tmp = sha1.split('.') sha1 = tmp[0] if len(tmp) == 2: f = DBSession.query(Files_up).filter(Files_up.sha1 == sha1).first() elif len(tmp) == 3: f_bam = DBSession.query(Files_up).filter(Files_up.sha1 == sha1).first() fullname = f_bam.filename name_tmp = fullname.split('.') name = name_tmp[0] f = DBSession.query(Files_up).filter(Files_up.filename == name + ".bam.bai").first() if f is None: flash("Sorry, your URL seems to be wrong. File corresponding to sha1 : " + str(sha1) + " and m_id : " + str(m_id) + " does not exist.", "error") raise abort(403) except: flash("Sorry, this file is not referenced into BioRepo.", "error") raise abort(403) list_meas = f.measurements for m in list_meas: if len(list_meas) == 1: if m.status_type: path_fu = f.path + "/" + f.sha1 extension = f.extension filename = f.filename file_size = os.path.getsize(path_fu) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_fu response.headers['Content-Disposition'] = 'attachement; filename=%s' % (filename) response.content_length = '%s' % (file_size) return None else: flash("Sorry, this file is not allowed to be extracted out of BioRepo.", "error") raise abort(403) #/!\lil hack : the same file can be used by several (or same) user in public AND private, and for this case it's tested in helpers.py else: meas = DBSession.query(Measurements).filter(Measurements.id == m_id).first() list_fus = meas.fus if len(list_fus) == 1 and meas.status_type: for other_f in list_fus: sha1 = other_f.sha1 path_fu = other_f.path + "/" + sha1 extension = other_f.extension filename = other_f.filename file_size = os.path.getsize(path_fu) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_fu response.headers['Content-Disposition'] = 'attachement; filename=%s' % (filename) response.content_length = '%s' % (file_size) return None elif not meas.status_type: flash("Sorry, this file is not allowed to be extracted out of BioRepo.", "error") raise abort(403) else: flash("Problem with the attached file", "error") raise abort(403)
def public_link(self, sha1, *args, **kw): #get the measurements selected id m_id = kw.get('m_id', None) f = DBSession.query(Files_up).filter(Files_up.sha1 == sha1).first() #if used with BAM_visualisation if f is None: try: tmp = sha1.split('.') sha1 = tmp[0] if len(tmp) == 2: f = DBSession.query(Files_up).filter( Files_up.sha1 == sha1).first() elif len(tmp) == 3: f_bam = DBSession.query(Files_up).filter( Files_up.sha1 == sha1).first() fullname = f_bam.filename name_tmp = fullname.split('.') name = name_tmp[0] f = DBSession.query(Files_up).filter( Files_up.filename == name + ".bam.bai").first() if f is None: flash( "Sorry, your URL seems to be wrong. File corresponding to sha1 : " + str(sha1) + " and m_id : " + str(m_id) + " does not exist.", "error") raise abort(403) except: flash("Sorry, this file is not referenced into BioRepo.", "error") raise abort(403) list_meas = f.measurements for m in list_meas: if len(list_meas) == 1: if m.status_type: path_fu = f.path + "/" + f.sha1 extension = f.extension filename = f.filename file_size = os.path.getsize(path_fu) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_fu response.headers[ 'Content-Disposition'] = 'attachement; filename=%s' % ( filename) response.content_length = '%s' % (file_size) return None else: flash( "Sorry, this file is not allowed to be extracted out of BioRepo.", "error") raise abort(403) #/!\lil hack : the same file can be used by several (or same) user in public AND private, and for this case it's tested in helpers.py else: meas = DBSession.query(Measurements).filter( Measurements.id == m_id).first() list_fus = meas.fus if len(list_fus) == 1 and meas.status_type: for other_f in list_fus: sha1 = other_f.sha1 path_fu = other_f.path + "/" + sha1 extension = other_f.extension filename = other_f.filename file_size = os.path.getsize(path_fu) if dico_mimetypes.has_key(extension): response.content_type = dico_mimetypes[extension] else: response.content_type = 'text/plain' response.headers['X-Sendfile'] = path_fu response.headers[ 'Content-Disposition'] = 'attachement; filename=%s' % ( filename) response.content_length = '%s' % (file_size) return None elif not meas.status_type: flash( "Sorry, this file is not allowed to be extracted out of BioRepo.", "error") raise abort(403) else: flash("Problem with the attached file", "error") raise abort(403)