Refine based on feedback from Windsor
authorDan Scott <dan@coffeecode.net>
Thu, 11 Aug 2011 15:25:33 +0000 (11:25 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 18:37:12 +0000 (14:37 -0400)
1) 506 $a and $b both need to end with ' ; '; try to make this happen
   even if the command line is screwed up.

2) Ensure the incoming 710 $a ends with a period.

Also, do not generate a 506 for Algoma if publisher == Cambridge

Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/ebooks/prep_ebook_records.py

index 2fb4859..ca05f49 100644 (file)
@@ -291,7 +291,6 @@ def process_fields(record, options):
     new_record = pymarc.Record(to_unicode=True, force_utf8=True)
 
     add_cat_source(record, options) # 040
-    add_restriction(record, options) # 506
 
     # 590
     if 'note' in options:
@@ -305,6 +304,7 @@ def process_fields(record, options):
 
     add_marc_source(record, options) # 598
     publisher = add_publisher(record, options) # 710
+    add_restriction(record, options, publisher) # 506
     add_platform(record, options) # 710
 
     marked_isbn = mark_isbn_for_sfx(record, options)
@@ -471,7 +471,7 @@ def add_publisher(record, options):
     # Iterate through all of the existing 710 fields
     for sten in record.get_fields('710'):
         for pub in sten.get_subfields('a'):
-            if pub == publisher:
+            if pub == publisher or (pub == publisher + '.'):
                 munge_publisher = True
                 for rel in sten.get_subfields('4'): 
                     if rel == 'pbl':
@@ -482,6 +482,10 @@ def add_publisher(record, options):
                     sten.add_subfield('4', 'pbl')
                     need_publisher = False
 
+    # Append a period to the publisher name
+    if publisher[-1] != '.':
+        publisher += '.'
+
     if need_publisher:
         # Add the publisher, with relator code
         seven_ten = pymarc.Field(tag = '710',
@@ -510,9 +514,13 @@ def add_platform(record, options):
     # Iterate through all of the existing 710 fields
     for sten in record.get_fields('710'):
         for pub in sten.get_subfields('a'):
-            if pub == platform:
+            if pub == platform or (pub == platform + '.'):
                 need_platform = False
 
+    # Append a period to the publisher name
+    if platform[-1] != '.':
+        platform += '.'
+
     if need_platform:
         # Add the platform
         seven_ten = pymarc.Field(tag = '710',
@@ -603,7 +611,7 @@ def clean_isbn(isbn):
 
     return isbn
 
-def add_restriction(new_record, options):
+def add_restriction(new_record, options, publisher):
     """
     Adds a 506 access restriction note per institution
 
@@ -620,19 +628,38 @@ def add_restriction(new_record, options):
         authnote += '.'
 
     for library in options['libraries']:
+
+        # Skip auth note if Algoma + CUP
+        if library == 'algoma' and 'Cambridge' in publisher:
+            continue
+
         libopts = options['settings'].get_settings(library)
         # Add the access restriction note
         note = pymarc.Field(tag = '506',
             indicators = ['1', ' '],
             subfields = [
-                'a', libopts['access_note'],
-                'b', options['consortium'] + ' ; ',
+                'a', append_space_semi_space(libopts['access_note']),
+                'b', append_space_semi_space(options['consortium']),
                 'e', authnote,
                 '9', libopts['code']
             ]
         )
         new_record.add_field(note)
 
+def append_space_semi_space(note):
+    """
+    Try to ensure the given text ends with ' ; '
+    """
+
+    if note[-3:] == ' ; ':
+        pass
+    elif note[-1] == ';':
+        note += ' '
+    elif note[-1] == ' ':
+        note += '; '
+
+    return note
+
 def add_cat_source(record, options):
     """Add or extend the 040 field to identify the cataloguing source"""