OpenSong fixes bug 759586

This commit is contained in:
Jonathan Corwin 2011-04-25 23:15:38 +01:00
parent 504a471491
commit 5bc0c27970

View File

@ -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)