2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Id: /var/cvsroot/gentoo-src/portage/bin/md5check.py,v 1.4 2004/10/10 10:07:20 carpaski Exp $
7 os.environ["PORTAGE_CALLER"]="mirror"
8 os.environ["FEATURES"]="mirror cvs"
9 sys.path = ["/usr/lib/portage/pym"]+sys.path
12 from threading import *
13 from output import red,green,blue,bold
14 from random import shuffle
15 from time import sleep
18 def cstrip(mystr,mychars):
30 for mycp in portage.db["/"]["porttree"].dbapi.cp_all():
31 hugelist += portage.db["/"]["porttree"].dbapi.cp_list(mycp)
34 for mycpv in hugelist:
35 pv = string.split(mycpv, "/")[-1]
37 newuri = portage.db["/"]["porttree"].dbapi.aux_get(mycpv,["SRC_URI"])[0]
38 newuri = string.split(newuri)
40 digestpath = portage.db["/"]["porttree"].dbapi.findname(mycpv)
41 digestpath = os.path.dirname(digestpath)+"/files/digest-"+pv
42 md5sums = portage.digestParseFile(digestpath)
45 portage.writemsg("Missing digest: %s\n" % mycpv)
48 for x in md5sums.keys():
52 #portage.writemsg("\n\ndigestpath: %s\n" % digestpath)
53 #portage.writemsg("md5sums: %s\n" % md5sums)
54 #portage.writemsg("newuri: %s\n" % newuri)
60 if (x in [")","(",":","||"]) or (x[-1] == "?"):
67 mybn = os.path.basename(x)
68 if mybn not in bn_list:
73 if mybn not in md5sums.keys():
74 portage_util.writemsg("Missing md5sum: %s in %s\n" % (mybn, mycpv))
76 if mybn in md5_list.keys():
77 if (md5_list[mybn]["MD5"] != md5sums[mybn]["MD5"]) or \
78 (md5_list[mybn]["size"] != md5sums[mybn]["size"]):
80 # This associates teh md5 with each file. [md5/size]
81 md5joins = string.split(md5_list[mybn][2],",")
82 md5joins = string.join(md5joins," ["+md5_list[mybn][0]+"/"+md5_list[mybn][1]+"],")
83 md5joins += " ["+md5_list[mybn][0]+"/"+md5_list[mybn][1]+"]"
85 portage.writemsg("Colliding md5: %s of %s [%s/%s] and %s\n" % (mybn,mycpv,md5sums[mybn][0],md5sums[mybn][1],md5joins))
88 md5_list[mybn][2] += ","+mycpv
90 md5_list[mybn] = md5sums[mybn]+[mycpv]
93 #portage.writemsg(str(bn_list)+"\n")
94 for x in md5sums.keys():
96 portage.writemsg("Extra md5sum: %s in %s\n" % (x, mycpv))
101 print str(len(md5_list.keys()))+" unique distfile md5s."
102 print str(len(bn_list))+" unique distfile names."