Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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()
Exemple #4
0
def insert_file_md5(fname, md5):
    item = FileMD5()
    item.fname = fname
    item.md5 = md5
    with make_session() as session:
        session.add(item)
Exemple #5
0
def move_file(fid, new_parent):
    file = get_file_by_id(fid)
    file.fparent = new_parent
    with make_session() as session:
        session.add(file)
Exemple #6
0
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)
Exemple #7
0
def delete_regular_file(fid):
    with make_session() as session:
        item = session.query(File).filter(File.id == fid).first()
        session.delete(item)
Exemple #8
0
def delete_dir_file(fid):
    with make_session() as session:
        _delete_dir(fid, session)
Exemple #9
0
def add_group(gname, gcomment):
    g = _make_group(gname, gcomment)
    with make_session() as session:
        session.add(g)
        session.commit()
    return g
Exemple #10
0
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()