r1850@llin: dpavlin | 2009-04-26 02:07:56 +0200
[webpac2] / run.pl
diff --git a/run.pl b/run.pl
index 01d3e77..8b3d666 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -22,6 +22,7 @@ use File::Slurp;
 use Data::Dump qw/dump/;
 use Storable qw/dclone/;
 use Pod::Usage qw/pod2usage/;
+use LWP::Simple;
 
 use POSIX ":sys_wait_h"; # imports WNOHANG
 
@@ -102,6 +103,10 @@ Create just links
 
 Create merged index of databases which have links
 
+=item --mirror http://www.example.com
+
+Tries to download input path files from mirror URI
+
 =back
 
 =cut
@@ -122,6 +127,7 @@ my $marc_dump = 0;
 my $parallel = 0;
 my $only_links = 0;
 my $merge = 0;
+my $mirror;
 my $help;
 
 my $log = _new WebPAC::Common()->_get_logger();
@@ -143,6 +149,7 @@ GetOptions(
        "parallel=i" => \$parallel,
        "only-links!" => \$only_links,
        "merge" => \$merge,
+       "mirror=s" => \$mirror,
        "help" => \$help,
 );
 
@@ -371,6 +378,11 @@ foreach my $database ( sort keys %{ $config->databases } ) {
 
                my $input_name = $input->{name} || $log->logdie("input without a name isn't valid: ",dump($input));
 
+               if ( $input->{skip} ) {
+                       $log->info("skip $input_name");
+                       next;
+               }
+
                next if ($only_input && ($input_name !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
 
                my $type = lc($input->{type});
@@ -398,6 +410,14 @@ foreach my $database ( sort keys %{ $config->databases } ) {
                        delete($input->{modify_file});
                }
 
+               if ( $mirror ) {
+                       my $path = $input->{path} || die "no input path in ",dump( $input );
+                       $log->info( "mirror ", $path, " ", -s $path, " bytes" );
+
+                       $log->warn( "$path not modified" )
+                               if mirror( "$mirror/$path", $path ) == RC_NOT_MODIFIED;
+               }
+
                my $input_db = new WebPAC::Input(
                        module => $input_module,
                        limit => $limit || $input->{limit},