>Shouldn't we have a CPAN mirror?
>
>One could write a small script that takes 
>http://www.cpan.org/MIRRORED.BY and generates a fink mirror file 
>from that, I'd think.
>

Ok.

------------------------------
#!/usr//bin/perl -w

use strict;


# configuration
my $mirror_dir = "/sw/lib/fink/mirror";
my $key_file = "$mirror_dir/_keys";
my $mirrored_by_file = "MIRRORED.BY";

# variables
my $current_server;
my %servers;

# script
open(MIRRORBY, "< $mirrored_by_file")
   or die "$mirrored_by_file: $!\n";
while(<MIRRORBY>) {
   chomp;
   next if (m/^\#/);
   if (m/^([a-z0-9A-Z.]+):/) {
     $current_server = $1;
     $servers{$current_server} = {};
     next;
   }
   if (m{^\s+([a-z_]+)\s+=\s+\"([^\"]+)\"}) {
     $servers{$current_server}{$1} = $2;
   }
}
close(MIRRORBY);

my %countries;

open(KEYS, "< $key_file")
   or die "$key_file: $!\n";
while(<KEYS>) {
   chomp;
   if (m/^([a-z]{3}-[A-Z]{2}):\s+(.*)/) {
     $countries{$2} = $1;
   }
}
close(KEYS);

SERVER: foreach my $server (keys %servers) {
   # print "$server\n";
   if (! defined $servers{$server}{dst_location}) {
     warn "$server: no location !\n";
     next;
   }
   foreach my $country (keys %countries) {
     if ($servers{$server}{dst_location} =~ m/$country/i) {
       # print "\t$country -> $countries{$country}\n";
       $servers{$server}{key} = $countries{$country};
       next SERVER;
     }
   }
   warn "$server: country not found in '$servers{$server}{dst_location}'\n";
}

my %keys;
foreach my $server (keys %servers) {
   if (defined $servers{$server}{key}) {
     my $key = $servers{$server}{key};
     my $ftp_location =  $servers{$server}{dst_ftp};
     my $http_location =  $servers{$server}{dst_http};
     if (! defined $keys{$key}) {
       $keys{$key} = [];
     }
     if (defined $http_location) {
       push @{$keys{$key}}, $http_location;
     }
     if (defined $ftp_location) {
       push @{$keys{$key}}, $ftp_location;
     }
   }
}

my ($year, $month, $day) = (gmtime())[5,4,3];
$year += 1900;
$month++;
print "Timestamp: ", sprintf("%d-%02d-%02d", $year, $month, $day), "\n";
print "\n";
print "Primary: ftp://ftp.funet.fi/pub/languages/perl/CPAN/\n";;
foreach my $key (sort keys %keys) {
   foreach my $location (@{$keys{$key}}) {
     print "$key: $location\n";
   }
}

--------------------------------------

-- 
Paul Gaborit -- <http://www.enstimac.fr/~gaborit/>
DR/GI -- <http://www.enstimac.fr/dr/gind/>
Perl en fran�ais -- <http://www.enstimac.fr/Perl/>

_______________________________________________
Fink-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/fink-devel

Reply via email to