Exemple #1
0
def get_parameters(kwarg):
    kwarg['quantum'] = get_size(kwarg.get('quantum', 0))
    kwarg['perturb_period'] = kwarg.get('perturb', 0) or \
        kwarg.get('perturb_period', 0)
    limit = kwarg['limit'] = kwarg.get('limit', 0) or \
        kwarg.get('redflowlimit', 0)
    qth_min = kwarg.get('min', 0)
    qth_max = kwarg.get('max', 0)
    avpkt = kwarg.get('avpkt', 1000)
    probability = kwarg.get('probability', 0.02)
    ecn = kwarg.get('ecn', False)
    harddrop = kwarg.get('harddrop', False)
    kwarg['flags'] = kwarg.get('flags', 0)
    if ecn:
        kwarg['flags'] |= TC_RED_ECN
    if harddrop:
        kwarg['flags'] |= TC_RED_HARDDROP
    if kwarg.get('redflowlimit'):
        qth_max = qth_max or limit / 4
        qth_min = qth_min or qth_max / 3
        kwarg['burst'] = kwarg['burst'] or \
            (2 * qth_min + qth_max) / (3 * avpkt)
        assert limit > qth_max
        assert qth_max > qth_min
        kwarg['qth_min'] = qth_min
        kwarg['qth_max'] = qth_max
        kwarg['Wlog'] = red_eval_ewma(qth_min, kwarg['burst'], avpkt)
        kwarg['Plog'] = red_eval_P(qth_min, qth_max, probability)
        assert kwarg['Wlog'] >= 0
        assert kwarg['Plog'] >= 0
        kwarg['max_P'] = int(probability * pow(2, 23))

    return kwarg
Exemple #2
0
 def printUsersFileSpace(self):
     users = self.db.getUsersByUName()
     for row in users:
         up = os.path.join(self.path, row[1])
         try:
             self.view.appendText(row[1] + " " + str(common.get_size(up)/1024) + "KB")
         except:
             pass
Exemple #3
0
def get_parameters(kwarg):
    # The code is ported from iproute2
    avpkt = 1000
    probability = 0.02
    opt = {'limit': kwarg['limit'],  # required
           'qth_min': kwarg.get('min', 0),
           'qth_max': kwarg.get('max', 0),
           'Wlog': 0,
           'Plog': 0,
           'Scell_log': 0,
           'flags': 1 if kwarg.get('ecn') else 0}

    rate = get_rate(kwarg['bandwith'])  # required
    burst = kwarg.get('burst', 0)
    avpkt = get_size(kwarg.get('avpkt', 1000))
    probability = kwarg.get('probability', 0.02)

    if not opt['qth_max']:
        opt['qth_max'] = opt['limit'] // 4
    if not opt['qth_min']:
        opt['qth_min'] = opt['qth_max'] // 3
    if not burst:
        burst = (2 * opt['qth_min'] + opt['qth_max']) // 3

    if opt['qth_max'] > opt['limit']:
        raise Exception('max is larger than limit')
    if opt['qth_min'] >= opt['qth_max']:
        raise Exception('min is not smaller than max')

    # Wlog
    opt['Wlog'] = red_eval_ewma(opt['qth_min']*avpkt,
                                burst,
                                avpkt)
    if opt['Wlog'] < 0:
        raise Exception('failed to calculate EWMA')
    elif opt['Wlog'] > 10:
        logging.warning('choke: burst %s seems to be too large' % burst)
    # Plog
    opt['Plog'] = red_eval_P(opt['qth_min']*avpkt,
                             opt['qth_max']*avpkt,
                             probability)
    if opt['Plog'] < 0:
        raise Exception('choke: failed to calculate probability')
    # Scell_log, stab
    opt['Scell_log'], stab = red_eval_idle_damping(opt['Wlog'], avpkt, rate)
    if opt['Scell_log'] < 0:
        raise Exception('choke: failed to calculate idle damping table')

    return {'attrs': [['TCA_CHOKE_PARMS', opt],
                      ['TCA_CHOKE_STAB', stab],
                      ['TCA_CHOKE_MAX_P', int(probability * pow(2, 32))]]}
Exemple #4
0
 def clean_cache(self, sysdaemon):
     totalsize = 0
     self.get_cache(None)
     for key in self.cache_dic.keys():
         for f in self.cache_dic[key]:
             totalsize += common.get_size(f)
             if os.path.isdir(f):
                 sysdaemon.info_for_mainpage_clean(f)
                 shutil.rmtree(f)
             else:
                 sysdaemon.info_for_mainpage_clean(f)
                 os.remove(f)
     size_str = common.confirm_filesize_unit(totalsize)
     sysdaemon.mainpage_clean(size_str)
