diff options
Diffstat (limited to 'perl-extras/bin/add_module.pl')
-rw-r--r-- | perl-extras/bin/add_module.pl | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/perl-extras/bin/add_module.pl b/perl-extras/bin/add_module.pl index 0cf3b0cfd..a39e9fd0c 100644 --- a/perl-extras/bin/add_module.pl +++ b/perl-extras/bin/add_module.pl @@ -7,15 +7,16 @@ use IPC::Run3; use LWP::Simple; use YAML; use File::Slurp; +use Path::Class; my $cpan_meta_db_base = "http://cpanmetadb.appspot.com/v1.0/package"; my $cpan_mirror_base = "http://search.cpan.org/CPAN/authors/id"; -my $root_dir = "/home/evdb/fixmystreet/perl-extras"; +my $root_dir = file(__FILE__)->dir->parent->absolute->stringify; my $dist_list = "$root_dir/install_order.txt"; +my $url_list = "$root_dir/urls.txt"; my $dist_dir = "$root_dir/distributions"; -my $local_lib_dir = "local-lib5"; my $fake_mirror = "$root_dir/fake_mirror"; -my $cpanm_cmd = "perl $root_dir/cpanm --reinstall -L $local_lib_dir"; +my $cpanm_cmd = "perl $root_dir/bin/cpanm"; # my $cpanm_cmd = # "perl $dist_dir/cpanm --mirror $fake_mirror --mirror-only -L $local_lib_dir"; @@ -29,9 +30,8 @@ print " running '$cmd'\n"; run3( $cmd, undef, \$out, \$out ) || die "Error running '$cmd'"; -warn $out; - -my @fetched_urls = +my %fetched_urls = + map { $_ => 1 } map { s{.*(http://\S+).*}{$1}; $_ } grep { m{^Fetching http://search.cpan.org} } split /\n/, $out; @@ -41,21 +41,25 @@ my @installed = map { m{^Successfully (?:re)?installed (\S+).*} ? $1 : undef } split /\n/, $out; -use Data::Dumper; -local $Data::Dumper::Sortkeys = 1; -warn Dumper( { fetched => \@fetched_urls, installed => \@installed } ); - foreach my $dist (@installed) { - my ($url) = grep { m{/$dist\.} } @fetched_urls; + my ($url) = grep { m{/$dist\.} } keys %fetched_urls; + die "Can't find url for $dist" unless $url; + delete $fetched_urls{$url}; + my ($filename) = $url =~ m{([^/]+)$}; - print " getting $filename from $url\n"; + print " fetching $filename from $url\n"; is_success( getstore( $url, "$dist_dir/$filename" ) ) || die "Error saving $url to $dist_dir/$filename"; write_file( $dist_list, { append => 1 }, "$filename\n" ); + write_file( $url_list, { append => 1 }, "$url\n" ); } +# Check that there are no urls left over +my @leftover = keys %fetched_urls; +die "URLs leftover: " . join( ', ', @leftover ) if @leftover; + # # # # load list of modules at start and write it back at the end # my %installed = (); |