Fix SongShowPlus Import when CCLI number contains text

bzr-revno: 2380
This commit is contained in:
Samuel Mehrbrodt 2014-05-09 17:10:07 +01:00 committed by Tim Bentley
commit 8592551d81
4 changed files with 40 additions and 2 deletions

View File

@ -121,7 +121,7 @@ class SongShowPlusImport(SongImport):
null, verse_no, = struct.unpack("BB", song_data.read(2))
elif block_key == CUSTOM_VERSE:
null, verse_name_length, = struct.unpack("BB", song_data.read(2))
verse_name = song_data.read(verse_name_length)
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)
# Detect if/how long the length descriptor is
@ -147,7 +147,12 @@ class SongShowPlusImport(SongImport):
elif block_key == COPYRIGHT:
self.add_copyright(self.decode(data))
elif block_key == CCLI_NO:
self.ccli_number = int(data)
# Try to get the CCLI number even if the field contains additional text
match = re.search(r'\d+', self.decode(data))
if match:
self.ccli_number = int(match.group())
else:
log.warn("Can't parse CCLI Number from string: %s" % self.decode(data))
elif block_key == VERSE:
self.add_verse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Verse], verse_no))
elif block_key == CHORUS:

View File

@ -57,6 +57,8 @@ class TestSongShowPlusFileImport(SongImportTestHelper):
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
self.file_import(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong'),
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')))
class TestSongShowPlusImport(TestCase):

View File

@ -0,0 +1,31 @@
{
"authors": [
"Martin Luther"
],
"ccli_number": 12456,
"comments": "",
"copyright": "Public Domain",
"song_number": 0,
"title": "A Mighty Fortress is our God",
"topics": [],
"verse_order_list": [],
"verses": [
[
"A mighty fortress is our God, a bulwark never failing;\r\nOur helper He, amid the flood of mortal ills prevailing:\r\nFor still our ancient foe doth seek to work us woe;\r\nHis craft and power are great, and, armed with cruel hate,\r\nOn earth is not his equal.\r\n",
"v1"
],
[
"Did we in our own strength confide, our striving would be losing;\r\nWere not the right Man on our side, the Man of God’s own choosing:\r\nDost ask who that may be? Christ Jesus, it is He;\r\nLord Sabaoth, His Name, from age to age the same,\r\nAnd He must win the battle.\r\n",
"v2"
],
[
"And though this world, with devils filled, should threaten to undo us,\r\nWe will not fear, for God hath willed His truth to triumph through us:\r\nThe Prince of Darkness grim, we tremble not for him;\r\nHis rage we can endure, for lo, his doom is sure,\r\nOne little word shall fell him.\r\n",
"v3"
],
[
"That word above all earthly powers, no thanks to them, abideth;\r\nThe Spirit and the gifts are ours through Him Who with us sideth:\r\nLet goods and kindred go, this mortal life also;\r\nThe body they may kill: God’s truth abideth still,\r\nHis kingdom is forever.\r\n",
"v4"
]
]
}