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

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Nov 24 17:44:18 EST 2010


Author: dbs
Date: 2010-11-24 17:44:12 -0500 (Wed, 24 Nov 2010)
New Revision: 1085

Modified:
   conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py
Log:
Significant clean up of the ebook prep script

Refine some of Windsor's requirements, and handle some of the
conditions raised by pylint to make things a tiny bit cleaner.


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-24 17:44:27 UTC (rev 1084)
+++ conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py	2010-11-24 22:44:12 UTC (rev 1085)
@@ -1,7 +1,20 @@
 #!/usr/bin/env python
+"""
+Prepare sets of electronic resource MARC records for loading into Evergreen
 
-import codecs, os, os.path, sys, getopt, pymarc, pymarc.marc8
+To avoid duplicating MARC records in Conifer, to minimize manual labour,
+and to make records as consistent as possible, we want to automate the
+processing of electronic resource MARC records purchased by two or more
+Conifer institutions.
 
+Each institution must confirm the standard data they require to be added
+to e-book MARC records. The principle here is to identify standard
+requirements that would be the same for each record and therefore can
+be accommodated in batch load.
+"""
+
+import os, os.path, sys, getopt, pymarc, pymarc.marc8
+
 class Institution():
     """Defines standard settings for each Conifer institution"""
 
@@ -27,7 +40,7 @@
             "code": "OWA", \
             "ebrary_code": "oculwindsor", \
             "proxy": "http://ezproxy.uwindsor.ca/login?url=", \
-            "public_note": "To view Windsor's electronic resource click here.", \
+            "public_note": "To view Windsor's electronic resource click here.",\
             "link_text": "To view Windsor's electronic resource click here." \
         }
 
@@ -182,12 +195,12 @@
         _short_opts = 'i:o:p:ALWn:h'
         _long_opts = ['input=', 'output=', 'publisher=', 'algoma', \
                 'laurentian', 'windsor', 'note=', 'help']
-        opts, args = getopt.getopt(sys.argv[1:], _short_opts, _long_opts) 
+        opts = getopt.getopt(sys.argv[1:], _short_opts, _long_opts) 
     except getopt.GetoptError, ex:
         print "* %s" % str(ex)
         do_help()
 
-    _options = consolidate_options(opts)
+    _options = consolidate_options(opts[0])
     return check_options(_options)    
 
 def process_records(options):
@@ -200,10 +213,7 @@
     for record in reader:
         url = False
         cnt = cnt + 1
-        if record['856'] and record['856']['u']:
-            url_tag = record['856']['u']
-            # print url
-        else:
+        if not (record['856'] and record['856']['u']):
             print("* No 856 for record # %s" % (cnt))
 
         new_record = pymarc.Record()
@@ -213,15 +223,15 @@
                 if url == False:
                     url = True
                     new_fields = process_urls(field, options)
-                    for nf in new_fields:
-                        new_record.add_field(nf)
+                    for new_856 in new_fields:
+                        new_record.add_field(new_856)
             else:
                 new_record.add_field(field)
 
         seven_ten = pymarc.Field(tag = '710',
             indicators = ['2', ' '],
             subfields = [
-                'a', options['publisher']
+                'a', options['publisher'] + '(Firm)'
             ]
         )
         new_record.add_field(seven_ten)
@@ -234,7 +244,13 @@
                 ]
             )
             new_record.add_field(note)
-            
+
+        forty = pymarc.Field(tag = '040',
+            indicators = [' ', ' '],
+            subfields = [ 'a', 'CaOWA' ]
+        )
+        new_record.add_field(forty)
+
         writer.write(new_record)
 
 def process_urls(field, options):
@@ -242,9 +258,7 @@
 
     new_fields = []
 
-    try:
-        url = field['u']
-    except Error:
+    if not field['u']:
         print "* No subfield 'u' found in this 856"
         return None
 
@@ -253,7 +267,7 @@
         eight_five_six = pymarc.Field(tag = '856',
             indicators = ['4', '0'],
             subfields = [
-                'u', data['proxy'] + url,
+                'u', data['proxy'] + field['u'],
                 'y', data['link_text'],
                 'z', data['public_note'],
                 '9', data['code']
@@ -265,22 +279,4 @@
 
 if __name__ == '__main__':
 
-    options = parse_opts() 
-    process_records(options);
-
-## Okay, made it through the basic invocation requirements; moving on
-#
-#For each MARC record:
-#
-#Find the 856 u ($url)
-#for each institution:
-#create a new 856 40
-#if $url =~ /\.ebrary\./, then:
-#$url =~ s/^.*?id=(\d+)\s*$/$1/
-#$url = http://site.ebrary.com/lib/ + institution.ebrary_code + "/Doc?id=" + $url
-#else:
-#$url = institution.proxy + $url
-#$u = $url
-#$y = institution.link_text
-#$z = institution.public_note
-#$9 = institution.code
+    process_records(parse_opts())



More information about the open-ils-commits mailing list