1
2
3
4
5
6
7
8
9
10
11
12 | # encoding: UTF-8
# api: streamtuner2
# title: Cache Reset
# description: Allows to empty cached stations and favicons
# version: 0.2
# type: feature
# category: config
# priority: optional
# hooks: config_load
#
# Inserts a [Cache Reset] button into the Options tab. Allows
# to either clear channel caches and/or stored favicons. |
|
| 1
2
3
4
5
6
7
8
9
10
11
12 | # encoding: UTF-8
# api: streamtuner2
# title: Cache Reset
# description: Allows to empty cached stations and favicons
# version: 0.3
# type: feature
# category: config
# priority: optional
# hooks: config_load
#
# Inserts a [Cache Reset] button into the Options tab. Allows
# to either clear channel caches and/or stored favicons. |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 | self.l1 = self.t1.get_children()[0]
self.l2 = self.t2.get_children()[0]
self.l3 = self.t3.get_children()[0]
# Update size labels
def dialog_update(self, *w):
s1 = self.foldersize(conf.dir + "/cache") / 1024
s2 = self.foldersize(conf.dir + "/icons") / 1024
s3 = self.foldersize(conf.tmp) / 1024
self.l1.set_text("Channels (%s KB)" % s1)
self.l2.set_text("Icons (%s KB)" % s2)
self.l3.set_text("Temp (%s KB)" % s3)
# Calculate folder size (flat dir)
def foldersize(self, p):
if os.path.exists(p):
try:
return sum([os.path.getsize(p+"/"+fn) for fn in os.listdir(p)])
except:
pass
return 0
# Actually delete stuff
def execute(self, *w):
for dir, btn in [(conf.dir+"/cache/", self.t1), (conf.dir+"/icons/", self.t2), (conf.tmp+"/", self.t3)]:
# check if checked
if not btn.get_state():
continue
# list dir + delete files
for fn in os.listdir(dir):
os.unlink(dir + fn)
open(dir + ".nobackup", "a").close()
self.dialog_update() |
|
|
|
| 49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 | self.l1 = self.t1.get_children()[0]
self.l2 = self.t2.get_children()[0]
self.l3 = self.t3.get_children()[0]
# Update size labels
def dialog_update(self, *w):
s1 = self.foldersize(conf.datadir + "/cache") / 1024
s2 = self.foldersize(conf.datadir + "/icons") / 1024
s3 = self.foldersize(conf.tmp) / 1024
self.l1.set_text("Channels (%s KB)" % s1)
self.l2.set_text("Icons (%s KB)" % s2)
self.l3.set_text("Temp (%s KB)" % s3)
# Calculate folder size (flat dir)
def foldersize(self, p):
if os.path.exists(p):
try:
return sum([os.path.getsize(p+"/"+fn) for fn in os.listdir(p)])
except:
pass
return 0
# Actually delete stuff
def execute(self, *w):
for dir, btn in [(conf.datadir+"/cache/", self.t1), (conf.datadir+"/icons/", self.t2), (conf.tmp+"/", self.t3)]:
# check if checked
if not btn.get_state():
continue
# list dir + delete files
for fn in os.listdir(dir):
os.unlink(dir + fn)
open(dir + ".nobackup", "a").close()
self.dialog_update() |