From 2def15c12fb6610bc3e2123ff5055f4bc205d2e2 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Fri, 6 May 2011 13:56:58 -0400 Subject: [PATCH] Bug 762856: Support Bridge section and make more robust error recovery --- openlp/plugins/songs/lib/songshowplusimport.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index 9fdc5804a..6d2e1f5b6 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -47,6 +47,7 @@ VERSE_ORDER = 31 SONG_BOOK = 35 SONG_NUMBER = 36 CUSTOM_VERSE = 37 +BRIDGE = 24 log = logging.getLogger(__name__) @@ -97,9 +98,10 @@ class SongShowPlusImport(SongImport): """ Receive a single file or a list of files to import. """ - if isinstance(self.import_source, list): + if not isinstance(self.import_source, list): return self.import_wizard.progressBar.setMaximum(len(self.import_source)) + for file in self.import_source: self.sspVerseOrderList = [] otherCount = 0 @@ -108,13 +110,15 @@ class SongShowPlusImport(SongImport): self.import_wizard.incrementProgressBar( WizardStrings.ImportingType % file_name, 0) songData = open(file, 'rb') + while True: blockKey, = struct.unpack("I", songData.read(4)) # The file ends with 4 NUL's if blockKey == 0: break nextBlockStarts, = struct.unpack("I", songData.read(4)) - if blockKey == VERSE or blockKey == CHORUS: + nextBlockStarts += songData.tell() + if blockKey in (VERSE, CHORUS, BRIDGE): null, verseNo, = struct.unpack("BB", songData.read(2)) elif blockKey == CUSTOM_VERSE: null, verseNameLength, = struct.unpack("BB", @@ -150,6 +154,9 @@ class SongShowPlusImport(SongImport): elif blockKey == CHORUS: self.add_verse(unicode(data, u'cp1252'), "C%s" % verseNo) + elif blockKey == BRIDGE: + self.add_verse(unicode(data, u'cp1252'), + "B%s" % verseNo) elif blockKey == TOPIC: self.topics.append(unicode(data, u'cp1252')) elif blockKey == COMMENTS: @@ -169,6 +176,7 @@ class SongShowPlusImport(SongImport): else: log.debug("Unrecognised blockKey: %s, data: %s" % (blockKey, data)) + songData.seek(nextBlockStarts) self.verse_order_list = self.sspVerseOrderList songData.close() if not self.finish():