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

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Dec 8 15:48:25 EST 2010


Author: dbs
Date: 2010-12-08 15:48:20 -0500 (Wed, 08 Dec 2010)
New Revision: 1103

Modified:
   conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py
Log:
Break the add_publisher() function out and refine it


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-12-08 19:18:27 UTC (rev 1102)
+++ conifer/branches/rel_1_6_1/tools/ebooks/prep_ebook_records.py	2010-12-08 20:48:20 UTC (rev 1103)
@@ -260,15 +260,7 @@
         else:
             new_record.add_field(field)
 
-    # Add the publisher, with relator code
-    seven_ten = pymarc.Field(tag = '710',
-        indicators = ['2', ' '],
-        subfields = [
-            'a', options['publisher'],
-            '4', 'pbl'
-        ]
-    )
-    new_record.add_field(seven_ten)
+    add_publisher(record, new_record, options)
 
     if 'note' in options:
         note = pymarc.Field(tag = '590',
@@ -283,6 +275,42 @@
 
     return new_record
 
+def add_publisher(record, new_record, options):
+    """
+    This is a convoluted way to avoid creating a new 710 if we already
+    have a matching 710 and just need to add the publisher relator code.
+    """
+
+    munge_publisher = False
+    need_publisher = True
+    need_relator = True
+
+    # Iterate through all of the existing 710 fields
+    for sten in record.get_fields('710'):
+        for pub in sten.get_subfields('a'):
+            if pub == options['publisher']:
+                munge_publisher = True
+                for rel in sten.get_subfields('4'): 
+                    if rel == 'pbl':
+                        need_publisher = False
+                        need_relator = False
+
+                if munge_publisher and need_relator:
+                    sten.add_subfield('4', 'pbl')
+                    need_publisher = False
+
+    if need_publisher:
+        # Add the publisher, with relator code
+        seven_ten = pymarc.Field(tag = '710',
+            indicators = ['2', ' '],
+            subfields = [
+                'a', options['publisher'],
+                '4', 'pbl'
+            ]
+        )
+        new_record.add_field(seven_ten)
+
+
 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