def get_files_by_dir(dirname): ret = [] with make_session() as session: files = File.query.filter(File.fparent == dirname).all() for f in files: ret.append(f.to_json()) return ret
def get_file_info_by_name(dirname, filename): ret = {} with make_session() as session: file = File.query.filter(and_(File.fparent == dirname, File.fname == filename)).first() if file != None: ret = file.to_json() return ret
def create_file(**params): model = File() fname = model.fname = params.pop('fname') fparent = model.fparent = params.pop('fparent') model.ftype = params.pop('ftype') model.fmode = params.pop('fmode') model.fcomment = params.pop('fcomment') model.flink = params.pop('flink') model.uid = params.pop('uid') model.gid = params.pop('gid') with make_session() as session: session.add(model) obj = File.query.filter(File.fname == fname).filter( File.fparent == fparent).first() return obj.to_json()
def insert_file_md5(fname, md5): item = FileMD5() item.fname = fname item.md5 = md5 with make_session() as session: session.add(item)
def move_file(fid, new_parent): file = get_file_by_id(fid) file.fparent = new_parent with make_session() as session: session.add(file)
def rename(fid, new_name): file = File.query.filter(File.id == fid).first() file.fname = new_name file.fmtime = datetime.datetime.now() with make_session() as session: session.add(file)
def delete_regular_file(fid): with make_session() as session: item = session.query(File).filter(File.id == fid).first() session.delete(item)
def delete_dir_file(fid): with make_session() as session: _delete_dir(fid, session)
def add_group(gname, gcomment): g = _make_group(gname, gcomment) with make_session() as session: session.add(g) session.commit() return g
def add_user(group, uname, usex, uemail, upwd, ucomment='no comment'): u = make_user(uname, usex, uemail, upwd, ucomment) u.group = [group] with make_session() as session: session.add(u) session.commit()