From 8057d13db6138c903e161013c3b9bd45d29e4cd6 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 16 Jun 2016 22:54:10 +0200 Subject: [PATCH] Fix traceback during songshowplus import. Fixes bug 1585489. Fixes: https://launchpad.net/bugs/1585489 --- .../songs/lib/importers/songshowplus.py | 8 +++- .../songs/test_songshowplusimport.py | 2 + .../songshowplussongs/cleanse-me.json | 38 ++++++++++++++++++ .../songshowplussongs/cleanse-me.sbsong | Bin 0 -> 1093 bytes 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/resources/songshowplussongs/cleanse-me.json create mode 100644 tests/resources/songshowplussongs/cleanse-me.sbsong diff --git a/openlp/plugins/songs/lib/importers/songshowplus.py b/openlp/plugins/songs/lib/importers/songshowplus.py index 4851894ab..1e7b07c61 100644 --- a/openlp/plugins/songs/lib/importers/songshowplus.py +++ b/openlp/plugins/songs/lib/importers/songshowplus.py @@ -116,7 +116,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)) diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index ec86eca07..a96f21a47 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -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): diff --git a/tests/resources/songshowplussongs/cleanse-me.json b/tests/resources/songshowplussongs/cleanse-me.json new file mode 100644 index 000000000..c88b434f9 --- /dev/null +++ b/tests/resources/songshowplussongs/cleanse-me.json @@ -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" + ] + ] +} diff --git a/tests/resources/songshowplussongs/cleanse-me.sbsong b/tests/resources/songshowplussongs/cleanse-me.sbsong new file mode 100644 index 0000000000000000000000000000000000000000..aa9915f8ecb4b40487d288e4e86c8926104cc294 GIT binary patch literal 1093 zcmYjRO>Yx15KUW}wkd&%JJKBZIz&}V3$4Tnl_nIZf=EOUh=a2`$y)K+E8ClBe-j5T zs6t#g@W*(w8&D3b*w1ff-kY)Wq}6J*<-2oqc6`2p)dSfbTo_h1FkLf!IXyZ5x(W2Y zoOFlY_vqarU8YNIw*VaoeD7m9F*>0)E?3&pBVcm2b-S^RpBag1xF_WHB%-Azc7=X)}mO7bp zN=sD{yyc9v|N4W|sdqW?f>9`F+h_?K!NU>rp*Z-n=HPkzXI)Rj%{XJY_~5*l=sQnI z-FIzgO*k?mC+hV}Gu6f*prV_GE}nBWXJHm4^e%PGw1tblFl*g0qp9}raZ@{THer~Z zl-`OT@F`@fHZ<_cLUTnahdN^HkbP$Lw5p3*&}u8c*Q}hhf7IG3);cOOddjPD)Y5dM zW#){L9NJ3b8f_I74sPpFL7WH?XEV<#l5q>BR4)(!Gh<1u#83sr#vuJQ!c_>`*&YQp zQ&MO};dLqnu1LlkO7GdGjJqld0n6Y>O+cz`+^*R;ZGRimTL+bc%!P;wpLn4c%20yw zhi1YuDx@DFD=G2~0n|~fuUm%xJ3ntOh{#?I3jIus@*D(mrC5kiR}`q`N>7$KmA0T8 z6T>iNXF(hw^RT%X7+6;36YvXMj`Z*$lsAv0xrB&VgIu1M7M&63o_M@_;qZ_Xui^^r p2)YZq=x+$Z>k6`8H(*p~ucLr_0`9CD@e~_*$nxjVdbYk1;4gFPC9D7d literal 0 HcmV?d00001