6 use OpenSRF::EX qw/:try/;
7 use OpenSRF::AppSession;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenILS::Application::AppUtils;
10 use OpenILS::Utils::Fieldmapper;
14 use UNIVERSAL::require;
18 my @formats = qw/USMARC UNIMARC XML/;
20 my ($config,$format,$encoding,$help) = ('/openils/conf/bootstrap.conf','USMARC','MARC8');
24 'config=s' => \$config,
25 'format=s' => \$format,
26 'encoding=s' => \$encoding,
32 --help or -h This screen.
33 --config or -c Configuration file [/openils/conf/bootstrap.conf]
34 --format or -f Output format (USMARC, UNIMARC, XML) [USMARC]
35 --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8]
39 cat list_of_ids | $0 > output_file
45 $format = uc($format);
46 $encoding = uc($encoding);
48 binmode(STDOUT, ':raw') if ($encoding ne 'UTF-8');
49 binmode(STDOUT, ':utf8') if ($encoding eq 'UTF-8');
51 if (!grep { $format eq $_ } @formats) {
52 die "Please select a supported format. ".
53 "Right now that means one of [".
54 join('|',@formats). "]\n";
57 if ($format ne 'XML') {
58 my $type = 'MARC::File::' . $format;
62 OpenSRF::System->bootstrap_client( config_file => $config );
63 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
65 my $ses = OpenSRF::AppSession->connect('open-ils.cstore');
67 print <<HEADER if ($format eq 'XML');
68 <?xml version="1.0" encoding="$encoding"?>
69 <collection xmlns='http://www.loc.gov/MARC21/slim'>
72 while ( my $i = <> ) {
73 my $bib = $ses->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve', $i )->gather(1);
77 my $r = MARC::Record->new_from_xml( $bib->marc, $encoding, $format );
78 $r->delete_field( $_ ) for ($r->field(901));
88 if (uc($format) eq 'XML') {
89 print $r->as_xml_record;
90 } elsif (uc($format) eq 'UNIMARC') {
92 } elsif (uc($format) eq 'USMARC') {
97 print "</collection>\n" if ($format eq 'XML');