/[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 664 by dpavlin, Mon Sep 11 11:57:18 2006 UTC revision 698 by dpavlin, Mon Sep 25 11:14:53 2006 UTC
# Line 7  use File::Temp qw/tempdir/; Line 7  use File::Temp qw/tempdir/;
7  use lib './lib';  use lib './lib';
8    
9  use WebPAC::Common 0.02;  use WebPAC::Common 0.02;
10    use WebPAC::Parser 0.04;
11  use WebPAC::Lookup 0.03;  use WebPAC::Lookup 0.03;
12  use WebPAC::Input 0.11;  use WebPAC::Input 0.11;
13  use WebPAC::Store 0.03;  use WebPAC::Store 0.03;
# Line 14  use WebPAC::Normalize 0.11; Line 15  use WebPAC::Normalize 0.11;
15  use WebPAC::Output::TT;  use WebPAC::Output::TT;
16  use WebPAC::Validate 0.06;  use WebPAC::Validate 0.06;
17  use WebPAC::Output::MARC;  use WebPAC::Output::MARC;
18  use YAML qw/LoadFile/;  use WebPAC::Config;
19  use Getopt::Long;  use Getopt::Long;
20  use File::Path;  use File::Path;
21  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
# Line 105  my $offset; Line 106  my $offset;
106  my $limit;  my $limit;
107    
108  my $clean = 0;  my $clean = 0;
109  my $config = 'conf/config.yml';  my $config_path;
110  my $debug = 0;  my $debug = 0;
111  my $only_filter;  my $only_filter;
112  my $stats = 0;  my $stats = 0;
# Line 119  my $merge = 0; Line 120  my $merge = 0;
120    
121  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
122    
 my $hostname = `hostname`;  
 chomp($hostname);  
 $hostname =~ s/\..+$//;  
 if (-e "conf/$hostname.yml") {  
         $config = "conf/$hostname.yml";  
         $log->info("using host configuration file: $config");  
 }  
   
123  GetOptions(  GetOptions(
124          "limit=i" => \$limit,          "limit=i" => \$limit,
125          "offset=i" => \$offset,          "offset=i" => \$offset,
126          "clean" => \$clean,          "clean" => \$clean,
127          "one=s" => \$only_filter,          "one=s" => \$only_filter,
128          "only=s" => \$only_filter,          "only=s" => \$only_filter,
129          "config" => \$config,          "config" => \$config_path,
130          "debug+" => \$debug,          "debug+" => \$debug,
131          "stats" => \$stats,          "stats" => \$stats,
132          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
# Line 146  GetOptions( Line 139  GetOptions(
139          "merge" => \$merge,          "merge" => \$merge,
140  );  );
141    
142  $config = LoadFile($config);  my $config = new WebPAC::Config( path => $config_path );
143    
144  #print "config = ",dump($config) if ($debug);  #print "config = ",dump($config) if ($debug);
145    
146  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->databases);
147    
148  $log->info( "-" x 79 );  $log->info( "-" x 79 );
149    
# Line 171  $validate = new WebPAC::Validate( Line 164  $validate = new WebPAC::Validate(
164  ) if ($validate_path);  ) if ($validate_path);
165    
166    
167  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->use_indexer;
168  if ($stats) {  if ($stats) {
169          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
170          $use_indexer = undef;          $use_indexer = undef;
# Line 182  if ($stats) { Line 175  if ($stats) {
175  # disable indexing when creating marc  # disable indexing when creating marc
176  $use_indexer = undef if ($marc_normalize);  $use_indexer = undef if ($marc_normalize);
177    
178    # parse normalize files and create source files for lookup and normalization
179    
180    my $parser = new WebPAC::Parser( config => $config );
181    
182  my $total_rows = 0;  my $total_rows = 0;
183  my $start_t = time();  my $start_t = time();
184    
# Line 192  if ($parallel) { Line 189  if ($parallel) {
189          Proc::Queue::size($parallel);          Proc::Queue::size($parallel);
190  }  }
191    
192  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->databases }) {
193    
194          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
195          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
# Line 212  while (my ($database, $db_config) = each Line 209  while (my ($database, $db_config) = each
209                  my $cfg_name = $use_indexer;                  my $cfg_name = $use_indexer;
210                  $cfg_name =~ s/\-.*$//;                  $cfg_name =~ s/\-.*$//;
211    
212                  my $indexer_config = $config->{$cfg_name} || $log->logdie("can't find '$cfg_name' part in confguration");                  my $indexer_config = $config->get( $cfg_name ) || $log->logdie("can't find '$cfg_name' part in confguration");
213                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
214                  $indexer_config->{clean} = $clean;                  $indexer_config->{clean} = $clean;
215                  $indexer_config->{label} = $db_config->{name};                  $indexer_config->{label} = $db_config->{name};
# Line 232  while (my ($database, $db_config) = each Line 229  while (my ($database, $db_config) = each
229                          use WebPAC::Output::EstraierNative;                          use WebPAC::Output::EstraierNative;
230                          $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } );                          $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } );
231    
                         $use_indexer = 'hyperestraier';  
   
