4 die "not yet ported to ds8143" if hostname
eq "ds8143";
24 my @opt = <<'=back' =~ /B<--(\S+)>/g;
28 defaults to C</home/ftp/cpantesters/reports>
34 =item B<--interactive|i!>
36 Defaults to true. If set to false (--nointeractive or --noi), you can
37 remove hundreds of thousands of file without being asked a single
40 =item B<--numversions=i>
42 Defaults to 2 which means look at the two most recent versions for
43 whatever we're doing. Everything older is discarded considered
50 Walk through all distro-directories we have and remove outdated ones.
52 Born as a copy of smokehistory.pl
58 use lib
"$FindBin::Bin/../lib";
64 use File
::Basename
qw(dirname);
65 use File
::Path
qw(mkpath rmtree);
69 use Hash
::Util
qw(lock_keys);
70 use List
::MoreUtils
qw(uniq);
71 use List
::Util
qw(first);
72 use Term
::Prompt
qw(prompt);
78 lock_keys
%Opt, map { /([^=!\|]+)/ } @opt;
82 $Opt{dir
} ||= "/home/ftp/cpantesters/reports";
83 $Opt{interactive
} = 1 unless defined $Opt{interactive
};
84 $Opt{numversions
} ||= 2;
86 opendir my $dh, $Opt{dir
} or die;
87 my %S; # for the summary at the end
88 my $tf = Text
::Format
->new(firstIndent
=>0);
90 LETTERDIR
: for my $dirent (sort readdir $dh) { # A B C
91 next unless $dirent =~ /^[A-Za-z]$/;
92 opendir my $dh2, "$Opt{dir}/$dirent" or die;
94 DISTRO
: for my $dirent2 (readdir $dh2) { # Dpchrist-ExtUtils-MakeMaker-1.015
95 next if $dirent2 =~ /^\.\.?$/;
96 my $vdistro = $dirent2;
97 my($distro,$version,$mod) = $vdistro =~ /(\S+)-(v?\d+(?:[\.\d]*[^-]*))(-(?:TRIAL|withoutworldwriteables|fix))?$/;
98 unless (defined $version) {
100 ($distro,$version) = $vdistro =~ /(\D+)(\d+)/;
102 unless (defined $version){
103 die "could not parse version from $vdistro";
105 $version=~s/[^\d\.]+$//;
106 1 while $version=~s/([\d\.])[^\d\.]+.*/$1/;
108 # print "DEBUG: parse version[$version] of distro[$distro](vdistro[$vdistro])\n";
109 my $numversion = eval {version
->new($version)->numify};
110 if (not defined $numversion) {
111 die "ERROR: Could not parse version[$version] of distro[$distro](vdistro[$vdistro]): $@";
113 die "Panic: we have a \$\@[$@] but a numversion[$numversion] too";
115 $vdistro{$distro}{$numversion} = $vdistro;
117 for my $distro (keys %vdistro) {
118 my $v = $vdistro{$distro};
119 my @vdistros_sorted_by_version = sort { $a <=> $b } keys %$v;
120 while (@vdistros_sorted_by_version > $Opt{numversions
}) {
121 my $cldir = $v->{$vdistros_sorted_by_version[0]};
122 my $absdir = "$Opt{dir}/$dirent/$cldir";
123 opendir my $dh3, "$absdir/nntp-testers" or die "Could not open '$absdir/nntp-testers': $!";
124 my @cldirent = grep { /\.gz$/ } readdir $dh3;
126 ("==> Having reports from
129 %s (%s). The oldest of those,
132 scalar @vdistros_sorted_by_version,
134 $cldir, join(",",@vdistros_sorted_by_version),
135 $vdistros_sorted_by_version[0],
138 print $tf->format($report);
140 if ($Opt{interactive
}) {
141 $answer = lc prompt
"x", "Shall I delete '$absdir'? (y/n/q)", "", "y";
145 if ($answer eq "q") {
147 } elsif ($answer eq "n") {
148 } elsif ($answer eq "y") {
150 if ($Opt{interactive
}) {
151 warn sprintf "Deleted %d reports.\n", scalar @cldirent;
154 shift @vdistros_sorted_by_version;
158 warn YAML
::Syck
::Dump \
%S;
162 # cperl-indent-level: 4