[open-ils-commits] r10135 - trunk/Open-ILS/src/extras/import
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jul 25 15:04:17 EDT 2008
Author: miker
Date: 2008-07-25 15:04:08 -0400 (Fri, 25 Jul 2008)
New Revision: 10135
Added:
trunk/Open-ILS/src/extras/import/marc_add_ids
Modified:
trunk/Open-ILS/src/extras/import/parallel_pg_loader.pl
trunk/Open-ILS/src/extras/import/pg_loader.pl
Log:
a tool for adding IDs to MARCXML dumped directly from biblio.record_entry
Added: trunk/Open-ILS/src/extras/import/marc_add_ids
===================================================================
--- trunk/Open-ILS/src/extras/import/marc_add_ids (rev 0)
+++ trunk/Open-ILS/src/extras/import/marc_add_ids 2008-07-25 19:04:08 UTC (rev 10135)
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+use MARC::Record;
+use MARC::Charset;
+use MARC::File::XML;
+use Error qw/:try/;
+
+MARC::Charset->assume_unicode(1);
+MARC::Charset->ignore_errors(1);
+
+binmode(STDIN, ':utf8');
+binmode(STDOUT, ':utf8');
+
+my ($delim, @fields) = (' \| ');
+GetOptions(
+ 'delimiter=s' => \$delim,
+ 'field=s' => \@fields,
+);
+
+my %partmap;
+my $partcount = 0;
+for (@fields) {
+ $partmap{$_} = $partcount;
+ $partcount++;
+}
+
+while (<>) {
+ chomp;
+ my @values = split $delim;
+
+ my %partlist;
+ for my $part (keys %partmap) {
+ ($partlist{tcn_value} = $values[ $partmap{tcn_value}]) =~ s/^\s*//o if ($part eq 'tcn_value');
+ ($partlist{tcn_source} = $values[ $partmap{tcn_source}]) =~ s/^\s*//o if ($part eq 'tcn_source');
+ ($partlist{id} = $values[ $partmap{id}]) =~ s/^\s*//o if ($part eq 'id');
+ $partlist{marc} = $values[ $partmap{marc}] if ($part eq 'marc');
+
+ $partlist{tcn_value} =~ s/\s*$//o if ($part eq 'tcn_value');
+ $partlist{tcn_source} =~ s/\s*$//o if ($part eq 'tcn_source');
+ $partlist{id} =~ s/\s*$//o if ($part eq 'id');
+ }
+
+ next unless ($partlist{marc});
+
+ try {
+ my $r = MARC::Record->new_from_xml($partlist{marc});
+
+ my %sfmap;
+ $sfmap{a} = $partlist{tcn_value} if ($partlist{tcn_value});
+ $sfmap{b} = $partlist{tcn_source} if ($partlist{tcn_source});
+ $sfmap{c} = $partlist{id} if ($partlist{id});
+
+ my $f = MARC::Field->new(901 => ' ' => ' ' => %sfmap);
+ $r->delete_field($_) for ($r->field('901'));
+ $r->append_fields( $f );
+
+ print $r->as_xml_record;
+ } otherwise {
+ warn "failed on record $., $partlist{marc}\n";
+ };
+}
+
+
Property changes on: trunk/Open-ILS/src/extras/import/marc_add_ids
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/Open-ILS/src/extras/import/parallel_pg_loader.pl
===================================================================
--- trunk/Open-ILS/src/extras/import/parallel_pg_loader.pl 2008-07-25 19:00:18 UTC (rev 10134)
+++ trunk/Open-ILS/src/extras/import/parallel_pg_loader.pl 2008-07-25 19:04:08 UTC (rev 10135)
@@ -80,6 +80,9 @@
fields => \@cols,
};
+ #XXX it burnnnsssessss
+ $fieldcache{$hint}{table} =~ s/\.full_rec/.real_full_rec/o if ($hint eq 'mfr');
+
my $fields = join(',', @{ $fieldcache{$hint}{fields} });
$main_out->print( "DELETE FROM $fieldcache{$hint}{table};\n" ) if (grep {$_ eq $hint } @wipe);
$main_out->print( "COPY $fieldcache{$hint}{table} ($fields) FROM '$pwd/$output.$hint.sql';\n" );
Modified: trunk/Open-ILS/src/extras/import/pg_loader.pl
===================================================================
--- trunk/Open-ILS/src/extras/import/pg_loader.pl 2008-07-25 19:00:18 UTC (rev 10134)
+++ trunk/Open-ILS/src/extras/import/pg_loader.pl 2008-07-25 19:04:08 UTC (rev 10135)
@@ -62,6 +62,9 @@
pkey => $class->Identity,
fields => \@cols,
};
+
+ #XXX it burnnnsssessss
+ $fieldcache{$hint}{table} =~ s/\.full_rec/.real_full_rec/o if ($hint eq 'mfr');
}
push @{ $lineset{$hint} }, [map { $row->$_ } @{ $fieldcache{$hint}{fields} }];
More information about the open-ils-commits
mailing list