/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 956 by dpavlin, Fri Nov 2 10:54:42 2007 UTC revision 1084 by dpavlin, Sun Dec 23 22:06:08 2007 UTC
# Line 133  GetOptions( Line 133  GetOptions(
133          "clean" => \$clean,          "clean" => \$clean,
134          "one=s" => \$only_filter,          "one=s" => \$only_filter,
135          "only=s" => \$only_filter,          "only=s" => \$only_filter,
136          "config" => \$config_path,          "config=s" => \$config_path,
137          "debug+" => \$debug,          "debug+" => \$debug,
138          "stats" => \$stats,          "stats" => \$stats,
139          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
# Line 153  pod2usage(-verbose => 2) if ($help); Line 153  pod2usage(-verbose => 2) if ($help);
153    
154  my $config = new WebPAC::Config( path => $config_path );  my $config = new WebPAC::Config( path => $config_path );
155    
156    WebPAC::Normalize::_debug( $debug - 1 ) if $debug > 1;
157    
158  #print "config = ",dump($config) if ($debug);  #print "config = ",dump($config) if ($debug);
159    
160  die "no databases in config file!\n" unless ($config->databases);  die "no databases in config file!\n" unless ($config->databases);
# Line 191  if ($stats) { Line 193  if ($stats) {
193    
194  # parse normalize files and create source files for lookup and normalization  # parse normalize files and create source files for lookup and normalization
195    
196  my $parser = new WebPAC::Parser( config => $config );  my ($only_database,$only_input) = split(m#/#, $only_filter) if $only_filter;
197    
198    my $parser = new WebPAC::Parser(
199            config => $config,
200            only_database => $only_database,
201            only_input => $only_input,
202    );
203    
204  my $total_rows = 0;  my $total_rows = 0;
205  my $start_t = time();  my $start_t = time();
# Line 215  sub create_ds_config { Line 223  sub create_ds_config {
223  foreach my $database ( sort keys %{ $config->databases } ) {  foreach my $database ( sort keys %{ $config->databases } ) {
224          my $db_config = $config->databases->{$database};          my $db_config = $config->databases->{$database};
225    
         my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);  
226          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
227    
228          if ($parallel) {          if ($parallel) {
# Line 311  foreach my $database ( sort keys %{ $con Line 318  foreach my $database ( sort keys %{ $con
318    
319          foreach my $output ( @outputs ) {          foreach my $output ( @outputs ) {
320    
321  warn '## output = ',dump( $output );  #warn '## output = ',dump( $output );
322    
323                  my $module = $output->{module} || $log->logdie("need module in output section of $database");                  my $module = $output->{module} || $log->logdie("need module in output section of $database");
324                  $module = 'WebPAC::Output::' . $module unless $module =~ m/::/;                  $module = 'WebPAC::Output::' . $module unless $module =~ m/::/;
# Line 321  warn '## output = ',dump( $output ); Line 328  warn '## output = ',dump( $output );
328    
329                  # add database to arugemnts for output filter                  # add database to arugemnts for output filter
330                  $output->{database} = $database;                  $output->{database} = $database;
331                    $output->{clean} = $clean;
332    
333                  $log->debug("calling $module->new(",dump( $output ),")");                  $log->debug("calling $module->new(",dump( $output ),")");
334                  my $out = new $module->new( $output );                  my $out = new $module->new( $output );
335                  $out->init;                  if ( $out->init ) {
336                            push @output_modules, $out;
337                  push @output_modules, $out;                  } else {
338                            $log->warn("SKIPPED $module");
339                    }
340          }          }
341    
342    
# Line 347  warn '## output = ',dump( $output ); Line 357  warn '## output = ',dump( $output );
357    
358                  my $type = lc($input->{type});                  my $type = lc($input->{type});
359    
360                  die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs')));                  # FIXME check if input module exists
361                    my $input_module = $input->{module};
362    
363                  my $input_module = $config->webpac('inputs')->{$type};                  if ( ! $input_module ) {
364                            if ( grep(/$type/, $config->webpac('inputs')) ) {
365                                    $input_module = $config->webpac('inputs')->{$type};
366                            } else {
367                                    $log->logdie("I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!" );
368                            }
369                    }
370    
371                  my @lookups = $parser->have_lookup_create($database, $input);                  my @lookups = $parser->have_lookup_create($database, $input);
372    
373                  $log->info("working on input '$input_name' in $input->{path} [type: $input->{type}] using $input_module",                  $log->info("working on $database/$input_name with $input_module on $input->{path}",
374                          @lookups ? " creating lookups: ".join(", ", @lookups) : ""                          @lookups ? " creating lookups: ".join(", ", @lookups) : ""
375                  );                  );
376    
# Line 473  warn '## output = ',dump( $output ); Line 490  warn '## output = ',dump( $output );
490                          );                          );
491                  }                  }
492    
493                  my $rules = $parser->normalize_rules($database,$input_name) || $log->logdie("no normalize rules found for $database/$input_name");                  my $rules = $parser->normalize_rules($database,$input_name);
494                    $log->logwarn("no normalize rules for $database/$input_name") unless $rules;
495    
496                  $log->debug("parsed normalize rules:\n$rules");                  $log->debug("parsed normalize rules:\n$rules");
497    
498                  # reset position in database                  # reset position in database
# Line 543  warn '## output = ',dump( $output ); Line 562  warn '## output = ',dump( $output );
562                                  next;   # validation doesn't create any output                                  next;   # validation doesn't create any output
563                          }                          }
564    
565                          if ( my $ds = WebPAC::Normalize::data_structure(                          if ($rules) {
566                                  row => $row,  
567                                  rules => $rules,                                  my $ds = WebPAC::Normalize::data_structure(
568                                  lookup => $lookup_hash,                                          row => $row,
569                                  config => create_ds_config( $db_config, $database, $input, $mfn ),                                          rules => $rules,
570                                  marc_encoding => 'utf-8',                                          lookup => $lookup_hash,
571                                  load_row_coderef => sub {                                          config => create_ds_config( $db_config, $database, $input, $mfn ),
572                                          my ($database,$input,$mfn) = @_;                                          marc_encoding => 'utf-8',
573                                          return $store->load_row(                                          load_row_coderef => sub {
574                                                    my ($database,$input,$mfn) = @_;
575    #warn "### load_row($database,$input,$mfn) from data_structure\n";
576                                                    return $store->load_row(
577                                                            database => $database,
578                                                            input => $input,
579                                                            id => $mfn,
580                                                    );
581                                            },
582                                    );
583    
584                                    $log->debug("ds = ", sub { dump($ds) });
585    
586                                    if ( $ds ) {
587    
588                                            $store->save_ds(
589                                                  database => $database,                                                  database => $database,
590                                                  input => $input,                                                  input => $input_name,
591                                                  id => $mfn,                                                  id => $mfn,
592                                          );                                                  ds => $ds,
593                                  },                                          ) if !$stats;
                         ) ) { # if  
594    
595                                  $log->debug("ds = ", sub { dump($ds) });                                          $indexer->add(
596                                                    id => "${input_name}/${mfn}",
597                                                    ds => $ds,
598                                                    type => $config->get($indexer_config)->{type},
599                                            ) if $indexer;
600    
601                                  $store->save_ds(                                          foreach my $out ( @output_modules ) {
602                                          database => $database,                                                  $out->add( $mfn, $ds ) if $out->can('add');
                                         input => $input_name,  
                                         id => $mfn,  
                                         ds => $ds,  
                                 ) if !$stats;  
   
                                 $indexer->add(  
                                         id => "${input_name}/${mfn}",  
                                         ds => $ds,  
                                         type => $config->get($indexer_config)->{type},  
                                 ) if $indexer;  
   
                                 if ($marc) {  
                                         my $i = 0;  
   
                                         while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {  
                                                 $marc->add(  
                                                         id => $mfn . ( $i ? "/$i" : '' ),  
                                                         fields => $fields,  
                                                         leader => WebPAC::Normalize::_get_marc_leader(),  
                                                         row => $row,  
                                                 );  
                                                 $i++;  
603                                          }                                          }
604    
605                                          $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                                  } else {
606                                            $log->warn("record $pos didn't produce any output after normalization rules!") unless $marc;
607                                  }                                  }
608                            }
609    
610                                  foreach my $out ( @output_modules ) {                          if ($marc) {
611                                          $out->add( $mfn, $ds ) if $out->can('add');                                  my $i = 0;
612    
613                                    while (my $fields = WebPAC::Normalize::MARC::_get_marc_fields( fetch_next => 1 ) ) {
614                                            $marc->add(
615                                                    id => $mfn . ( $i ? "/$i" : '' ),
616                                                    fields => $fields,
617                                                    leader => WebPAC::Normalize::MARC::_get_marc_leader(),
618                                                    row => $row,
619                                            );
620                                            $i++;
621                                  }                                  }
622    
623                          } else {                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
                                 $log->warn("record $pos didn't produce any output after normalization rules!");  
624                          }                          }
625    
626                  }                  }

Legend:
Removed from v.956  
changed lines
  Added in v.1084

  ViewVC Help
Powered by ViewVC 1.1.26