232                  } elsif ($use_indexer eq 'kinosearch') {                  } elsif ($use_indexer eq 'kinosearch') {
233    
234                          # open KinoSearch                          # open KinoSearch
# Line 282  while (my ($database, $db_config) = each Line 277  while (my ($database, $db_config) = each
277          my $abs_path = abs_path($0);          my $abs_path = abs_path($0);
278          $abs_path =~ s#/[^/]*$#/#;          $abs_path =~ s#/[^/]*$#/#;
279    
280          my $db_path = $config->{webpac}->{db_path} . '/' . $database;          my $db_path = $config->get('webpac')->{db_path} . '/' . $database;
281    
282          if ($clean) {          if ($clean) {
283                  $log->info("creating new database '$database' in $db_path");                  $log->info("creating new database '$database' in $db_path");
# Line 311  while (my ($database, $db_config) = each Line 306  while (my ($database, $db_config) = each
306                  $log->info("database $database doesn't have inputs defined");                  $log->info("database $database doesn't have inputs defined");
307          }          }
308    
         my @supported_inputs = keys %{ $config->{webpac}->{inputs} };  
   
309          foreach my $input (@inputs) {          foreach my $input (@inputs) {
310    
311                  next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));                  next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
312    
313                  my $type = lc($input->{type});                  my $type = lc($input->{type});
314    
315                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));                  die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs')));
   
                 my $lookup;  
                 if ($input->{lookup}) {  
                         $lookup = new WebPAC::Lookup(  
                                 lookup_file => $input->{lookup},  
                         );  
                         delete( $input->{lookup} );  
                 }  
316    
317                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->webpac('inputs')->{$type};
318    
319                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",
320                          $input->{lookup} ? "lookup '$input->{lookup}'" : ""                          $input->{lookup} ? "lookup '$input->{lookup}'" : ""
# Line 341  while (my ($database, $db_config) = each Line 326  while (my ($database, $db_config) = each
326                          delete($input->{modify_file});                          delete($input->{modify_file});
327                  }                  }
328    
329                    warn "depends on: ", dump( $parser->depends($database, $input->{name}), $parser->{depends}, $parser->lookup_create_rules($database, $input->{name}), $parser->{_lookup_create} );
330    
331                    my $lookup;
332    
333                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
334                          module => $input_module,                          module => $input_module,
335                          encoding => $config->{webpac}->{webpac_encoding},                          encoding => $config->webpac('webpac_encoding'),
336                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
337                          offset => $offset,                          offset => $offset,
338                          lookup_coderef => sub {                          lookup_coderef => sub {
# Line 363  while (my ($database, $db_config) = each Line 352  while (my ($database, $db_config) = each
352                          %{ $input },                          %{ $input },
353                  );                  );
354    
355                    my $report_fh;
356                    if ($stats || $validate) {
357                            my $path = "out/report/" . $database . '-' . $input->{name} . '.txt';
358                            open($report_fh, '>', $path) || $log->logdie("can't open $path: $!");
359    
360                            print $report_fh "Report for database '$database' input '$input->{name}' records ",
361                                    $offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n";
362                            $log->info("Generating report file $path");
363                    }
364    
365                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?
366                          @{ $input->{normalize} } : ( $input->{normalize} );                          @{ $input->{normalize} } : ( $input->{normalize} );
367    
# Line 392  while (my ($database, $db_config) = each Line 391  while (my ($database, $db_config) = each
391                          # reset position in database                          # reset position in database
392                          $input_db->seek(1);                          $input_db->seek(1);
393    
394                            # generate name of config key for indexer (strip everything after -)
395                            my $indexer_config = $use_indexer;
396                            $indexer_config =~ s/^(\w+)-?.*$/$1/g if ($indexer_config);
397    
398                          foreach my $pos ( 0 ... $input_db->size ) {                          foreach my $pos ( 0 ... $input_db->size ) {
399    
400                                  my $row = $input_db->fetch || next;                                  my $row = $input_db->fetch || next;
# Line 408  while (my ($database, $db_config) = each Line 411  while (my ($database, $db_config) = each
411                                  if ($validate) {                                  if ($validate) {
412                                          if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {                                          if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {
413                                                  $log->error( "MFN $mfn validation error:\n",                                                  $log->error( "MFN $mfn validation error:\n",
414                                                          dump( $errors )                                                          $validate->report_error( $errors )
415                                                  );                                                  );
416                                          }                                          }
417                                  }                                  }
# Line 441  while (my ($database, $db_config) = each Line 444  while (my ($database, $db_config) = each
444                                  $indexer->add(                                  $indexer->add(
445                                          id => $input->{name} . "/" . $mfn,                                          id => $input->{name} . "/" . $mfn,
446                                          ds => $ds,                                          ds => $ds,
447                                          type => $config->{$use_indexer}->{type},                                          type => $config->get($indexer_config)->{type},
448                                  ) if ($indexer && $ds);                                  ) if ($indexer && $ds);
449    
450                                  if ($marc) {                                  if ($marc) {
# Line 465  while (my ($database, $db_config) = each Line 468  while (my ($database, $db_config) = each
468    
469                          if ($validate) {                          if ($validate) {
470                                  my $errors = $validate->report;                                  my $errors = $validate->report;
471                                  $log->info("validation errors:\n$errors\n" ) if ($errors);                                  if ($errors) {
472                                            $log->info("validation errors:\n$errors\n" );
473                                            print $report_fh "$errors\n" if ($report_fh);
474                                    }
475                          }                          }
476    
477                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          if ($stats) {
478                                    my $s = $input_db->stats;
479                                    $log->info("statistics of fields usage:\n$s");
480                                    print $report_fh "Statistics of fields usage:\n$s" if ($report_fh);
481                            }
482    
483                          # close MARC file                          # close MARC file
484                          $marc->finish if ($marc);                          $marc->finish if ($marc);
485    
486                            # close report
487                            close($report_fh) if ($report_fh)
488                  }                  }
489    
490          }          }

Legend:
Removed from v.664  
changed lines
  Added in v.698

  ViewVC Help
Powered by ViewVC 1.1.26