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; |
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 |
|
|
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 |
=back |
=back |
81 |
|
|
82 |
=cut |
=cut |
91 |
my $stats = 0; |
my $stats = 0; |
92 |
my $validate_path; |
my $validate_path; |
93 |
my ($marc_normalize, $marc_output); |
my ($marc_normalize, $marc_output); |
94 |
|
my $marc_lint = 1; |
95 |
|
|
96 |
GetOptions( |
GetOptions( |
97 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
105 |
"validate=s" => \$validate_path, |
"validate=s" => \$validate_path, |
106 |
"marc-normalize=s" => \$marc_normalize, |
"marc-normalize=s" => \$marc_normalize, |
107 |
"marc-output=s" => \$marc_output, |
"marc-output=s" => \$marc_output, |
108 |
|
"marc-lint!" => \$marc_lint, |
109 |
); |
); |
110 |
|
|
111 |
$config = LoadFile($config); |
$config = LoadFile($config); |
112 |
|
|
113 |
print "config = ",Dumper($config) if ($debug); |
print "config = ",dump($config) if ($debug); |
114 |
|
|
115 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
116 |
|
|
139 |
my @links; |
my @links; |
140 |
my $indexer; |
my $indexer; |
141 |
|
|
142 |
|
my $lint = new MARC::Lint if ($marc_lint); |
143 |
|
|
144 |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
145 |
|
|
146 |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
270 |
open($marc_fh, '>', $path) || |
open($marc_fh, '>', $path) || |
271 |
$log->logdie("can't open MARC output $path: $!"); |
$log->logdie("can't open MARC output $path: $!"); |
272 |
|
|
273 |
$log->info("Creating MARC export file $path\n"); |
$log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n"); |
274 |
} |
} |
275 |
|
|
276 |
# reset position in database |
# reset position in database |
317 |
if ($marc_fh) { |
if ($marc_fh) { |
318 |
my $marc = new MARC::Record; |
my $marc = new MARC::Record; |
319 |
$marc->encoding( 'utf-8' ); |
$marc->encoding( 'utf-8' ); |
320 |
$marc->add_fields( WebPAC::Normalize::_get_marc_fields() ); |
my @marc_fields = WebPAC::Normalize::_get_marc_fields(); |
321 |
print $marc_fh $marc->as_usmarc; |
if (! @marc_fields) { |
322 |
|
$log->warn("MARC record $mfn is empty, skipping"); |
323 |
|
} else { |
324 |
|
$marc->add_fields( @marc_fields ); |
325 |
|
if ($marc_lint) { |
326 |
|
$lint->check_record( $marc ); |
327 |
|
my $err = join( "\n", $lint->warnings ); |
328 |
|
$log->error("MARC lint detected warning on MFN $mfn\n", |
329 |
|
"Original imput row: ",dump($row), "\n", |
330 |
|
"Normalized MARC row: ",dump(@marc_fields), "\n", |
331 |
|
"MARC lint warnings: ",$err,"\n" |
332 |
|
) if ($err); |
333 |
|
} |
334 |
|
print $marc_fh $marc->as_usmarc; |
335 |
|
} |
336 |
} |
} |
337 |
|
|
338 |
$total_rows++; |
$total_rows++; |