[open-ils-commits] r18113 - trunk/Open-ILS/src/support-scripts (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Oct 1 01:24:42 EDT 2010


Author: dbs
Date: 2010-10-01 01:24:38 -0400 (Fri, 01 Oct 2010)
New Revision: 18113

Modified:
   trunk/Open-ILS/src/support-scripts/marc_export
Log:
Teach marc_export script how to export MFHD serial records

Passing the --mfhd flag will export any non-deleted MFHD records in
serial.record_entry associated with each bib ID. So, for a hypothetical set of
bib IDs 1, 2, 3, where 2 has no associated MFHD records and 3 has 2 MFHD records
associated with it, the output will be structured as follows:

Bib MARC for bib ID 1
MFHD MARC for bib ID 1
Bib MARC for bib ID 2
Bib MARC for bib ID 3
MFHD MARC for bib ID 3
MFHD MARC for bib ID 2


Modified: trunk/Open-ILS/src/support-scripts/marc_export
===================================================================
--- trunk/Open-ILS/src/support-scripts/marc_export	2010-10-01 05:16:41 UTC (rev 18112)
+++ trunk/Open-ILS/src/support-scripts/marc_export	2010-10-01 05:24:38 UTC (rev 18113)
@@ -10,6 +10,7 @@
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::Fieldmapper;
+use OpenILS::Utils::CStoreEditor;
 
 use MARC::Record;
 use MARC::File::XML;
@@ -21,11 +22,12 @@
 
 my @formats = qw/USMARC UNIMARC XML BRE/;
 
-my ($config,$format,$encoding,$location,$dollarsign,$idl,$help,$holdings,$timeout) = ('/openils/conf/opensrf_core.xml','USMARC','MARC8','','$',0,undef,undef,0);
+my ($config,$format,$encoding,$location,$dollarsign,$idl,$help,$holdings,$timeout,$export_mfhd) = ('/openils/conf/opensrf_core.xml','USMARC','MARC8','','$',0,undef,undef,0,undef);
 
 GetOptions(
         'help'       => \$help,
         'items'      => \$holdings,
+        'mfhd'       => \$export_mfhd,
         'location=s' => \$location,
         'money=s'    => \$dollarsign,
         'config=s'   => \$config,
@@ -40,9 +42,11 @@
 Usage: $0 [options]
  --help or -h       This screen.
  --config or -c     Configuration file [/openils/conf/opensrf_core.xml]
- --format or -f     Output format (USMARC, UNIMARC, XML) [USMARC]
+ --format or -f     Output format (USMARC, UNIMARC, XML, BRE) [USMARC]
  --encoding or -e   Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8]
  --items or -i      Include items (holdings) in the output
+ --mfhd             Export serial MFHD records for associated bib records
+                    Not compatible with --format=BRE
  --xml-idl or -x    Location of the IDL XML
  --location or -l   MARC Location Code for holdings from
                     http://www.loc.gov/marc/organizations/orgshome.html
@@ -91,6 +95,8 @@
 Fieldmapper->import(IDL => $idl);
 
 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
+OpenILS::Utils::CStoreEditor::init();
+my $editor = OpenILS::Utils::CStoreEditor->new();
 
 print <<HEADER if ($format eq 'XML');
 <?xml version="1.0" encoding="$encoding"?>
@@ -222,6 +228,29 @@
         import MARC::File::XML; # reset SAX parser so that one bad record doesn't kill the entire export
     };
 
+    if ($export_mfhd) {
+        my $mfhds = $editor->search_serial_record_entry({record => $i, deleted => 'f'});
+        foreach my $mfhd (@$mfhds) {
+            try {
+                my $r = MARC::Record->new_from_xml( $mfhd->marc, $encoding, $format );
+
+                if (uc($format) eq 'XML') {
+                    my $xml = $r->as_xml_record;
+                    $xml =~ s/^<\?.+?\?>$//mo;
+                    print $xml;
+                } elsif (uc($format) eq 'UNIMARC') {
+                    print $r->as_usmarc;
+                } elsif (uc($format) eq 'USMARC') {
+                    print $r->as_usmarc;
+                }
+            } otherwise {
+                my $e = shift;
+                warn "\n$e\n";
+                import MARC::File::XML; # reset SAX parser so that one bad record doesn't kill the entire export
+            };
+        }
+    }
+
     stats() if (! ($count{bib} % 50 ));
 }
 



More information about the open-ils-commits mailing list