From 5bc0c27970d112c749a359f05bcef06e8c388437 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Mon, 25 Apr 2011 23:15:38 +0100 Subject: [PATCH] OpenSong fixes bug 759586 --- openlp/plugins/songs/lib/opensongimport.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index 37fc2b5ef..4d32f7f81 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -32,6 +32,7 @@ from lxml.etree import Error, LxmlError import re from openlp.core.ui.wizard import WizardStrings +from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) @@ -209,7 +210,10 @@ class OpenSongImport(SongImport): verse_num = u'1' # for the case where song has several sections with same marker inst = 1 - lyrics = unicode(root.lyrics) + if u'lyrics' in fields: + lyrics = unicode(root.lyrics) + else: + lyrics = u'' for this_line in lyrics.split(u'\n'): # remove comments semicolon = this_line.find(u';') @@ -230,7 +234,7 @@ class OpenSongImport(SongImport): # have we got any digits? # If so, verse number is everything from the digits # to the end (even if there are some alpha chars on the end) - match = re.match(u'(.*)(\d+.*)', content) + match = re.match(u'([A-Za-z]*)(\d+.*)', content) if match is not None: verse_tag = match.group(1) verse_num = match.group(2) @@ -239,12 +243,13 @@ class OpenSongImport(SongImport): # the verse tag verse_tag = content verse_num = u'1' + verse_index = VerseType.from_loose_input(verse_tag) + verse_tag = VerseType.Tags[verse_index] inst = 1 if [verse_tag, verse_num, inst] in our_verse_order \ and verses.has_key(verse_tag) \ and verses[verse_tag].has_key(verse_num): inst = len(verses[verse_tag][verse_num])+1 - our_verse_order.append([verse_tag, verse_num, inst]) continue # number at start of line.. it's verse number if this_line[0].isdigit(): @@ -257,6 +262,7 @@ class OpenSongImport(SongImport): verses[verse_tag][verse_num] = {} if not verses[verse_tag][verse_num].has_key(inst): verses[verse_tag][verse_num][inst] = [] + our_verse_order.append([verse_tag, verse_num, inst]) # Tidy text and remove the ____s from extended words this_line = self.tidy_text(this_line) this_line = this_line.replace(u'_', u'') @@ -268,6 +274,8 @@ class OpenSongImport(SongImport): verse_def = u'%s%s' % (verse_tag, verse_num) lines = u'\n'.join(verses[verse_tag][verse_num][inst]) self.add_verse(lines, verse_def) + if not self.verses: + self.add_verse('') # figure out the presentation order, if present if u'presentation' in fields and root.presentation != u'': order = unicode(root.presentation)