[open-ils-commits] r20240 - branches/rel_2_1/Open-ILS/src/support-scripts (gmc)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Apr 20 10:50:15 EDT 2011


Author: gmc
Date: 2011-04-20 10:50:13 -0400 (Wed, 20 Apr 2011)
New Revision: 20240

Modified:
   branches/rel_2_1/Open-ILS/src/support-scripts/marc_export
Log:
Teach marc_export how to export bibs for specified libraries

Useful shortcut for getting the bibs for libraries based on the
non-deleted callnumbers they have attached to non-deleted bibs.
Doesn't guarantee that they also have either a visible copy or
localized URI attached but whaddya want, magic? :)

Usage: marc_export --library BR1 --library BR2

Signed-off-by: Galen Charlton <gmc at esilibrary.com>

Modified: branches/rel_2_1/Open-ILS/src/support-scripts/marc_export
===================================================================
--- branches/rel_2_1/Open-ILS/src/support-scripts/marc_export	2011-04-20 14:50:11 UTC (rev 20239)
+++ branches/rel_2_1/Open-ILS/src/support-scripts/marc_export	2011-04-20 14:50:13 UTC (rev 20240)
@@ -36,6 +36,7 @@
 my $type = 'biblio';
 my $all_records = undef;
 my $replace_001 = undef;
+my @library = ();
 
 GetOptions(
         'help'       => \$help,
@@ -51,6 +52,7 @@
         'xml-idl=s'  => \$idl,
         'encoding=s' => \$encoding,
         'timeout=i'  => \$timeout,
+        'library=s'  => \@library,
 );
 
 if ($help) {
@@ -79,6 +81,9 @@
                     have a lot of items attached to them.
  --type or -t       Record type (BIBLIO, AUTHORITY) [BIBLIO]
  --all or -a        Export all records; ignores input list
+ --library          Export the bibliographic records that have attached
+                    holdings for the listed library or libraries as
+                    identified by shortname
  --replace_001      Replace the 001 field value with the record ID
 
  Additional options for type = 'BIBLIO':
@@ -99,10 +104,21 @@
 for all authority records in the database:
   $0 --format XML --type AUTHORITY --all > output.xml
 
+To export a set of USMARC bibliographic records encoded in UTF-8 in a file
+named "sys1_bibs.mrc" based on records which have attached callnumbers for the
+libraries with the short names "BR1" and "BR2":
+
+  $0 --library BR1 --library BR2 --encoding UTF-8 > sys1_bibs.mrc
+
 HELP
     exit;
 }
 
+if ($all_records && @library) {
+    die('Incompatible arguments: you cannot combine a request for all ' .
+        'records with a request for records by library');
+}
+
 $type = lc($type);
 $format = uc($format);
 $encoding = uc($encoding);
@@ -175,12 +191,39 @@
     for (my $i = 0; $i++ < $top_record;) {
         export_record($i);
     }
+} elsif (@library) {
+    my $recids = $editor->json_query({
+        select => { bre => ['id'] },
+        from => { bre => 'acn' },
+        where => {
+            '+bre' => { deleted => 'f' },
+            '+acn' => { 
+                deleted => 'f', 
+                owning_lib => {
+                    in => {
+                        select => {'aou' => ['id'] },
+                        from => 'aou',
+                        where => { shortname => { in => \@library } }
+                    } 
+                }
+            }
+        },
+        distinct => 1,
+        order_by => [{
+            class => 'bre',
+            field => 'id',
+            direction => 'ASC' 
+        }]
+    });
+
+    foreach my $record (@$recids) {
+        export_record($record->{id});
+    }; 
 } else {
     while ( my $i = <> ) {
         export_record($i);
     }
 }
-
 print "</collection>\n" if ($format eq 'XML');
 
 $speed = $count{did} / (time - $start);



More information about the open-ils-commits mailing list