[open-ils-commits] r1094 - conifer/branches/rel_1_6_1/tools/ebooks (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Dec 2 10:55:59 EST 2010


Author: dbs
Date: 2010-12-02 10:55:57 -0500 (Thu, 02 Dec 2010)
New Revision: 1094

Modified:
   conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py
Log:
Add --sample option for generating sample output records

Also add the publisher relator code for added 710 fields and
clean up help to reference MARC instead of MARCXML input files.


Modified: conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py
===================================================================
--- conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py	2010-11-30 04:44:20 UTC (rev 1093)
+++ conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py	2010-12-02 15:55:57 UTC (rev 1094)
@@ -57,8 +57,8 @@
     print '''
 Conifer ebook MARCXML processor
 
-This script takes a set of MARCXML records and processes them to generate a set
-of MARCXML records ready for loading into the Conifer consortial library
+This script takes a set of MARC records and processes them to generate a set
+of MARC records ready for loading into the Conifer consortial library
 system. The processing consists of taking the existing 856 field and creating
 one or more new 856 fields for each Conifer institution that should have access
 to these resources.
@@ -77,9 +77,9 @@
     line.
 
 Required arguments:
-    -i / --input : The name of the input MARCXML file.
+    -i / --input : The name of the input MARC file.
 
-    -o / --output : The name of the output MARCXML file.
+    -o / --output : The name of the output MARC file.
 
     -p / --publisher : The name of the publisher to be inserted in a 710 field.
 
@@ -92,6 +92,9 @@
 Optional arguments:
     -n / --note : The text of the internal note to be inserted into a 590 field.
 
+    -s / --sample : The name of the sample output MARC file (generates
+                    1 sample record for every 100 records processed)
+
     -h / --help : Prints help message
 
 Examples:
@@ -119,6 +122,8 @@
             _options['--laurentian'] = val
         elif key == '-W':
             _options['--windsor'] = val
+        elif key == '-s':
+            _options['--sample'] = val
         elif key == '-h':
             _options['--help'] = val
 
@@ -179,6 +184,9 @@
     clean_opts = dict()
     clean_opts['publisher'] = options['--publisher']
 
+    if '--sample' in options:
+        clean_opts['sample'] = options['--sample']
+
     if '--note' in options:
         clean_opts['note'] = options['--note']
 
@@ -192,9 +200,9 @@
 def parse_opts():
     """Get command-line arguments from the script"""
     try:
-        _short_opts = 'i:o:p:ALWn:h'
+        _short_opts = 'i:o:p:ALWn:s:h'
         _long_opts = ['input=', 'output=', 'publisher=', 'algoma', \
-                'laurentian', 'windsor', 'note=', 'help']
+                'laurentian', 'windsor', 'note=', 'sample=', 'help']
         opts = getopt.getopt(sys.argv[1:], _short_opts, _long_opts) 
     except getopt.GetoptError, ex:
         print "* %s" % str(ex)
@@ -206,15 +214,18 @@
 def process_records(options):
     """Converts raw ebook MARC records to Conifer-ready MARC records"""
 
+    sample = ''
     reader = pymarc.MARCReader(open(options['input'], 'rb'))
     writer = pymarc.MARCWriter(open(options['output'], 'wb'))
+    if ('sample' in options):
+        sample = pymarc.MARCWriter(open(options['sample'], 'wb'))
 
     cnt = 0
     for record in reader:
         url = False
         cnt = cnt + 1
         if not (record['856'] and record['856']['u']):
-            print("* No 856 for record # %s" % (cnt))
+            print("* No 856 for record # %s in file %s" % (cnt, options['input']))
 
         new_record = pymarc.Record()
         for field in record.get_fields():
@@ -228,10 +239,12 @@
             else:
                 new_record.add_field(field)
 
+        # Add the publisher, with relator code
         seven_ten = pymarc.Field(tag = '710',
             indicators = ['2', ' '],
             subfields = [
-                'a', options['publisher'] + '(Firm)'
+                'a', options['publisher'] + ' (Firm)',
+                '4', 'pbl'
             ]
         )
         new_record.add_field(seven_ten)
@@ -248,6 +261,9 @@
         add_cat_source(new_record, options)
 
         writer.write(new_record)
+        if (sample and ((cnt == 1) or (cnt % 100 == 0))):
+            print("SHOULD BE")
+            sample.write(new_record)
 
 def add_cat_source(record, options):
     """Add or extend the 040 field to identify the cataloguing source"""



More information about the open-ils-commits mailing list