4 import Task
, Utils
, Options
, Build
7 Execute a method to reduce the cache size after the build is complete
8 Looking at the cache size is an expensive operation
11 re_num
= re
.compile('[a-zA-Z_]+(\d+)')
15 for (p
, d
, files
) in os
.walk(root
):
18 tot
+= os
.path
.getsize(os
.path
.join(p
, f
))
21 return tot
/ (1024*1024.0)
24 return cmp(x
[1], y
[1])
26 old
= Build
.BuildContext
.compile
33 if not Options
.cache_global
or Options
.options
.nocache
:
37 val
= re_num
.sub('\\1', os
.path
.basename(Options
.cache_global
))
45 # loop in case another process is still filling up the cache
46 s
= dsize(Options
.cache_global
)
50 lst
= [Options
.cache_global
+ os
.sep
+ x
for x
in Utils
.listdir(Options
.cache_global
)]
55 acc
.append((x
, os
.path
.getctime(x
), dsize(x
)))
59 # sort the files by the oldest first
62 tot
= sum([x
[2] for x
in acc
])
65 # remove at least 10% more, just to make sure
66 while tot
- cur
> 0.9 * CACHESIZE
:
70 # ignore if the folders cannot be removed
76 Build
.BuildContext
.compile = compile