← Back to team overview

openlp-core team mailing list archive

[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/125861

I've fixed 876211 and 904690.
My fix feels clumsy, but I couldn't think of a better way to do it.
Merged Trunk

-- 
https://code.launchpad.net/~phill-ridout/openlp/openlyric_split/+merge/125861
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-09-22 19:58: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,21 @@
         # 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
+        # Add a suffix letter to each verse
+        verse_tags = []
+        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
+            verse_tags.append(verse_def)
+            verse[0][u'suffix'] = chr(96 + verse_tags.count(verse_def))
+        # If the verse tag is a duplicate use the suffix letter
+        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_tags.count(verse_def) > 1:
+                verse_def += verse[0][u'suffix']
             verse_element = \
                 self._add_text_to_element(u'verse', lyrics, None, verse_def)
             if u'lang' in verse[0]:
@@ -742,11 +753,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 +767,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