/[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 552 by dpavlin, Fri Jun 30 20:43:18 2006 UTC revision 560 by dpavlin, Sun Jul 2 14:40:32 2006 UTC
# Line 4  use strict; Line 4  use strict;
4    
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
 use Data::Dumper;  
7  use lib './lib';  use lib './lib';
8    
9  use WebPAC::Common 0.02;  use WebPAC::Common 0.02;
# Line 20  use File::Path; Line 19  use File::Path;
19  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
20  use File::Slurp;  use File::Slurp;
21  use MARC::Record 2.0;   # need 2.0 for utf-8 encoding see marcpm.sf.net  use MARC::Record 2.0;   # need 2.0 for utf-8 encoding see marcpm.sf.net
22    use MARC::Lint;
23    use Data::Dump qw/dump/;
24    
25  =head1 NAME  =head1 NAME
26    
# Line 71  This option specifies normalisation file Line 72  This option specifies normalisation file
72    
73  Optional path to output file  Optional path to output file
74    
75    =item --marc-lint
76    
77    By default turned on if C<--marc-normalize> is used. You can disable lint
78    messages with C<--no-marc-lint>.
79    
80    =item --marc-dump
81    
82    Force dump or input and marc record for debugging.
83    
84  =back  =back
85    
86  =cut  =cut
# Line 85  my $only_filter; Line 95  my $only_filter;
95  my $stats = 0;  my $stats = 0;
96  my $validate_path;  my $validate_path;
97  my ($marc_normalize, $marc_output);  my ($marc_normalize, $marc_output);
98    my $marc_lint = 1;
99    my $marc_dump = 0;
100    
101  GetOptions(  GetOptions(
102          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 93  GetOptions( Line 105  GetOptions(
105          "one=s" => \$only_filter,          "one=s" => \$only_filter,
106          "only=s" => \$only_filter,          "only=s" => \$only_filter,
107          "config" => \$config,          "config" => \$config,
108          "debug" => \$debug,          "debug+" => \$debug,
109          "stats" => \$stats,          "stats" => \$stats,
110          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
111          "marc-normalize=s" => \$marc_normalize,          "marc-normalize=s" => \$marc_normalize,
112          "marc-output=s" => \$marc_output,          "marc-output=s" => \$marc_output,
113            "marc-lint!" => \$marc_lint,
114            "marc-dump!" => \$marc_dump,
115  );  );
116    
117  $config = LoadFile($config);  $config = LoadFile($config);
118    
119  print "config = ",Dumper($config) if ($debug);  print "config = ",dump($config) if ($debug);
120    
121  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
122    
# Line 131  my $start_t = time(); Line 145  my $start_t = time();
145  my @links;  my @links;
146  my $indexer;  my $indexer;
147    
148    my $lint = new MARC::Lint if ($marc_lint);
149    
150  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
151    
152          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
# Line 260  while (my ($database, $db_config) = each Line 276  while (my ($database, $db_config) = each
276                                  open($marc_fh, '>', $path) ||                                  open($marc_fh, '>', $path) ||
277                                          $log->logdie("can't open MARC output $path: $!");                                          $log->logdie("can't open MARC output $path: $!");
278    
279                                  $log->info("Creating MARC export file $path\n");                                  $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n");
280                          }                          }
281    
282                          # reset position in database                          # reset position in database
# Line 284  while (my ($database, $db_config) = each Line 300  while (my ($database, $db_config) = each
300                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
301                                  }                                  }
302    
                                           
303                                  my $ds = WebPAC::Normalize::data_structure(                                  my $ds = WebPAC::Normalize::data_structure(
304                                          row => $row,                                          row => $row,
305                                          rules => $rules,                                          rules => $rules,
# Line 307  while (my ($database, $db_config) = each Line 322  while (my ($database, $db_config) = each
322                                  if ($marc_fh) {                                  if ($marc_fh) {
323                                          my $marc = new MARC::Record;                                          my $marc = new MARC::Record;
324                                          $marc->encoding( 'utf-8' );                                          $marc->encoding( 'utf-8' );
325                                          $marc->add_fields( WebPAC::Normalize::_get_marc_fields() );                                          my @marc_fields = WebPAC::Normalize::_get_marc_fields();
326                                          print $marc_fh $marc->as_usmarc;                                          if (! @marc_fields) {
327                                                    $log->warn("MARC record $mfn is empty, skipping");
328                                            } else {
329                                                    $marc->add_fields( @marc_fields );
330    
331                                                    if ($marc_lint) {
332                                                            $lint->check_record( $marc );
333                                                            my $err = join( "\n", $lint->warnings );
334                                                            $log->error("MARC lint detected warning on MFN $mfn\n",
335                                                                    "Original imput row: ",dump($row), "\n",
336                                                                    "Normalized MARC row: ",dump(@marc_fields), "\n",
337                                                                    "MARC lint warnings: ",$err,"\n"
338                                                            ) if ($err);
339                                                    }
340    
341                                                    if ($marc_dump) {
342                                                            $log->info("MARC record on MFN $mfn\n",
343                                                                    "Original imput row: ",dump($row), "\n",
344                                                                    "Normalized MARC row: ",dump(@marc_fields), "\n",
345                                                            );
346                                                    }
347    
348                                                    print $marc_fh $marc->as_usmarc;
349                                            }
350                                  }                                  }
351    
352                                  $total_rows++;                                  $total_rows++;

Legend:
Removed from v.552  
changed lines
  Added in v.560

  ViewVC Help
Powered by ViewVC 1.1.26