← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~phill-ridout/openlp/fixes into lp:openlp

 

phill has proposed merging lp:~phill-ridout/openlp/fixes into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)

For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/fixes/+merge/96841

A few minor fixes, and modifications to Wowimport:

Fixes 439 on the support tracker

Remove .encode hopefully to fix http://support.openlp.org/issues/442

Revisited Words of Worship importer. A few tweeks, some to make it more robust, and to provide more information to the user.

Fixed indentation.
-- 
https://code.launchpad.net/~phill-ridout/openlp/fixes/+merge/96841
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2012-01-18 13:50:06 +0000
+++ openlp/core/ui/thememanager.py	2012-03-09 21:48:24 +0000
@@ -159,7 +159,7 @@
         encoding = get_filesystem_encoding()
         files = SettingsManager.get_files(self.settingsSection, u'.otz')
         for file in files:
-            file = os.path.join(self.path, file).encode(encoding)
+            file = os.path.join(self.path, file)
             self.unzipTheme(file, self.path)
             delete_file(file)
         Receiver.send_message(u'cursor_normal')

=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py	2012-01-18 13:50:06 +0000
+++ openlp/core/utils/__init__.py	2012-03-09 21:48:24 +0000
@@ -400,7 +400,7 @@
     """
     if not isinstance(filename, unicode):
         filename = unicode(filename, u'utf-8')
-    return re.sub(r'[/\\?*|<>\[\]":<>+%]+', u'_', filename).strip(u'_')
+    return re.sub(r'[/\\?*|<>\[\]":<>+%\n]+', u'_', filename).strip(u'_')
 
 def delete_file(file_path_name):
     """

=== modified file 'openlp/plugins/songs/lib/wowimport.py'
--- openlp/plugins/songs/lib/wowimport.py	2011-12-27 10:33:55 +0000
+++ openlp/plugins/songs/lib/wowimport.py	2012-03-09 21:48:24 +0000
@@ -31,6 +31,7 @@
 import os
 import logging
 
+from openlp.core.lib import translate
 from openlp.plugins.songs.lib.songimport import SongImport
 
 BLOCK_TYPES = (u'V', u'C', u'B')
@@ -52,18 +53,19 @@
     * A block can be a verse, chorus or bridge.
 
     File Header:
-        Bytes are counted from one, i.e. the first byte is byte 1. These bytes,
-        up to the 56 byte, can change but no real meaning has been found. The
+        Bytes are counted from one, i.e. the first byte is byte 1. The first 19 
+        bytes should be "WoW File \\nSong Words" The bytes after this and up to
+        the 56th byte, can change but no real meaning has been found. The
         56th byte specifies how many blocks there are. The first block starts
         with byte 83 after the "CSongDoc::CBlock" declaration.
 
     Blocks:
         Each block has a starting header, some lines of text, and an ending
-        footer. Each block starts with 4 bytes, the first byte specifies how
-        many lines are in that block, the next three bytes are null bytes.
+        footer. Each block starts with a 32 bit number, which specifies how
+        many lines are in that block.
 
-        Each block ends with 4 bytes, the first of which defines what type of
-        block it is, and the rest which are null bytes:
+        Each block ends with a 32 bit number, which defines what type of
+        block it is:
 
         * ``NUL`` (0x00) - Verse
         * ``SOH`` (0x01) - Chorus
@@ -76,7 +78,6 @@
         Each line starts with a byte which specifies how long that line is,
         the line text, and ends with a null byte.
 
-
     Footer:
         The footer follows on after the last block, the first byte specifies
         the length of the author text, followed by the author text, if
@@ -107,22 +108,28 @@
             for file in self.importSource:
                 if self.stopImportFlag:
                     return
-                file_name = os.path.split(file)[1]
-                # Get the song title
-                self.title = file_name.rpartition(u'.')[0]
+                self.setDefaults()
                 song_data = open(file, 'rb')
                 if song_data.read(19) != u'WoW File\nSong Words':
-                    self.logError(file)
+                    self.logError(file, unicode(
+                        translate('SongsPlugin.WordsofWorshipSongImport',
+                        ('Invalid Words of Worship song file. Missing '
+                            '"Wow File\\nSong Words" header.'))))
                     continue
                 # Seek to byte which stores number of blocks in the song
                 song_data.seek(56)
                 no_of_blocks = ord(song_data.read(1))
+                song_data.seek(66)
+                if song_data.read(16) != u'CSongDoc::CBlock':
+                    self.logError(file, unicode(
+                        translate('SongsPlugin.WordsofWorshipSongImport',
+                        ('Invalid Words of Worship song file. Missing '
+                            '"CSongDoc::CBlock" string.'))))
+                    continue
                 # Seek to the beging of the first block
                 song_data.seek(82)
                 for block in range(no_of_blocks):
-                    self.linesToRead = ord(song_data.read(1))
-                    # Skip 3 nulls to the beginnig of the 1st line
-                    song_data.seek(3, os.SEEK_CUR)
+                    self.linesToRead = ord(song_data.read(4)[:1])
                     block_text = u''
                     while self.linesToRead:
                         self.lineText = unicode(
@@ -132,9 +139,7 @@
                             block_text += u'\n'
                         block_text += self.lineText
                         self.linesToRead -= 1
-                    block_type = BLOCK_TYPES[ord(song_data.read(1))]
-                    # Skip 3 nulls at the end of the block
-                    song_data.seek(3, os.SEEK_CUR)
+                    block_type = BLOCK_TYPES[ord(song_data.read(4)[:1])]
                     # Blocks are seperated by 2 bytes, skip them, but not if
                     # this is the last block!
                     if block + 1 < no_of_blocks:
@@ -150,6 +155,9 @@
                 if copyright_length:
                     self.addCopyright(unicode(
                         song_data.read(copyright_length), u'cp1252'))
+                file_name = os.path.split(file)[1]
+                # Get the song title
+                self.title = file_name.rpartition(u'.')[0]
                 song_data.close()
                 if not self.finish():
                     self.logError(file)


Follow ups