diff options
Diffstat (limited to 'perl-install/mirror.pm')
| -rw-r--r-- | perl-install/mirror.pm | 105 |
1 files changed, 82 insertions, 23 deletions
diff --git a/perl-install/mirror.pm b/perl-install/mirror.pm index 563464874..654bdb2e9 100644 --- a/perl-install/mirror.pm +++ b/perl-install/mirror.pm @@ -1,4 +1,4 @@ -package mirror; # $Id$ +package mirror; use diagnostics; use strict; @@ -7,11 +7,21 @@ use feature 'state'; use common; use log; +=head1 SYNOPSYS + +B<mirror> enables to manage Mageia distribution mirrors + +=head1 Functions + +=over + +=cut + my %land2tzs = ( N_("Australia") => [ 'Australia/Sydney' ], N_("Austria") => [ 'Europe/Vienna', 'Europe/Brussels', 'Europe/Berlin' ], N_("Belgium") => [ 'Europe/Brussels', 'Europe/Paris', 'Europe/Berlin' ], - N_("Brazil") => [ 'Brazil/East' ], + N_("Brazil") => [ 'America/Sao_Paulo' ], N_("Canada") => [ 'Canada/Atlantic', 'Canada/Eastern' ], N_("Costa Rica") => [ 'America/Costa_Rica' ], N_("Czech Republic") => [ 'Europe/Prague', 'Europe/Berlin' ], @@ -42,46 +52,85 @@ my %land2tzs = ( N_("United States") => [ 'America/New_York', 'Canada/Atlantic', 'Asia/Tokyo', 'Australia/Sydney', 'Europe/Paris' ], ); +=item mirror2text($mirror) + +Returns a displayable string from a mirror struct + +=cut + sub mirror2text { my ($mirror) = @_; translate($mirror->{country}) . '|' . $mirror->{host} . ($mirror->{method} ? " ($mirror->{method})" : ''); } +=item register_downloader($func) + +Sets a downloader program + +=cut + my $downloader; sub register_downloader { my ($func) = @_; $downloader = $func; } +sub _mirrors_raw_install { + my ($list) = @_; + require install::http; + my $f = install::http::getFile($list, "strict-certificate-check" => 1) or die "mirror list not found"; + local $SIG{ALRM} = sub { die "timeout" }; + alarm 60; + log::l("using mirror list $list"); + my @lines; + push @lines, $_ while <$f>; + alarm 0; + @lines; +} + +sub _mirrors_raw_standalone { + my ($list) = @_; + my @lines; + if (ref($downloader)) { + @lines = $downloader->($list); + @lines or die "mirror list not found"; + } else { + die "Missing download callback"; + } + @lines; +} + +=item mirrors_raw($product_id) + +Returns a list of mirrors hash refs from http://mirrors.mageia.org + +Note that in standalone mode, one has to actually use register_downloader() +first in order to provide a downloader callback. + +=cut + sub mirrors_raw { my ($product_id) = @_; #- contact the following URL to retrieve the list of mirrors. - #- http://wiki.mandriva.com/en/Product_id + #- http://wiki.mageia.org/en/Product_id my $type = lc($product_id->{type}); $type =~ s/\s//g; - my $list = "https://api.mandriva.com/mirrors/$type.$product_id->{version}.$product_id->{arch}.list?product=$product_id->{product}"; + #- FIXME! (blino) we use use https here + my $list = "http://mirrors.mageia.org/api/$type.$product_id->{version}.$product_id->{arch}.list?product=$product_id->{product}"; log::explanations("trying mirror list from $list"); - my @lines; - if ($::isInstall) { - require install::http; - my $f = install::http::getFile($list, "strict-certificate-check" => 1) or die "mirror list not found"; - local $SIG{ALRM} = sub { die "timeout" }; - alarm 60; - log::l("using mirror list $list"); - push @lines, $_ while <$f>; - install::http::close(); - alarm 0; - } else { - if (ref($downloader)) { - @lines = $downloader->($list); - @lines or die "mirror list not found"; - } else { - die "Missing download callback"; - } - } + my @lines = $::isInstall ? _mirrors_raw_install($list) : _mirrors_raw_standalone($list); map { common::parse_LDAP_namespace_structure(chomp_($_)) } @lines; } +=item list($product_id, $type) + + +Returns a list of mirrors hash refs as returned by mirrors_raw() but filters it. + +One can select the type of mirrors ('distrib', 'updates', ...) or 'all' + +=cut + sub list { my ($product_id, $type) = @_; @@ -97,12 +146,18 @@ sub list { my @mirrors = grep { ($_->{method}, $_->{host}, $_->{dir}) = $_->{url} =~ m!^(ftp|http)://(.*?)(/.*)!; - $_->{method} && ($type eq 'all' || $_->{type} eq $type); + $_->{method} && (member($type, 'all', $_->{type})); } @mirrors_raw or log::explanations("no mirrors of type $type"), return; @mirrors && \@mirrors; } +=item nearest($timezone, $mirrors) + +Randomly returns one of the nearest mirror + +=cut + sub nearest { my ($timezone, $mirrors) = @_; @@ -119,4 +174,8 @@ sub nearest { $possible[rand @possible]; } +=back + +=cut + 1; |
