From 41bb03a721b1aeb25295324854068ebdf60e5286 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 7 Dec 2016 10:20:11 -0500 Subject: [PATCH] JBAS-1437 Backstage importer --marc-file option Importer now supports processing a single MARC file in addition to ZIP files as before. Zip file option is now specified via --zip-file. Signed-off-by: Bill Erickson --- KCLS/authority-control/backstage/README.adoc | 2 +- .../backstage/process-backstage-files.pl | 51 ++++++++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/KCLS/authority-control/backstage/README.adoc b/KCLS/authority-control/backstage/README.adoc index 0f834eaada..1f950b6254 100644 --- a/KCLS/authority-control/backstage/README.adoc +++ b/KCLS/authority-control/backstage/README.adoc @@ -55,7 +55,7 @@ cd /home/opensrf/Evergreen/KCLS/backstage/ ./process-backstage-files.pl \ --verbose \ --export-date $EXPORT_DATE \ - --file $WORKING_DIR/ \ + --zip-file $WORKING_DIR/ \ --working-dir $WORKING_DIR \ --bib-collision-file bib-collisions.mrc \ > $WORKING_DIR/process.log diff --git a/KCLS/authority-control/backstage/process-backstage-files.pl b/KCLS/authority-control/backstage/process-backstage-files.pl index 364461e281..c034846b2d 100755 --- a/KCLS/authority-control/backstage/process-backstage-files.pl +++ b/KCLS/authority-control/backstage/process-backstage-files.pl @@ -22,7 +22,8 @@ binmode(STDOUT, ':utf8'); my $db_handle; my $log_mod = 500; # log every 500th of each type of event (see verbose) -my $file; +my $marc_file; +my $zip_file; my $export_date; my $working_dir = '.', my $bib_collision_file; @@ -53,7 +54,8 @@ my $col_bibs_ctr = 0; my $help; GetOptions( - 'file=s' => \$file, + 'marc-file=s' => \$marc_file, + 'zip-file=s' => \$zip_file, 'export-date=s' => \$export_date, 'working-dir=s' => \$working_dir, 'bib-collision-file=s' => \$bib_collision_file, @@ -81,7 +83,11 @@ Options avoid losing change made by staff since the export. --file - Full path to ZIP file to process. + Full path to a single bib or authority MARC file. + + --zip-file + Full path to a ZIP file containing multiple authority and bib + MARC files to process. --working-dir Directory where constituent files are extracted. @@ -106,7 +112,7 @@ HELP die "required: --export-date YYYY-MM-DD\n" unless $export_date && $export_date =~ /^\d{4}-\d{2}-\d{2}$/; -die "--file required\n" unless $file; +die "--marc-file or --zip-file required\n" unless ($marc_file || $zip_file); # Log every occurrence of each event type. $log_mod = 1 if $verbose; @@ -149,8 +155,8 @@ sub process_zip_file { my $zip = Archive::Zip->new(); - announce('ERR', "Failed to read $file", 1) - unless $zip->read($file) == AZ_OK; + announce('ERR', "Failed to read $zip_file", 1) + unless $zip->read($zip_file) == AZ_OK; # Avoid processing XLS and HTM files. # All of the MARC files end in .UTF8. @@ -165,24 +171,32 @@ sub process_zip_file { announce('ERR', "Unable to extract to file: $local_file", 1) unless $member->extractToFileNamed($local_file) == AZ_OK; - my $marc_batch = MARC::File::USMARC->in($local_file, 'UTF8') - or announce('ERR', "Unable to read $local_file as MARC", 1); + process_marc_file($local_file); + } +} - if ($basename =~ /BIB/) { +sub process_marc_file { + my $local_file = shift; + my $basename = basename($local_file); - handle_modified_bibs($marc_batch); + my $marc_batch = MARC::File::USMARC->in($local_file, 'UTF8') + or announce('ERR', "Unable to read $local_file as MARC", 1); - } elsif ($basename =~ /DEL/) { + if ($basename =~ /BIB/) { - handle_deleted_auths($marc_batch); + handle_modified_bibs($marc_batch); - } elsif ($basename =~ /CHG|NEW|AUTH/) { + } elsif ($basename =~ /DEL/) { - handle_modified_auths($marc_batch); + handle_deleted_auths($marc_batch); - } else { - announce('WARNING', "Un-handled file type: $basename"); - } + } elsif ($basename =~ /CHG|NEW|AUTH/) { + + handle_modified_auths($marc_batch); + + } else { + + announce('WARNING', "Unknown file type: $basename"); } } @@ -490,7 +504,8 @@ sub prepare_statements { openlog($syslog_ident, $syslog_ops, $syslog_facility); connect_db(); prepare_statements(); -process_zip_file(); +process_zip_file() if $zip_file; +process_marc_file($marc_file) if $marc_file; $new_auth_sth->finish; $mod_auth_sth->finish; -- 2.11.0