From: dbs Date: Wed, 8 Dec 2010 20:48:20 +0000 (+0000) Subject: Break the add_publisher() function out and refine it X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=90a8cf7463836612076c05c97f64fa880aa58651;p=contrib%2FConifer.git Break the add_publisher() function out and refine it git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1103 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/tools/ebooks/prep_ebook_records.py b/tools/ebooks/prep_ebook_records.py index a914f9eb7b..cfe0d46088 100644 --- a/tools/ebooks/prep_ebook_records.py +++ b/tools/ebooks/prep_ebook_records.py @@ -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"""