--- trunk/run.pl 2006/06/30 20:43:18 552 +++ trunk/run.pl 2006/07/01 20:29:09 556 @@ -4,7 +4,6 @@ use Cwd qw/abs_path/; use File::Temp qw/tempdir/; -use Data::Dumper; use lib './lib'; use WebPAC::Common 0.02; @@ -20,6 +19,8 @@ use Time::HiRes qw/time/; use File::Slurp; use MARC::Record 2.0; # need 2.0 for utf-8 encoding see marcpm.sf.net +use MARC::Lint; +use Data::Dump qw/dump/; =head1 NAME @@ -71,6 +72,11 @@ Optional path to output file +=item --marc-lint + +By default turned on if C<--marc-normalize> is used. You can disable lint +messages with C<--no-arc-lint>. + =back =cut @@ -85,6 +91,7 @@ my $stats = 0; my $validate_path; my ($marc_normalize, $marc_output); +my $marc_lint = 1; GetOptions( "limit=i" => \$limit, @@ -98,11 +105,12 @@ "validate=s" => \$validate_path, "marc-normalize=s" => \$marc_normalize, "marc-output=s" => \$marc_output, + "marc-lint!" => \$marc_lint, ); $config = LoadFile($config); -print "config = ",Dumper($config) if ($debug); +print "config = ",dump($config) if ($debug); die "no databases in config file!\n" unless ($config->{databases}); @@ -131,6 +139,8 @@ my @links; my $indexer; +my $lint = new MARC::Lint if ($marc_lint); + while (my ($database, $db_config) = each %{ $config->{databases} }) { my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); @@ -260,7 +270,7 @@ open($marc_fh, '>', $path) || $log->logdie("can't open MARC output $path: $!"); - $log->info("Creating MARC export file $path\n"); + $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n"); } # reset position in database @@ -307,8 +317,22 @@ if ($marc_fh) { my $marc = new MARC::Record; $marc->encoding( 'utf-8' ); - $marc->add_fields( WebPAC::Normalize::_get_marc_fields() ); - print $marc_fh $marc->as_usmarc; + my @marc_fields = WebPAC::Normalize::_get_marc_fields(); + if (! @marc_fields) { + $log->warn("MARC record $mfn is empty, skipping"); + } else { + $marc->add_fields( @marc_fields ); + if ($marc_lint) { + $lint->check_record( $marc ); + my $err = join( "\n", $lint->warnings ); + $log->error("MARC lint detected warning on MFN $mfn\n", + "Original imput row: ",dump($row), "\n", + "Normalized MARC row: ",dump(@marc_fields), "\n", + "MARC lint warnings: ",$err,"\n" + ) if ($err); + } + print $marc_fh $marc->as_usmarc; + } } $total_rows++;