#!/usr/bin/env python # vim: set ts=4 sts=4: # # eclean -- (c) 2004 Michal Januszewski # # 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). 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)