last commit was the wrong version (older) - this is the right one

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1131274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2011-06-03 22:36:20 +00:00
parent 64a1a701e7
commit 5c4cf50847
1 changed files with 23 additions and 10 deletions

View File

@ -27,7 +27,9 @@
use strict; use strict;
use warnings; use warnings;
use Getopt::Long; use Getopt::Long;
use POSIX qw/strftime/;
use LWP::Simple; use LWP::Simple;
use HTTP::Request;
require LWP::Parallel::UserAgent; require LWP::Parallel::UserAgent;
my $version; my $version;
@ -53,7 +55,7 @@ select $previously_selected;
my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc"; my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc";
my $apache_mirrors_list_url = "http://www.apache.org/mirrors/"; my $apache_mirrors_list_url = "http://www.apache.org/mirrors/";
my $maven_url = "http://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc"; my $maven_url = "http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
my $maven_available = 0; my $maven_available = 0;
@ -83,36 +85,47 @@ if (defined($apache_mirrors_list_page)) {
} }
my $num_apache_mirrors = $#apache_mirrors; my $num_apache_mirrors = $#apache_mirrors;
print "# Apache Mirrors: $num_apache_mirrors\n";
while (1) { while (1) {
my $start = time();
print "\nPolling $#apache_mirrors Apache Mirrors";
print " and Maven Central" unless ($maven_available);
print "...\n";
unless ($maven_available) { unless ($maven_available) {
my $content = get($maven_url); my $content = get($maven_url);
$maven_available = defined($content); $maven_available = defined($content);
} }
@apache_mirrors = &check_mirrors; @apache_mirrors = &check_mirrors;
my $num_downloadable_apache_mirrors my $num_downloadable_apache_mirrors
= $num_apache_mirrors - $#apache_mirrors; = $num_apache_mirrors - $#apache_mirrors;
print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime), "\n";
print "$version is ", ($maven_available ? "" : "not "),
"downloadable from Maven Central.\n";
printf "$version is downloadable from %d/%d Apache Mirrors (%0.1f%%)\n",
$num_downloadable_apache_mirrors, $num_apache_mirrors,
($num_downloadable_apache_mirrors*100/$num_apache_mirrors);
print "Available: "; last if ($maven_available && 0 == $#apache_mirrors);
print "Maven Central; " if ($maven_available);
printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors, my $stop = time();
$num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors); my $sleep_interval = $interval - 2 * ($stop - $start);
last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors); sleep($interval) if ($sleep_interval > 0);
sleep($interval);
} }
sub check_mirrors { sub check_mirrors {
my $agent = LWP::Parallel::UserAgent->new(); my $agent = LWP::Parallel::UserAgent->new();
$agent->timeout(30); $agent->timeout(30);
$agent->redirect(1); # follow redirects $agent->redirect(1); # follow redirects
$agent->register($_) for (@apache_mirrors); $agent->register(HTTP::Request->new(GET=>$_)) for (@apache_mirrors);
my $entries = $agent->wait(); my $entries = $agent->wait();
my @not_yet_downloadable_apache_mirrors; my @not_yet_downloadable_apache_mirrors;
for my $entry (keys %$entries) { for my $entry (keys %$entries) {
my $response = $entries->{$entry}->response; my $response = $entries->{$entry}->response;
push @not_yet_downloadable_apache_mirrors, $response->request->uri push @not_yet_downloadable_apache_mirrors, $response->request->uri
unless ($response->is_success); unless (200 == $response->code);
} }
return @not_yet_downloadable_apache_mirrors; return @not_yet_downloadable_apache_mirrors;
} }