JBAS-1437 Backstage importer --marc-file option
authorBill Erickson <berickxx@gmail.com>
Wed, 7 Dec 2016 15:20:11 +0000 (10:20 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <berickxx@gmail.com>
KCLS/authority-control/backstage/README.adoc
KCLS/authority-control/backstage/process-backstage-files.pl

index 0f834ea..1f950b6 100644 (file)
@@ -55,7 +55,7 @@ cd /home/opensrf/Evergreen/KCLS/backstage/
 ./process-backstage-files.pl \
     --verbose \
     --export-date $EXPORT_DATE \
-    --file $WORKING_DIR/<results-file> \
+    --zip-file $WORKING_DIR/<results-file> \
     --working-dir $WORKING_DIR \
     --bib-collision-file bib-collisions.mrc \
     > $WORKING_DIR/process.log
index 364461e..c034846 100755 (executable)
@@ -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;