1 |
On Tuesday 25 March 2003 18:55, DJ Cozatt wrote: |
2 |
> I won't repost the thread but I liked this idea and wondered it if could |
3 |
> also be extended to remove old pkg's in PKGDIR set when usindg buildpkg |
4 |
> in /etc/make.conf Would yield a more general housecleaning app |
5 |
> |
6 |
> bus_drivr |
7 |
> |
8 |
> -- |
9 |
> gentoo-dev@g.o mailing list |
10 |
|
11 |
Heres my binary packages cleaning script. Its very simplistic but does the |
12 |
job. |
13 |
|
14 |
#!/usr/bin/python |
15 |
|
16 |
import os |
17 |
import stat |
18 |
import string |
19 |
|
20 |
def samename(s0,s1): |
21 |
i=0 |
22 |
for x in s0: |
23 |
if x in string.digits: |
24 |
break |
25 |
i+=1 |
26 |
# same for s1 |
27 |
j=0 |
28 |
for x in s0: |
29 |
if x in string.digits: |
30 |
break |
31 |
j+=1 |
32 |
return s0[:i]==s1[:j] |
33 |
|
34 |
dirs=['All'] |
35 |
removed=[] |
36 |
for dir in dirs: |
37 |
print 'Searching files' |
38 |
os.chdir('/usr/portage/packages/'+dir) |
39 |
list=os.listdir('.') |
40 |
list.sort() |
41 |
current=list[0] |
42 |
for x in list[1:]: |
43 |
if samename(current,x): |
44 |
time0=os.stat(current)[stat.ST_CTIME] |
45 |
time1=os.stat(x)[stat.ST_CTIME] |
46 |
if time0<time1: |
47 |
removed.append(current) |
48 |
os.remove(current) |
49 |
current=x |
50 |
else: |
51 |
removed.append(x) |
52 |
os.remove(x) |
53 |
else: |
54 |
current=x |
55 |
|
56 |
print 'Removed',removed |
57 |
|
58 |
print 'Searching for broken symlinks' |
59 |
removed=[] |
60 |
dirs=os.listdir('/usr/portage/packages/') |
61 |
for dir in dirs: |
62 |
os.chdir('/usr/portage/packages/'+dir) |
63 |
list=os.listdir('.') |
64 |
for f in list: |
65 |
try: |
66 |
os.stat(f) |
67 |
except: |
68 |
if os.path.islink(f): |
69 |
removed.append(f) |
70 |
os.remove(f) |
71 |
|
72 |
print 'Removed',removed |
73 |
|
74 |
|
75 |
|
76 |
-- |
77 |
gentoo-dev@g.o mailing list |