#!/usr/bin/perl -w # Gentoo package download size # (C) Alex Walker 2002 # alex@x3ja.co.uk # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Major problems: # - Uses digest file to predict sizes - not all these files are used in the # relative ebuild. # - Can only put in one package at a time. use strict; use Digest::MD5; my $debug; if ($ARGV[0] && $ARGV[0] eq "-d") { $debug = 1; shift @ARGV; } unless ($ARGV[0] && $ARGV[1]) { print "Need at least two arguments!\n"; exit } my ($category, $package) = split('/',"$ARGV[0]",2); my $version = "$ARGV[1]"; my $digestfile = "/usr/portage/$category/$package/files/digest-$package-$version"; my $distfilepath = "/usr/portage/distfiles/"; print "Category: $category\nPackage: $package\nVersion: $version\n" if $debug; open(DIGEST,'<',$digestfile) or die "Can't open digest file file!"; my $togo = 0; my $got = 0; my $total = 0; while () { chomp $_; my (undef,$md5,$file,$size) = split (' ',$_,4); print "File: $file\nSize: $size\nMD5 digest: $md5\n" if $debug; $total = $total + $size; if (open(FILE, "$distfilepath/$file")) { binmode(FILE); my $filemd5 = Digest::MD5->new->addfile(*FILE)->hexdigest; print "MD5 file: $filemd5\n" if $debug; if ( $filemd5 eq $md5) { $got = $got + $size; next; } } $togo = $togo + $size; } print "Got: $got\nTo get: $togo\nTotal: $total\n" if $debug; print "$togo\n"