Fixed bug #771529, dealing with 1.9.0 databases.

bzr-revno: 1499
This commit is contained in:
Raoul Snyman 2011-04-29 09:22:18 +02:00
commit 80b6135c5a
2 changed files with 18 additions and 3 deletions

View File

@ -293,7 +293,10 @@ def clean_song(manager, song):
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
# Rebuild the verse order, to convert translated verse tags, which might
# have been added prior to 1.9.5.
order = song.verse_order.strip().split()
if song.verse_order:
order = song.verse_order.strip().split()
else:
order = []
new_order = []
for verse_def in order:
verse_type = VerseType.Tags[VerseType.from_loose_input(verse_def[0])]

View File

@ -134,14 +134,26 @@ class SongXML(object):
[{'lang': 'en', 'type': 'c', 'label': '1'}, u"English chorus"]]
"""
self.song_xml = None
if xml[:5] == u'<?xml':
verse_list = []
if not xml.startswith(u'<?xml') and not xml.startswith(u'<song'):
# This is an old style song, without XML. Let's handle it correctly
# by iterating through the verses, and then recreating the internal
# xml object as well.
self.song_xml = objectify.fromstring(u'<song version="1.0" />')
self.lyrics = etree.SubElement(self.song_xml, u'lyrics')
verses = xml.split(u'\n\n')
for count, verse in enumerate(verses):
verse_list.append([{u'type': u'v', u'label': unicode(count)},
unicode(verse)])
self.add_verse_to_lyrics(u'v', unicode(count), verse)
return verse_list
elif xml.startswith(u'<?xml'):
xml = xml[38:]
try:
self.song_xml = objectify.fromstring(xml)
except etree.XMLSyntaxError:
log.exception(u'Invalid xml %s', xml)
xml_iter = self.song_xml.getiterator()
verse_list = []
for element in xml_iter:
if element.tag == u'verse':
if element.text is None: