7 use OpenSRF::EX qw/:try/;
8 use OpenSRF::AppSession;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Application::AppUtils;
11 use OpenILS::Utils::Fieldmapper;
15 use UNIVERSAL::require;
17 use Time::HiRes qw/time/;
21 my @formats = qw/USMARC UNIMARC XML BRE/;
23 my ($config,$format,$encoding,$location,$dollarsign,$idl,$help,$holdings) = ('/openils/conf/bootstrap.conf','USMARC','MARC8','','$');
27 'items' => \$holdings,
28 'location=s' => \$location,
29 'money=s' => \$dollarsign,
30 'config=s' => \$config,
31 'format=s' => \$format,
33 'encoding=s' => \$encoding,
39 --help or -h This screen.
40 --config or -c Configuration file [/openils/conf/bootstrap.conf]
41 --format or -f Output format (USMARC, UNIMARC, XML) [USMARC]
42 --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8]
43 --items or -i Include items (holdings) in the output
44 --xml-idl or -x Location of the IDL XML
45 --location or -l MARC Location Code for holdings from
46 http://www.loc.gov/marc/organizations/orgshome.html
50 cat list_of_ids | $0 > output_file
56 $format = uc($format);
57 $encoding = uc($encoding);
59 binmode(STDOUT, ':raw') if ($encoding ne 'UTF-8');
60 binmode(STDOUT, ':utf8') if ($encoding eq 'UTF-8');
62 if (!grep { uc($format) eq $_ } @formats) {
63 die "Please select a supported format. ".
64 "Right now that means one of [".
65 join('|',@formats). "]\n";
68 if ($format ne 'XML') {
69 my $type = 'MARC::File::' . $format;
73 OpenSRF::System->bootstrap_client( config_file => $config );
76 $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
79 Fieldmapper->import(IDL => $idl);
81 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
83 print <<HEADER if ($format eq 'XML');
84 <?xml version="1.0" encoding="$encoding"?>
85 <collection xmlns='http://www.loc.gov/MARC21/slim'>
94 print STDERR "Retrieving Org Units ... ";
95 my $r = $ses->request( 'open-ils.cstore.direct.actor.org_unit.search', { id => { '!=' => undef } } );
97 while (my $o = $r->recv) {
98 die $r->failed->stringify if ($r->failed);
106 print STDERR "Retrieving Shelving locations ... ";
107 $r = $ses->request( 'open-ils.cstore.direct.asset.copy_location.search', { id => { '!=' => undef } } );
109 while (my $s = $r->recv) {
110 die $r->failed->stringify if ($r->failed);
113 $shelves{$s->id} = $s;
118 $flesh = { flesh => 2, flesh_fields => { bre => [ 'call_numbers' ], acn => [ 'copies' ] } };
122 my $last_time = time;
125 while ( my $i = <> ) {
128 local $SIG{ALRM} = sub { die "TIMEOUT\n" };
130 $bib = $ses->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve', $i, $flesh )->gather(1);
133 warn "\n!!!!!! Timed out trying to read record $i\n";
140 if (uc($format) eq 'BRE') {
141 print JSON->perl2JSON($bib);
148 my $r = MARC::Record->new_from_xml( $bib->marc, $encoding, $format );
149 $r->delete_field( $_ ) for ($r->field(901));
154 a => $bib->tcn_value,
155 b => $bib->tcn_source,
161 my $cn_list = $bib->call_numbers;
162 if ($cn_list && @$cn_list) {
164 $count{cn} += @$cn_list;
166 my $cp_list = [ map { @{ $_->copies } } @$cn_list ];
167 if ($cp_list && @$cp_list) {
170 push @{$cn_map{$_->call_number}}, $_ for (@$cp_list);
172 for my $cn ( @$cn_list ) {
173 my $cn_map_list = $cn_map{$cn->id};
175 for my $cp ( @$cn_map_list ) {
182 b => $orgs{$cn->owning_lib}->shortname,
183 b => $orgs{$cp->circ_lib}->shortname,
184 c => $shelves{$cp->location}->name,
186 ($cp->circ_modifier ? ( g => $cp->circ_modifier ) : ()),
188 ($cp->price ? ( y => $dollarsign.$cp->price ) : ()),
189 ($cp->copy_number ? ( t => $cp->copy_number ) : ()),
190 ($cp->ref eq 't' ? ( x => 'reference' ) : ()),
191 ($cp->holdable eq 'f' ? ( x => 'unholdable' ) : ()),
192 ($cp->circulate eq 'f' ? ( x => 'noncirculating' ) : ()),
193 ($cp->opac_visible eq 'f' ? ( x => 'hidden' ) : ()),
197 stats() if (! ($count{cp} % 100 ));
203 if (uc($format) eq 'XML') {
204 print $r->as_xml_record;
205 } elsif (uc($format) eq 'UNIMARC') {
207 } elsif (uc($format) eq 'USMARC') {
218 stats() if (! ($count{bib} % 50 ));
221 print "</collection>\n" if ($format eq 'XML');
223 $speed = $count{did} / (time - $start);
224 my $time = time - $start;
227 Exports Attempted : $count{bib}
228 Exports Completed : $count{did}
229 Overall Speed : $speed
230 Total Time Elapsed: $time seconds
239 $speed = $count{did} / (time - $start);
241 my $speed_now = ($count{did} - $count{did_last}) / (time - $count{time_last});
242 my $cn_speed = $count{cn} / (time - $start);
243 my $cp_speed = $count{cp} / (time - $start);
245 printf STDERR "\r $count{did} of $count{bib} @ \%0.4f/s ttl / \%0.4f/s rt ".
246 "($count{cn} CNs @ \%0.4f/s :: $count{cp} CPs @ \%0.4f/s)\r",
252 $count{did_last} = $count{did};
253 $count{time_last} = time;