Exemple #5
0
 def clean_cache(self, sysdaemon):
     totalsize = 0
     self.get_cache(None)
     for key in self.cache_dic.keys():
         for f in self.cache_dic[key]:
             totalsize += common.get_size(f)
             if os.path.isdir(f):
                 sysdaemon.info_for_mainpage_clean(f)
                 shutil.rmtree(f)
             else:
                 sysdaemon.info_for_mainpage_clean(f)
                 os.remove(f)
     size_str = common.confirm_filesize_unit(totalsize)
     sysdaemon.mainpage_clean(size_str)
Exemple #6
0
    def get_cache(self, sesdaemon):
        flag = False
        totalsize = 0
        homedir = ''
        cache_obj = cacheclean.CacheClean()
        if sesdaemon:
            homedir = common.return_homedir_sesdaemon()
        else:
            homedir = return_homedir_sysdaemon()

        self.cache_dic = {'apt':[], 'softwarecenter':[], 'thumbnail':[]}
        aptpath = "/var/cache/apt/archives"
        temp_apt_list = cache_obj.scan_apt_cache(aptpath)
        if sesdaemon:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
        softwarecenterpath = "%s/.cache/software-center" % homedir
        temp_softwarecenter_list = cache_obj.public_scan_cache(softwarecenterpath)
        if sesdaemon:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
        thumbnailspath = "%s/.cache/thumbnails" % homedir
        try:
            temp_thumbnails_list = cache_obj.public_scan_cache(thumbnailspath)
        except Exception, e:
            print e
Exemple #7
0
    def get_cache(self, sesdaemon):
        flag = False
        totalsize = 0
        homedir = ''
        cache_obj = cacheclean.CacheClean()
        if sesdaemon:
            homedir = common.return_homedir_sesdaemon()
        else:
            homedir = return_homedir_sysdaemon()

        self.cache_dic = {'apt':[], 'softwarecenter':[], 'thumbnail':[]}
        aptpath = "/var/cache/apt/archives"
        temp_apt_list = cache_obj.scan_apt_cache(aptpath)
        if sesdaemon:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
        softwarecenterpath = "%s/.cache/software-center" % homedir
        temp_softwarecenter_list = cache_obj.public_scan_cache(softwarecenterpath)
        if sesdaemon:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
        thumbnailspath = "%s/.cache/thumbnails" % homedir
        try:
            temp_thumbnails_list = cache_obj.public_scan_cache(thumbnailspath)
        except Exception, e:
            print e
Exemple #8
0
 def select_file(self):
     self.filename = filedialog.askopenfilename()
     if self.filename == '':
         return
     if self.sel_list:
         name = self.filename
         size = common.get_size(name)
         self.filesize = os.path.getsize(name)
         info = {'name': os.path.basename(name), 'size': self.filesize}
         self.show(f'send file \'{name}\'\nsize: \'{size}\'\n')
         if name.endswith(('jpg', 'png', 'jpeg', 'bmp', 'gif')):
             self.show(name, 'img')
             self.send(f'IMG::{info}::{self.sel_list}')
             with open(self.filename, 'rb') as f:
                 for data in f:
                     s.send(data)
         elif name != '':
             # self.text_input.delete(1.0, 'end')
             self.send(f'FILE::{info}::{self.sel_list}')
     else:
         self.show('请至少选择一个用户...\n')
Exemple #9
0
 def load_pcs_nodes(self, nodes):
     groups = find_red(nodes)
     total, red = get_size(groups)
     self.ui.lblStatus.setText(
         u'共%s重复文件,去重可节省%s' % (fmt_size(total), fmt_size(red)))
     sizesum = lambda g: sum([f['size'] for f in g])
     groups.sort(lambda a, b: cmp(sizesum(a), sizesum(b)), reverse=True)
     self.ui.treeDir.clear()
     self.path_d = {}
     self.groups = []
     for g in groups:
         f = g[0]
         diritem = eqt.SortableTreeItem([self.pcs.basename(f['path'])])
         grp = []
         self.groups.append(grp)
         for f in g:
             item = eqt.SortableTreeItem([f['path']], f)
             item.setCheckState(0, QtCore.Qt.Unchecked)
             self.path_d[f['path']] = item
             diritem.addChild(item)
             grp.append((f, item))
         self.ui.treeDir.addTopLevelItem(diritem)
         diritem.setExpanded(True)
