File size: 1,843 Bytes
17e971c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# coding: utf-8
# -------------------------------------------------------------------
# 宝塔Linux面板
# -------------------------------------------------------------------
# Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
# -------------------------------------------------------------------
# Author: cjxin <cjxin@bt.cn>
# -------------------------------------------------------------------
# 面板获取列表公共库
# ------------------------------

import os,sys,time,json,db,re
import public


class dataBase:

    quota_conf = os.path.join(public.get_panel_path(), "config/quota_list.json")

    def __init__(self):
        pass

    """
    @name 获取配额数据列表
    """
    def get_quota_list(self):
        quota_dict = {}
        try:
            quota_dict = json.loads(public.readFile(self.quota_conf))
        except:
            pass
        return quota_dict


    """
    @name 批量获取所有容量配额
    """
    def get_all_quota(self,paths = []):
        n_paths = []
        confs = self.get_quota_list()


        for path in paths:
            if path in n_paths: continue
            if not path in confs: continue
            n_paths.append(path.strip())

        res = public.get_size_total(n_paths)

        n_data = {}
        for val in n_paths:
            n_data[val] = {"used":0,"size":0,"quota_push":{"size":0,"used":0},"quota_storage":{"size":0,"used":0}}
            if val in confs.keys():
                n_data[val] = confs[val]

            n_data[val]['used'] = -1
            for key in res.keys():
                if key != val: continue

                n_data[val]['used'] = res[val]
                n_data[val]['quota_storage']['used'] = res[val]
                n_data[val]['quota_push']['used'] = res[val]

        print(n_data)
        return n_data