[open-ils-commits] r9122 - trunk/build/i18n/scripts
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 24 12:16:12 EDT 2008
Author: dbs
Date: 2008-03-24 11:41:09 -0400 (Mon, 24 Mar 2008)
New Revision: 9122
Modified:
trunk/build/i18n/scripts/marc_tooltip_maker.py
Log:
Generate <name> fields just like miker's fancy XSL for LoC MARC
Normalize linefeeds to be consistent with marcedit-tooltips.xml
Modified: trunk/build/i18n/scripts/marc_tooltip_maker.py
===================================================================
--- trunk/build/i18n/scripts/marc_tooltip_maker.py 2008-03-24 14:33:48 UTC (rev 9121)
+++ trunk/build/i18n/scripts/marc_tooltip_maker.py 2008-03-24 15:41:09 UTC (rev 9122)
@@ -110,8 +110,9 @@
You can directly access and manipulate the indicators and subfields lists
"""
- def __init__(self, tag, repeatable, description):
+ def __init__(self, tag, name, repeatable, description):
self.tag = tag
+ self.name = name
self.repeatable = repeatable
self.description = description
self.indicators = []
@@ -122,6 +123,7 @@
Convert the MARC field to XML representation
"""
xml = u" <field repeatable='%s' tag='%s'>\n" % (self.repeatable, self.tag)
+ xml += u" <name>%s</name>\n" % (self.name)
xml += u" <description>%s</description>\n" % (self.description)
for ind in self.indicators:
xml += ind.to_xml()
@@ -187,7 +189,7 @@
matches = re.compile(r'^(\S(-\S)?)\s*-\s*(.+)$', re.S).search(text)
if matches is None:
continue
- new_ind = Indicator(position, matches.group(1), matches.group(3))
+ new_ind = Indicator(position, matches.group(1).replace('\n', ' ').rstrip(), matches.group(3).replace('\n', ' ').rstrip())
field.indicators.append(new_ind)
def process_subfield(field, subfield):
@@ -213,13 +215,14 @@
if (not matches):
print "No subfield match for field: " + field.tag
return None
- field.subfields.append(Subfield(matches.group(1), repeatable, matches.group(2)))
+ field.subfields.append(Subfield(matches.group(1).replace('\n', ' ').rstrip(), repeatable, matches.group(2).replace('\n', ' ').rstrip()))
def process_tag(tag):
"""
Given a chunk of XML representing a MARC field, generate a MarcField object
"""
repeatable = 'true'
+ name = u''
description = u''
# Get tag
@@ -231,6 +234,11 @@
if (re.compile(r'\(NR\)').search(tag.renderContents())):
repeatable = 'false'
+ # Get name - stored in <h2> like:
+ # <h2><a id="mrcb250">250 - Mention d'édition <span class="small">(NR)</span></a>
+ name = re.compile(r'^.+?-\s*(.+)\s*\(.+$', re.S).sub(r'\1', ''.join(tag.findAll(text=True)))
+ name = name.replace('\n', ' ').rstrip()
+
# Get description
desc = tag.parent.findNextSibling('p')
if (not desc):
@@ -244,9 +252,10 @@
print u' '.join(desc.findAll(text=True))
else:
description += desc.string
+ description = description.replace('\n', ' ').rstrip()
# Create the tag
- field = MarcField(tag_num, repeatable, description)
+ field = MarcField(tag_num, name, repeatable, description)
for desc in tag.parent.findNextSiblings():
if (str(desc.__class__) == 'BeautifulSoup.Tag'):
More information about the open-ils-commits
mailing list