Exemple #10
0
 def load_pcs_nodes(self, nodes):
     groups = find_red(nodes)
     total, red = get_size(groups)
     self.ui.lblStatus.setText(u'共%s重复文件,去重可节省%s' %
                               (fmt_size(total), fmt_size(red)))
     sizesum = lambda g: sum([f['size'] for f in g])
     groups.sort(lambda a, b: cmp(sizesum(a), sizesum(b)), reverse=True)
     self.ui.treeDir.clear()
     self.path_d = {}
     self.groups = []
     for g in groups:
         f = g[0]
         diritem = eqt.SortableTreeItem([self.pcs.basename(f['path'])])
         grp = []
         self.groups.append(grp)
         for f in g:
             item = eqt.SortableTreeItem([f['path']], f)
             item.setCheckState(0, QtCore.Qt.Unchecked)
             self.path_d[f['path']] = item
             diritem.addChild(item)
             grp.append((f, item))
         self.ui.treeDir.addTopLevelItem(diritem)
         diritem.setExpanded(True)
Exemple #11
0
class MainPage():
    def __init__(self):
        pass

    def get_cache(self, sesdaemon):
        flag = False
        totalsize = 0
        homedir = ''
        cache_obj = cacheclean.CacheClean()
        if sesdaemon:
            homedir = common.return_homedir_sesdaemon()
        else:
            homedir = return_homedir_sysdaemon()

        self.cache_dic = {'apt':[], 'softwarecenter':[], 'thumbnail':[]}
        aptpath = "/var/cache/apt/archives"
        temp_apt_list = cache_obj.scan_apt_cache(aptpath)
        if sesdaemon:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_apt_list:
                self.cache_dic['apt'].append(one)
        softwarecenterpath = "%s/.cache/software-center" % homedir
        temp_softwarecenter_list = cache_obj.public_scan_cache(softwarecenterpath)
        if sesdaemon:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_softwarecenter_list:
                self.cache_dic['softwarecenter'].append(one)
        thumbnailspath = "%s/.cache/thumbnails" % homedir
        try:
            temp_thumbnails_list = cache_obj.public_scan_cache(thumbnailspath)
        except Exception, e:
            print e
        if sesdaemon:
            for one in temp_thumbnails_list:
                self.cache_dic['thumbnail'].append(one)
                totalsize += common.get_size(one)
                sesdaemon.check_scan_garbage_process(one)
        else:
            for one in temp_thumbnails_list:
                self.cache_dic['thumbnail'].append(one)
        if sesdaemon:
            for key in self.cache_dic.keys():
                if self.cache_dic[key]:
                    flag = True
                    break
            if flag:
                sesdaemon.scan_complete('True')
            else:
                sesdaemon.scan_complete('False')
            size_str = common.confirm_filesize_unit(totalsize)
            sesdaemon.check_scan_complete(size_str)
        else:
            pass
Exemple #12
0
 def printTotalFileSpace(self):
     up = os.path.join(self.path)
     self.view.appendText("Total file space used by all users: " + str(common.get_size(up)/1024) + "KB")
Exemple #13
0
 if not os.path.exists(CACHE):
         CACHE     =  xbmc.translatePath(os.path.join('special://home/temp',''))
 if not os.path.exists(PACKAGES):
         os.makedirs(PACKAGES)
 
 if not CLEAR_CACHE_SIZE == "0":
         if CLEAR_CACHE_SIZE == "1":
                 CACHE_TO_CLEAR = 25000000
         if CLEAR_CACHE_SIZE == "2":
                 CACHE_TO_CLEAR = 50000000
         if CLEAR_CACHE_SIZE == "3":
                 CACHE_TO_CLEAR = 75000000
         if CLEAR_CACHE_SIZE == "4":
                 CACHE_TO_CLEAR = 100000000
 
         CACHE_SIZE_BYTE    = Common.get_size(CACHE)
 
         if  CACHE_SIZE_BYTE > CACHE_TO_CLEAR:
                 maintenance.AUTO_CLEAR_CACHE_MB()
 
 if not CLEAR_PACKAGES_SIZE == "0":
         if CLEAR_PACKAGES_SIZE == "1":
                 PACKAGES_TO_CLEAR = 25000000
         if CLEAR_PACKAGES_SIZE == "2":
                 PACKAGES_TO_CLEAR = 50000000
         if CLEAR_PACKAGES_SIZE == "3":
                 PACKAGES_TO_CLEAR = 75000000
         if CLEAR_PACKAGES_SIZE == "4":
                 PACKAGES_TO_CLEAR = 100000000
 
         PACKAGES_SIZE_BYTE    = Common.get_size(PACKAGES)