added --marcxml flag
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Dec 2017 08:03:36 +0000 (09:03 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Dec 2017 08:03:36 +0000 (09:03 +0100)
lib/WebPAC/Output/MARC.pm
run.pl

index 00de7cf..97500e1 100644 (file)
@@ -37,6 +37,7 @@ L<WebPAC::Normalize>.
        marc_encoding => 'utf-8',
        lint => 1,
        dump => 0,
        marc_encoding => 'utf-8',
        lint => 1,
        dump => 0,
+       marcxml => 0,
   )
 
 =cut
   )
 
 =cut
@@ -56,13 +57,15 @@ sub new {
        $self->{marc_encoding} ||= 'utf-8';
 
        if (my $path = $self->{path}) {
        $self->{marc_encoding} ||= 'utf-8';
 
        if (my $path = $self->{path}) {
-               open($self->{fh}, '>', $path) ||
+               open($self->{fh}, '>', $path . '.marc') ||
                        $log->logdie("can't open MARC output $path: $!");
                binmode($self->{fh}, ':utf8');
 
                        $log->logdie("can't open MARC output $path: $!");
                binmode($self->{fh}, ':utf8');
 
-               $log->info("Creating MARC export file $path", $self->{lint} ? ' (with lint)' : '', " encoding ", $self->{marc_encoding}, "\n");
-               if ( $ENV{MARCXML} ) {
-                       open($self->{fh_marcxml}, '>:utf8', "$path.marcxml");
+               $log->info("Creating MARC export file $path.marc", $self->{lint} ? ' (with lint)' : '', " encoding ", $self->{marc_encoding}, "\n");
+               if ( $self->{marcxml} || $ENV{MARCXML} ) {
+                       open($self->{fh_marcxml}, '>:utf8', "$path.marcxml") ||
+                               $log->logdie("can't open MARCXML output $path.marcxml: $!");
+                       $log->info("Creating MARCXML export file $path.marcxml");
                        print {$self->{fh_marcxml}} qq{<?xml version="1.0" encoding="UTF-8"?>\n<collection>\n};
                }
        } else {
                        print {$self->{fh_marcxml}} qq{<?xml version="1.0" encoding="UTF-8"?>\n<collection>\n};
                }
        } else {
@@ -179,11 +182,11 @@ sub finish {
 
        my $log = $self->get_logger;
 
 
        my $log = $self->get_logger;
 
-       close( $self->{fh} ) or $log->logdie("can't close ", $self->{path}, ": $!");
+       close( $self->{fh} ) or $log->logdie("can't close ", $self->{path}, ".marc: $!");
 
        if ( $self->{fh_marcxml} ) {
                print {$self->{fh_marcxml}} qq{</collection>\n};
 
        if ( $self->{fh_marcxml} ) {
                print {$self->{fh_marcxml}} qq{</collection>\n};
-               $log->info("MARCXML file size ", -s $self->{fh_marcxml}, " bytes");
+               $log->info("MARCXML file ", $self->{path}, ".marcxml ", -s $self->{fh_marcxml}, " bytes");
                close( $self->{fh_marcxml} );
        }
        if (my $w = $self->{_marc_lint_warnings}) {
                close( $self->{fh_marcxml} );
        }
        if (my $w = $self->{_marc_lint_warnings}) {
diff --git a/run.pl b/run.pl
index 5560537..a8c4e70 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -86,6 +86,10 @@ You can use this option as C<--no-marc-generate> to disable MARC generation.
 By default turned on if normalisation file has C<marc*> directives. You can disable lint
 messages with C<--no-marc-lint>.
 
 By default turned on if normalisation file has C<marc*> directives. You can disable lint
 messages with C<--no-marc-lint>.
 
+=item --marc-xml
+
+Creeate MARCXML file (this can be quite large)
+
 =item --marc-dump
 
 Force dump or input and marc record for debugging.
 =item --marc-dump
 
 Force dump or input and marc record for debugging.
@@ -122,8 +126,9 @@ my $stats = 0;
 my $validate_path;
 my $validate_delimiters_path;
 my $marc_generate = 1;
 my $validate_path;
 my $validate_delimiters_path;
 my $marc_generate = 1;
-my $marc_lint = 1;
+my $marc_lint = 0;
 my $marc_dump = 0;
 my $marc_dump = 0;
+my $marc_xml = 0;
 my $parallel = 0;
 my $only_links = 0;
 my $merge = 0;
 my $parallel = 0;
 my $only_links = 0;
 my $merge = 0;
@@ -146,6 +151,7 @@ GetOptions(
        "marc-generate!" => \$marc_generate,
        "marc-lint!" => \$marc_lint,
        "marc-dump!" => \$marc_dump,
        "marc-generate!" => \$marc_generate,
        "marc-lint!" => \$marc_lint,
        "marc-dump!" => \$marc_dump,
+       "marcxml!" => \$marc_xml,
        "parallel=i" => \$parallel,
        "only-links!" => \$only_links,
        "merge" => \$merge,
        "parallel=i" => \$parallel,
        "only-links!" => \$only_links,
        "merge" => \$merge,
@@ -535,9 +541,10 @@ foreach my $database ( sort keys %{ $config->databases } ) {
                        mkpath $out_marc unless -e $out_marc;
 
                        $marc = new WebPAC::Output::MARC(
                        mkpath $out_marc unless -e $out_marc;
 
                        $marc = new WebPAC::Output::MARC(
-                               path => "$out_marc/${database}-${input_name}.marc",
+                               path => "$out_marc/${database}-${input_name}",
                                lint => $marc_lint,
                                dump => $marc_dump,
                                lint => $marc_lint,
                                dump => $marc_dump,
+                               marcxml => $marc_xml,
                        );
                }
 
                        );
                }