예제 #1
0
파일: files.py 프로젝트: vanbac91/rumpanel
def getitem(path):
    if not os.path.exists(path) and not os.path.islink(path):
        return False
    name = os.path.basename(path)
    basepath = os.path.dirname(path)
    stat = os.lstat(path)
    mode = stat.st_mode
    try:
        uname = pwd.getpwuid(stat.st_uid).pw_name
    except:
        uname = ''
    try:
        gname = grp.getgrgid(stat.st_gid).gr_name
    except:
        gname = ''
    item = {
        'name': name,
        'isdir': S_ISDIR(mode),
        # 'ischr': S_ISCHR(mode),
        # 'isblk': S_ISBLK(mode),
        'isreg': S_ISREG(mode),
        # 'isfifo': S_ISFIFO(mode),
        'islnk': S_ISLNK(mode),
        # 'issock': S_ISSOCK(mode),
        'perms': oct(stat.st_mode & 0777),
        'uid': stat.st_uid,
        'gid': stat.st_gid,
        'uname': uname,
        'gname': gname,
        'size': b2h(stat.st_size),
        'atime': ftime(stat.st_atime),
        'mtime': ftime(stat.st_mtime),
        'ctime': ftime(stat.st_ctime),
    }
예제 #2
0
파일: files.py 프로젝트: vanbac91/rumpanel
def tlist():
    mounts = _getmounts()
    _inittrash(mounts)
    # gather informations in each mount point's trash
    items = []
    for mount in mounts:
        db = anydbm.open(os.path.join(mount, '.deleted_files', '.fileinfo'), 'c')
        for uuid, info in db.items():
            fields = info.split('\t')
            item = {
                'uuid': uuid,
                'name': fields[0],
                'path': fields[1],
                'time': ftime(float(fields[2])),
                'mount': mount
            }
            filepath = os.path.join(mount, '.deleted_files', uuid)
            if os.path.exists(filepath):
                stat = os.stat(filepath)
                item['isdir'] = S_ISDIR(stat.st_mode)
                item['isreg'] = S_ISREG(stat.st_mode)
                item['islnk'] = S_ISLNK(stat.st_mode)
            items.append(item)
        db.close()
    items.sort(lambda x, y: cmp(y['time'], x['time']))
    return items
예제 #3
0
파일: files.py 프로젝트: vanbac91/rumpanel
def titem(mount, uuid):
    # _inittrash()
    try:
        trashpath = os.path.join(mount, '.deleted_files')
        db = anydbm.open(os.path.join(trashpath, '.fileinfo'), 'c')
        info = db[uuid]
        db.close()
        fields = info.split('\t')
        info = {
            'uuid': uuid,
            'name': fields[0],
            'path': fields[1],
            'time': ftime(float(fields[2])),
            'mount': mount
        }
        info['originpath'] = os.path.join(trashpath, uuid)
        return info
    except:
        return False