Fix traceback during songshowplus import. Fixes bug 1585489.

Fixes: https://launchpad.net/bugs/1585489
This commit is contained in:
Tomas Groth 2016-05-25 09:04:41 +02:00
parent 72120d8b2f
commit fd4cfd1eaa
4 changed files with 50 additions and 4 deletions

View File

@ -105,6 +105,7 @@ class SongShowPlusImport(SongImport):
song_data = open(file, 'rb')
while True:
block_key, = struct.unpack("I", song_data.read(4))
log.debug('block_key: %d' % block_key)
# The file ends with 4 NULL's
if block_key == 0:
break
@ -116,7 +117,13 @@ class SongShowPlusImport(SongImport):
null, verse_name_length, = struct.unpack("BB", song_data.read(2))
verse_name = self.decode(song_data.read(verse_name_length))
length_descriptor_size, = struct.unpack("B", song_data.read(1))
log.debug(length_descriptor_size)
log.debug('length_descriptor_size: %d' % length_descriptor_size)
# In the case of song_numbers the number is in the data from the
# current position to the next block starts
if block_key == SONG_NUMBER:
sn_bytes = song_data.read(length_descriptor_size - 1)
self.song_number = int.from_bytes(sn_bytes, byteorder='little')
continue
# Detect if/how long the length descriptor is
if length_descriptor_size == 12 or length_descriptor_size == 20:
length_descriptor, = struct.unpack("I", song_data.read(4))
@ -126,8 +133,9 @@ class SongShowPlusImport(SongImport):
length_descriptor = 0
else:
length_descriptor, = struct.unpack("B", song_data.read(1))
log.debug(length_descriptor_size)
log.debug('length_descriptor: %d' % length_descriptor)
data = song_data.read(length_descriptor)
log.debug(data)
if block_key == TITLE:
self.title = self.decode(data)
elif block_key == AUTHOR:
@ -164,8 +172,6 @@ class SongShowPlusImport(SongImport):
self.ssp_verse_order_list.append(verse_tag)
elif block_key == SONG_BOOK:
self.song_book_name = self.decode(data)
elif block_key == SONG_NUMBER:
self.song_number = ord(data)
elif block_key == CUSTOM_VERSE:
verse_tag = self.to_openlp_verse_tag(verse_name)
self.add_verse(self.decode(data), verse_tag)

View File

@ -52,6 +52,8 @@ class TestSongShowPlusFileImport(SongImportTestHelper):
self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json')))
self.file_import([os.path.join(TEST_PATH, 'a mighty fortress is our god.sbsong')],
self.load_external_result_data(os.path.join(TEST_PATH, 'a mighty fortress is our god.json')))
self.file_import([os.path.join(TEST_PATH, 'cleanse-me.sbsong')],
self.load_external_result_data(os.path.join(TEST_PATH, 'cleanse-me.json')))
class TestSongShowPlusImport(TestCase):

View File

@ -0,0 +1,38 @@
{
"authors": [
"J. Edwin Orr"
],
"ccli_number": 56307,
"comments": "",
"copyright": "Public Domain ",
"song_book_name": "",
"song_number": 438,
"title": "Cleanse Me [438]",
"topics": [
"Cleansing",
"Communion",
"Consecration",
"Holiness",
"Holy Spirit",
"Revival"
],
"verse_order_list": [],
"verses": [
[
"Search me, O God,\r\nAnd know my heart today;\r\nTry me, O Savior,\r\nKnow my thoughts, I pray.\r\nSee if there be\r\nSome wicked way in me;\r\nCleanse me from every sin\r\nAnd set me free.",
"v1"
],
[
"I praise Thee, Lord,\r\nFor cleansing me from sin;\r\nFulfill Thy Word,\r\nAnd make me pure within.\r\nFill me with fire\r\nWhere once I burned with shame;\r\nGrant my desire\r\nTo magnify Thy name.",
"v2"
],
[
"Lord, take my life,\r\nAnd make it wholly Thine;\r\nFill my poor heart\r\nWith Thy great love divine.\r\nTake all my will,\r\nMy passion, self and pride;\r\nI now surrender, Lord\r\nIn me abide.",
"v3"
],
[
"O Holy Ghost,\r\nRevival comes from Thee;\r\nSend a revival,\r\nStart the work in me.\r\nThy Word declares\r\nThou wilt supply our need;\r\nFor blessings now,\r\nO Lord, I humbly plead.",
"v4"
]
]
}

Binary file not shown.