1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#!/usr/bin/env python
# vim: set ts=4 sts=4:
#
# eclean -- (c) 2004 Michal Januszewski <spock@gentoo.org>
#
# A little script to display a list of ebuilds than can be cleaned out
# - ie. a list of ebuilds that don't provide any new archs or ~archs.
#
# Usage: just call it in a directory with a bunch of ebuilds.
#
# $Header: /srv/cvs/gentoo/gendevtools/eclean,v 1.2 2004/09/10 14:38:07 spock Exp $
import sys, re, string, commands, math
# The following two functions are taken from portage and hacked a little bit
# to handle package revisions (-r<x>).
endversion={"pre":-2,"p":0,"alpha":-4,"beta":-3,"rc":-1}
endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
def relparse(myver):
"converts last version part into three components"
number=0
suffix=0
endtype=0
endnumber=0
mynewver=string.split(myver,"_")
myver=mynewver[0]
#normal number or number with letter at end
divider=len(myver)-1
if myver[divider:] not in "1234567890":
#letter at end
suffix=ord(myver[divider:])
number=string.atof(myver[0:divider])
elif re.match("r([0-9]+)", myver):
# this will fail if we ever get more than 100 revisions
# - hopefully, that will never happen ;>
number=string.atof(myver[1:])/100
else:
number=string.atof(myver)
if len(mynewver)==2:
#an endversion
for x in endversion_keys:
elen=len(x)
if mynewver[1][:elen] == x:
match=1
endtype=endversion[x]
try:
endnumber=string.atof(mynewver[1][elen:])
except:
endnumber=0
break
return [number,suffix,endtype,endnumber]
vcmpcache={}
def vercmp(val1,val2):
if val1==val2:
#quick short-circuit
return 0
valkey=val1+" "+val2
try:
return vcmpcache[valkey]
try:
return -vcmpcache[val2+" "+val1]
except KeyError:
pass
except KeyError:
pass
# consider 1_p2 vc 1.1
# after expansion will become (1_p2,0) vc (1,1)
# then 1_p2 is compared with 1 before 0 is compared with 1
# to solve the bug we need to convert it to (1,0_p2)
# by splitting _prepart part and adding it back _after_expansion
val1_prepart = val2_prepart = ''
if val1.count('_'):
val1, val1_prepart = val1.split('_', 1)
if val2.count('_'):
val2, val2_prepart = val2.split('_', 1)
# replace '-' by '.'
# FIXME: Is it needed? can val1/2 contain '-'?
val1=string.split(val1,'-')
if len(val1)==2:
val1[0]=val1[0]+"."+val1[1]
val2=string.split(val2,'-')
if len(val2)==2:
val2[0]=val2[0]+"."+val2[1]
val1=string.split(val1[0],'.')
val2=string.split(val2[0],'.')
#add back decimal point so that .03 does not become "3" !
for x in range(1,len(val1)):
if val1[x][0] == '0' :
val1[x]='.' + val1[x]
for x in range(1,len(val2)):
if val2[x][0] == '0' :
val2[x]='.' + val2[x]
# extend version numbers
if len(val2)<len(val1):
val2.extend(["0"]*(len(val1)-len(val2)))
elif len(val1)<len(val2):
val1.extend(["0"]*(len(val2)-len(val1)))
# add back _prepart tails
if val1_prepart:
val1[-1] += '_' + val1_prepart
if val2_prepart:
val2[-1] += '_' + val2_prepart
#The above code will extend version numbers out so they
#have the same number of digits.
for x in range(0,len(val1)):
cmp1=relparse(val1[x])
cmp2=relparse(val2[x])
for y in range(0,4):
myret=cmp1[y]-cmp2[y]
if myret != 0:
if myret < 0:
myret = -1
else:
myret = 1
vcmpcache[valkey]=myret
return myret
vcmpcache[valkey]=0
return 0
pkg = commands.getoutput('basename $(pwd)')
versions = string.split(commands.getoutput('ls -1 *ebuild | sed -e "s/.ebuild//" -e "s/$(basename $(pwd))-//"'),"\n")
versions.sort(vercmp)
versions.reverse()
tbl={}
for i in versions:
data = commands.getoutput('grep KEYWORDS %s-%s.ebuild | sed -e "s/KEYWORDS=//" -e \'s/"//g\'' % (pkg, i))
toclean = 1
for arch in string.split(data,' '):
if re.match('\*', arch) or len(arch) == 0:
continue
if arch[0] == '~':
if not tbl.has_key(arch[1:]):
tbl[arch[1:]] = {}
if not tbl[arch[1:]].has_key("unstable") and not tbl[arch[1:]].has_key("stable"):
tbl[arch[1:]]["unstable"] = i
toclean = 0
elif data[0] != '-':
if not tbl.has_key(arch):
tbl[arch] = {}
if not tbl[arch].has_key("stable"):
tbl[arch]["stable"] = i
toclean = 0
if toclean:
print "clean %s (%s)" % (i,data)
|