def _get_ufile(file_indicator = None): ufile = UFile.query.filter(UFile.url == file_indicator).first() if not ufile: ufile = None if ufile is not None: # test whether file exists if not funcs.f_exists(ufile.filename): db_session.delete(ufile) db_session.commit() abort(404) else: if not funcs.f_exists(file_indicator): abort(404) ufile = UFile( name = funcs.get_name_from_filename(file_indicator), url = file_indicator, filename = file_indicator, filesize = funcs.get_file_size(file_indicator), mimetype = funcs.get_file_mimetype(file_indicator), created = datetime.utcnow() ) db_session.add(ufile) db_session.commit() #if not r: # logging.error('Failed to commit new record: %r' % ufile) # abort(404) return ufile
def gen_file_item(realfile, o_filename): pos = o_filename.rfind(".") if pos != -1: ufile_name = o_filename[:pos] else: ufile_name = o_filename d_fn = os.path.basename(realfile) ufile = UFile( name=ufile_name, url=d_fn, filename=d_fn, filesize=funcs.get_file_size(d_fn), mimetype=funcs.get_file_mimetype(d_fn), created=datetime.utcnow(), ) db_session.add(ufile) db_session.commit() return d_fn