set native eol style; print timestamps at each polling interval; remove -quiet option; improve polling interval timing accuracy

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1131270 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2011-06-03 22:31:04 +00:00
parent 1da4ffee6e
commit 64a1a701e7
1 changed files with 118 additions and 118 deletions

View File

@ -1,118 +1,118 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# poll-mirrors.pl # poll-mirrors.pl
# #
# This script is designed to poll download sites after posting a release # This script is designed to poll download sites after posting a release
# and print out notice as each becomes available. The RM can use this # and print out notice as each becomes available. The RM can use this
# script to delay the release announcement until the release can be # script to delay the release announcement until the release can be
# downloaded. # downloaded.
# #
# #
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. # this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0 # The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with # (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at # the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
use strict; use strict;
use warnings; use warnings;
use Getopt::Long; use Getopt::Long;
use LWP::Simple; use LWP::Simple;
require LWP::Parallel::UserAgent; require LWP::Parallel::UserAgent;
my $version; my $version;
my $interval = 300; my $interval = 300;
my $quiet = 0; my $quiet = 0;
my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval); my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval);
my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]"; my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]";
unless ($result) { unless ($result) {
print STDERR $usage; print STDERR $usage;
exit(1); exit(1);
} }
unless (defined($version) && $version =~ /\d+(?:\.\d+)+/) { unless (defined($version) && $version =~ /\d+(?:\.\d+)+/) {
print STDERR "You must specify the release version.\n$usage"; print STDERR "You must specify the release version.\n$usage";
exit(1); exit(1);
} }
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/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://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
my $maven_available = 0; my $maven_available = 0;
my @apache_mirrors = (); my @apache_mirrors = ();
my $apache_mirrors_list_page = get($apache_mirrors_list_url); my $apache_mirrors_list_page = get($apache_mirrors_list_url);
if (defined($apache_mirrors_list_page)) { if (defined($apache_mirrors_list_page)) {
#<TR> #<TR>
# <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A>&nbsp;&nbsp;<A HREF="http://apache.dattatec.com/">@</A></TD> # <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A>&nbsp;&nbsp;<A HREF="http://apache.dattatec.com/">@</A></TD>
# #
# <TD>http</TD> # <TD>http</TD>
# <TD ALIGN=RIGHT>8 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD> # <TD ALIGN=RIGHT>8 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
# <TD ALIGN=RIGHT>5 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD> # <TD ALIGN=RIGHT>5 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
# <TD>ok</TD> # <TD>ok</TD>
#</TR> #</TR>
while ($apache_mirrors_list_page =~ m~<TR>(.*?)</TR>~gis) { while ($apache_mirrors_list_page =~ m~<TR>(.*?)</TR>~gis) {
my $mirror_entry = $1; my $mirror_entry = $1;
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 {
print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url"; print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url";
exit(1); exit(1);
} }
my $num_apache_mirrors = $#apache_mirrors; my $num_apache_mirrors = $#apache_mirrors;
print "# Apache Mirrors: $num_apache_mirrors\n"; print "# Apache Mirrors: $num_apache_mirrors\n";
while (1) { while (1) {
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 "Available: "; print "Available: ";
print "Maven Central; " if ($maven_available); print "Maven Central; " if ($maven_available);
printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors, printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors,
$num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors); $num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors);
last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors); last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors);
sleep($interval); 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($_) 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 ($response->is_success);
} }
return @not_yet_downloadable_apache_mirrors; return @not_yet_downloadable_apache_mirrors;
} }