[open-ils-commits] r19586 - trunk/Open-ILS/src/support-scripts (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Mar 4 15:58:32 EST 2011
Author: dbs
Date: 2011-03-04 15:58:27 -0500 (Fri, 04 Mar 2011)
New Revision: 19586
Modified:
trunk/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
Modified: trunk/Open-ILS/src/support-scripts/marc_export
===================================================================
--- trunk/Open-ILS/src/support-scripts/marc_export 2011-03-04 19:49:09 UTC (rev 19585)
+++ trunk/Open-ILS/src/support-scripts/marc_export 2011-03-04 20:58:27 UTC (rev 19586)
@@ -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