~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to backends/youker-assistant-daemon/src/cleaner/cacheclean.py

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
from common import get_dir_size
3
 
from common import confirm_filesize_unit
4
 
 
5
 
 
6
 
class CacheClean():
7
 
    def __init__(self):
8
 
        pass
9
 
 
10
 
    def get_apt_cache(self):
11
 
        apt_cache = '/var/cache/apt/archives'
12
 
        #aptcachelist = map(lambda filename: '%s/%s<2_2>%s' % (apt_cache, filename, str(os.path.getsize('%s/%s' % (apt_cache, filename)))), filter(lambda filestr: filestr.endswith('deb'), os.listdir(apt_cache)))
13
 
        aptcachelist = ['%s/%s<2_2>%s' % (apt_cache,filename, confirm_filesize_unit(os.path.getsize('%s/%s' % (apt_cache, filename)))) for filename in os.listdir(apt_cache) if filename.endswith('deb')]
14
 
        return aptcachelist
15
 
 
16
 
    def scan_apt_cache(self, path):
17
 
        aptcache_list = []
18
 
        if os.path.exists(path):
19
 
            aptcache_list = ['%s/%s' % (path, filename) for filename in os.listdir(path) if filename.endswith('deb')]
20
 
 
21
 
        return aptcache_list
22
 
 
23
 
    def public_scan_cache(self, path):
24
 
        publiccache_list = []
25
 
        if os.path.exists(path):
26
 
            publiccache_list = ['%s/%s' % (path, filename) for filename in os.listdir(path)]
27
 
 
28
 
        return publiccache_list
29
 
 
30
 
    def firefox_scan_cache(self, path):
31
 
        firefoxcache_list = []
32
 
        if os.path.exists(path):
33
 
            firefoxcache_list = ['%s/%s' % (path, filename) for filename in os.listdir(path) if filename in 'Cache']
34
 
        return firefoxcache_list
35
 
 
36
 
    def get_softwarecenter_cache(self, homedir):
37
 
        centercachelist = []
38
 
        if homedir:
39
 
            softwarecenter_cache = '%s/.cache/software-center/' % homedir
40
 
        else:
41
 
            softwarecenter_cache = os.path.expanduser('~/.cache/software-center/')
42
 
        full_path = softwarecenter_cache
43
 
        if os.path.exists(full_path):
44
 
            for one in os.listdir(full_path):
45
 
                tmp_path = full_path + one
46
 
                if os.path.isdir(tmp_path):
47
 
                    size = get_dir_size(tmp_path)
48
 
                    centercachelist.append('%s<2_2>%s' % (tmp_path, confirm_filesize_unit(size)))
49
 
                else:
50
 
                    centercachelist.append('%s<2_2>%s' % (tmp_path, confirm_filesize_unit(os.path.getsize(tmp_path))))
51
 
        return centercachelist
52
 
 
53
 
if __name__ == "__main__":
54
 
    obja = CacheClean()
55
 
    obja.get_apt_cache()
56
 
    obja.get_softwarecenter_cache()