示例#1
0
    def list(self):
        """查看用户
        """
        params = self.req_params()
        page_no = int(params.pn) if params.pn else 1
        total = self.db.query_row("""select count(user.id) from user, quota where
                user.id=quota.user_id and user.level='%d'""" % (user_normal));
        pg = page.Page(total, page_no, user_page_size)

        user_li = self.db.query_all("""select user.id as id, user.name as name,
                user.email as email, user.state as state,
                user.create_time as create_time,
                user.last_login_time as last_login_time,
                quota.total as total, quota.used as used from user,
                quota where user.id=quota.user_id and user.level='%d' limit %d, %d""" %
                (user_normal, (pg.current - 1) * user_page_size, user_page_size))
        if len(user_li) > 0:
            for u in user_li:
                u_idx = user_li.index(u)
                user_li[u_idx]['file_num'] = self.db.query_row("select count(*) from file_system where file_system.user_id='%s'" % (u['id']))
                user_li[u_idx]['total'] = fileutil.friend_size(user_li[u_idx]['total'])
                user_li[u_idx]['used'] = fileutil.friend_size(user_li[u_idx]['used'])
                user_li[u_idx]['state'] = user_state_name[int(user_li[u_idx]['state'])]

        self.db.commit()
        self.resp = {'errno': errno_ok, 'list': user_li}
        self.resp.update(pg.__dict__)
        return self.json()
示例#2
0
    def index(self):
        userid = auth.decode_token(web.ctx.session.token)['userid']
        quota_li = self.db.query_all("select * from quota where `user_id`='%s'" % (userid))
        self.db.commit()
        if 0 == len(quota_li):
            self.resp = {'errno': errno_db, 'msg': '暂无数据'}
            return self.json()

        self.resp = {'errno': errno_ok, 'total':
                fileutil.friend_size(quota_li[0]['total']), 'used':
                fileutil.friend_size(quota_li[0]['used'])}
        return self.json()
示例#3
0
        try:
            files = os.listdir(filepath)
        except OSError, e:
            self.resp = {'errno': errno_client, 'msg': '路径不存在'}
            return self.json()

        self.resp = {}
        self.resp['errno'] = errno_ok
        self.resp['label'] = '所有文件'
        self.resp['path'] = path
        self.resp['list'] = []
        for filename in files:
            file_info = {}
            file_info['server_filename'] = filename
            fpath = fileutil.join_path(filepath, filename)
            file_info['size'] = fileutil.friend_size(os.path.getsize(fpath))
            file_info['path'] = fileutil.join_path(path, filename)
            file_info['isdir'] = 1 if os.path.isdir(fpath) else 0
            file_info['server_ctime'] = timeutil.time_sec_to_str(os.path.getctime(fpath), timeutil.common_date)
            file_info['server_mtime'] = timeutil.time_sec_to_str(os.path.getmtime(fpath), timeutil.common_date)
            if file_info['isdir']:
                file_info['dir_empty'] = 0 if os.listdir(fpath) else 1
            file_info['fs_id'] = 0
            file_info['category'] = 0
            self.resp['list'].append(file_info)

        return self.json()

    def remove(self):
        """删除文件(非目录)
        """