Break the add_publisher() function out and refine it
authordbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 8 Dec 2010 20:48:20 +0000 (20:48 +0000)
committerdbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 8 Dec 2010 20:48:20 +0000 (20:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1103 6d9bc8c9-1ec2-4278-b937-99fde70a366f

tools/ebooks/prep_ebook_records.py

index a914f9e..cfe0d46 100644 (file)
@@ -260,15 +260,7 @@ def process_fields(record, options):
         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 @@ def process_fields(record, options):
 
     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"""