Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; $|++; ### CONFIG # the CPAN url to fetch my $REMOTE = "http://www.cpan.org/"; # my $REMOTE = "file://Users/merlyn/MIRROR/CPAN/"; # my $REMOTE = "http://fi.cpan.org/"; # my $REMOTE = "http://au.cpan.org/"; # the path to the local mirror # warning: unknown files below this dir are deleted! my $LOCAL = "/Users/merlyn/Perl/MINICPAN/"; # how verbose? false means nothing but errors my $TRACE = 1; ## END CONFIG ## core: use File::Path qw(mkpath); use File::Basename qw(dirname); use File::Spec::Functions qw(catfile); use File::Find qw(find); ## LWP: use URI (); use LWP::Simple qw(mirror RC_OK RC_NOT_MODIFIED); ## Compress::Zlib use Compress::Zlib qw(gzopen $gzerrno); ## first, get index files my_mirror($_) for qw( authors/01mailrc.txt.gz modules/02packages.details.txt.gz modules/03modlist.data.gz ); ## now walk the packages list my $gz = gzopen(catfile($LOCAL, "modules/02packages.details.txt.gz"), +"rb") or die "Cannot open details: $gzerrno"; my $state = 1; while ($gz->gzreadline($_) > 0) { if ($state == 1) { # in header $state = 2 unless /\S/; next; } if ($state == 2) { # blank following header $state = 3; next; } my ($module, $version, $path) = split; my_mirror("authors/id/$path"); } ## finally, clean the files we didn't stick there clean_unmirrored(); exit 0; BEGIN { my %mirrored; sub my_mirror { my $path = shift; my $remote_uri = URI->new_abs($path, $REMOTE)->as_string; my $local_file = catfile($LOCAL, $path); return if $mirrored{$local_file}++; ## presume "authors/id/*" is up to date if it is present return if $path =~ m{^authors/id} and -f $local_file; print "$remote_uri -> $local_file\n" if $TRACE; mkpath(dirname($local_file), 1, 0711); my $status = mirror($remote_uri, $local_file); return if $status == RC_OK or $status == RC_NOT_MODIFIED; warn "$remote_uri: $status!\n"; } sub clean_unmirrored { find sub { return unless -f and not $mirrored{$File::Find::name}; print "removing $File::Find::name\n" if $TRACE; unlink $_ or warn "Cannot remove $File::Find::name: $!"; }, $LOCAL; } }

In reply to Mirror only the installable parts of CPAN by merlyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-24 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found