LUCENE-5104: fix poll-mirrors.pl: a) use HEAD; b) look for Changes.html instead of KEYS; c) support looking for arbitrary paths

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1502646 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-07-12 18:37:12 +00:00
parent 40968cf653
commit 412895a266
1 changed files with 43 additions and 16 deletions

View File

@ -30,35 +30,57 @@ use Getopt::Long;
use POSIX qw/strftime/; use POSIX qw/strftime/;
use LWP::UserAgent; use LWP::UserAgent;
my $rel_path;
my $version; my $version;
my $interval = 300; my $interval = 300;
my $quiet = 0; my $details = 0;
my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval); my $result = GetOptions ("version=s" => \$version,
"details!" => \$details,
"path=s" => \$rel_path,
"interval=i" => \$interval);
my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]"; my $usage = ""
. "$0 -v version [ -i interval (seconds; default: 300) ] [ -details ]\n"
. "$0 -p some/explicit/path [ -i interval (seconds; default: 300) ] [ -details ]\n"
;
unless ($result) { unless ($result) {
print STDERR $usage; print STDERR $usage;
exit(1); exit(1);
} }
unless (defined($version) && $version =~ /\d+(?:\.\d+)+/) {
print STDERR "You must specify the release version.\n$usage"; unless (defined($version) xor defined($rel_path)) {
print STDERR "You must specify either -version or -path but not both\n$usage";
exit(1); exit(1);
} }
my $label;
my $apache_url_suffix;
my $maven_url;
if (defined($version)) {
if ($version !~ /^\d+(?:\.\d+)+/) {
print STDERR "You must specify the release version as a number.\n$usage";
exit(1);
}
$label = $version;
$apache_url_suffix = "lucene/java/$version/changes/Changes.html";
$maven_url = "http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
} else {
# path based
$apache_url_suffix = $label = $rel_path;
}
my $previously_selected = select STDOUT; my $previously_selected = select STDOUT;
$| = 1; # turn off buffering of STDOUT, so status is printed immediately $| = 1; # turn off buffering of STDOUT, so status is printed immediately
select $previously_selected; select $previously_selected;
my $apache_url_suffix = "lucene/java/$version/KEYS";
my $apache_mirrors_list_url = "http://www.apache.org/mirrors/"; my $apache_mirrors_list_url = "http://www.apache.org/mirrors/";
my $maven_url = "http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
my $agent = LWP::UserAgent->new(); my $agent = LWP::UserAgent->new();
$agent->timeout(2); $agent->timeout(2);
my $maven_available = 0; my $maven_available = defined($maven_url) ? 0 : -999;
my @apache_mirrors = (); my @apache_mirrors = ();
@ -77,7 +99,7 @@ if (defined($apache_mirrors_list_page)) {
next unless ($mirror_entry =~ m~<TD>\s*ok\s*</TD>\s*$~i); # skip mirrors with problems next unless ($mirror_entry =~ m~<TD>\s*ok\s*</TD>\s*$~i); # skip mirrors with problems
if ($mirror_entry =~ m~<A\s+HREF\s*=\s*"([^"]+)"\s*>~i) { if ($mirror_entry =~ m~<A\s+HREF\s*=\s*"([^"]+)"\s*>~i) {
my $mirror_url = $1; my $mirror_url = $1;
push @apache_mirrors, "$mirror_url/$apache_url_suffix"; push @apache_mirrors, "${mirror_url}${apache_url_suffix}";
} }
} }
} else { } else {
@ -95,16 +117,16 @@ while (1) {
print "...\n"; print "...\n";
my $start = time(); my $start = time();
$maven_available = (200 == $agent->get($maven_url)->code) $maven_available = (200 == $agent->head($maven_url)->code)
unless ($maven_available); unless ($maven_available);
@apache_mirrors = &check_mirrors; @apache_mirrors = &check_mirrors;
my $stop = time(); my $stop = time();
$sleep_interval = $interval - ($stop - $start); $sleep_interval = $interval - ($stop - $start);
my $num_downloadable_apache_mirrors = $num_apache_mirrors - $#apache_mirrors; my $num_downloadable_apache_mirrors = $num_apache_mirrors - $#apache_mirrors;
print "$version is ", ($maven_available ? "" : "not "), print "$label is ", ($maven_available ? "" : "not "),
"downloadable from Maven Central.\n"; "downloadable from Maven Central.\n" if defined($maven_url);
printf "$version is downloadable from %d/%d Apache Mirrors (%0.1f%%)\n", printf "$label is downloadable from %d/%d Apache Mirrors (%0.1f%%)\n",
$num_downloadable_apache_mirrors, $num_apache_mirrors, $num_downloadable_apache_mirrors, $num_apache_mirrors,
($num_downloadable_apache_mirrors*100/$num_apache_mirrors); ($num_downloadable_apache_mirrors*100/$num_apache_mirrors);
@ -119,9 +141,14 @@ while (1) {
sub check_mirrors { sub check_mirrors {
my @not_yet_downloadable_apache_mirrors; my @not_yet_downloadable_apache_mirrors;
for my $mirror (@apache_mirrors) { for my $mirror (@apache_mirrors) {
push @not_yet_downloadable_apache_mirrors, $mirror
unless (200 == $agent->get($mirror)->code); ### print "\n$mirror\n";
print "."; if (200 != $agent->head($mirror)->code) {
push @not_yet_downloadable_apache_mirrors, $mirror;
print $details ? "\nFAIL: $mirror\n" : "X";
} else {
print ".";
}
} }
print "\n"; print "\n";
return @not_yet_downloadable_apache_mirrors; return @not_yet_downloadable_apache_mirrors;