openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #16836
[Merge] lp:~phill-ridout/openlp/openlyric_split into lp:openlp
phill has proposed merging lp:~phill-ridout/openlp/openlyric_split into lp:openlp.
Requested reviews:
Tim Bentley (trb143)
Related bugs:
Bug #876211 in OpenLP: "OpenLyrics export non-compliant for split verses"
https://bugs.launchpad.net/openlp/+bug/876211
Bug #904690 in OpenLP: "cloning a song does not retain splits"
https://bugs.launchpad.net/openlp/+bug/904690
For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/openlyric_split/+merge/119196
I've fixed 876211 and 904690.
My fix feels clumsy, but I couldn't think of a better way to do it.
Please let me know if you have any ideas how to do it better.
changed '' to None
--
https://code.launchpad.net/~phill-ridout/openlp/openlyric_split/+merge/119196
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2012-06-22 14:14:53 +0000
+++ openlp/plugins/songs/lib/xml.py 2012-08-10 21:33:20 +0000
@@ -260,7 +260,7 @@
IMPLEMENTED_VERSION = u'0.8'
START_TAGS_REGEX = re.compile(r'\{(\w+)\}')
END_TAGS_REGEX = re.compile(r'\{\/(\w+)\}')
- VERSE_NUMBER_REGEX = re.compile(u'[a-zA-Z]*')
+ VERSE_TAG_SPLITTER = re.compile(u'([a-zA-Z]+)([0-9]*)([a-zA-Z]?)')
def __init__(self, manager):
self.manager = manager
@@ -325,10 +325,32 @@
# Process the song's lyrics.
lyrics = etree.SubElement(song_xml, u'lyrics')
verse_list = sxml.get_verses(song.lyrics)
- for verse in verse_list:
- verse_tag = verse[0][u'type'][0].lower()
- verse_number = verse[0][u'label']
- verse_def = verse_tag + verse_number
+ # Find duplicate verses
+ duplicate_verses = {}
+ # Count duplicate verse tags using a dictionary
+ for verse in verse_list:
+ verse_tag = verse[0][u'type'][0].lower()
+ verse_number = verse[0][u'label']
+ verse_def = verse_tag + verse_number
+ if verse_def in duplicate_verses:
+ duplicate_verses[verse_def] += 1
+ else:
+ duplicate_verses[verse_def] = 1
+ # For each duplicate verse, create a list of letters to append
+ for duplicate in duplicate_verses:
+ verse_duplicates = duplicate_verses[duplicate]
+ duplicate_verses[duplicate] = []
+ if verse_duplicates > 1:
+ for i in range(0, verse_duplicates):
+ duplicate_verses[duplicate].append(chr(97 + i))
+ duplicate_verses[duplicate].reverse()
+ # Append the letters to each duplicate verse
+ for verse in verse_list:
+ verse_tag = verse[0][u'type'][0].lower()
+ verse_number = verse[0][u'label']
+ verse_def = verse_tag + verse_number
+ if duplicate_verses[verse_def]:
+ verse_def += duplicate_verses[verse_def].pop()
verse_element = \
self._add_text_to_element(u'verse', lyrics, None, verse_def)
if u'lang' in verse[0]:
@@ -742,11 +764,10 @@
if lines.get(u'break') is not None:
text += u'\n[---]'
verse_def = verse.get(u'name', u' ').lower()
- if verse_def[0] in VerseType.Tags:
- verse_tag = verse_def[0]
- else:
+ verse_tag, verse_number, verse_part = \
+ OpenLyrics.VERSE_TAG_SPLITTER.search(verse_def).groups()
+ if verse_tag not in VerseType.Tags:
verse_tag = VerseType.Tags[VerseType.Other]
- verse_number = OpenLyrics.VERSE_NUMBER_REGEX.sub(u'', verse_def)
# OpenLyrics allows e. g. "c", but we need "c1". However, this does
# not correct the verse order.
if not verse_number:
@@ -757,13 +778,13 @@
if song_xml.get(u'modifiedIn') in (u'1.9.6', u'OpenLP 1.9.6') and \
song_xml.get(u'version') == u'0.7' and \
(verse_tag, verse_number, lang) in verses:
- verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text
+ verses[(verse_tag, verse_number, lang, None)] += u'\n[---]\n' + text
# Merge v1a, v1b, .... to v1.
- elif (verse_tag, verse_number, lang) in verses:
+ elif (verse_tag, verse_number, lang, verse_part) in verses:
verses[(verse_tag, verse_number, lang)] += u'\n' + text
else:
- verses[(verse_tag, verse_number, lang)] = text
- verse_def_list.append((verse_tag, verse_number, lang))
+ verses[(verse_tag, verse_number, lang, verse_part)] = text
+ verse_def_list.append((verse_tag, verse_number, lang, verse_part))
# We have to use a list to keep the order, as dicts are not sorted.
for verse in verse_def_list:
sxml.add_verse_to_lyrics(
Follow ups