← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~thelinuxguy/openlp/backport-fix into lp:openlp/2.4

 

Simon Hanna has proposed merging lp:~thelinuxguy/openlp/backport-fix into lp:openlp/2.4.

Requested reviews:
  Tim Bentley (trb143)

For more details, see:
https://code.launchpad.net/~thelinuxguy/openlp/backport-fix/+merge/321379

Backport songbeamer fix
-- 
Your team OpenLP Core is subscribed to branch lp:openlp/2.4.
=== modified file 'openlp/plugins/songs/lib/importers/songbeamer.py'
--- openlp/plugins/songs/lib/importers/songbeamer.py	2017-01-22 17:04:32 +0000
+++ openlp/plugins/songs/lib/importers/songbeamer.py	2017-03-29 22:05:48 +0000
@@ -22,11 +22,10 @@
 """
 The :mod:`songbeamer` module provides the functionality for importing SongBeamer songs into the OpenLP database.
 """
-import chardet
-import codecs
 import logging
 import os
 import re
+import chardet
 
 from openlp.plugins.songs.lib import VerseType
 from openlp.plugins.songs.lib.importers.songimport import SongImport
@@ -120,7 +119,7 @@
                 # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode.
                 # So if it doesn't start with 'u' we default to cp1252. See:
                 # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2
-                if self.input_file_encoding.lower().startswith('u'):
+                if not self.input_file_encoding.lower().startswith('u'):
                     self.input_file_encoding = 'cp1252'
                 infile = open(import_file, 'rt', encoding=self.input_file_encoding)
                 song_data = infile.readlines()

=== modified file 'tests/functional/openlp_plugins/songs/test_songbeamerimport.py'
--- tests/functional/openlp_plugins/songs/test_songbeamerimport.py	2016-12-31 11:05:48 +0000
+++ tests/functional/openlp_plugins/songs/test_songbeamerimport.py	2017-03-29 22:05:48 +0000
@@ -49,6 +49,13 @@
         self.file_import([os.path.join(TEST_PATH, 'Lobsinget dem Herrn.sng')],
                          self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json')))
 
+    def test_cp1252_encoded_file(self):
+        """
+        Test that a CP1252 encoded file get's decoded properly.
+        """
+        self.file_import([os.path.join(TEST_PATH, 'cp1252song.sng')],
+                         self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json')))
+
 
 class TestSongBeamerImport(TestCase):
     """

=== added file 'tests/resources/songbeamersongs/cp1252song.json'
--- tests/resources/songbeamersongs/cp1252song.json	1970-01-01 00:00:00 +0000
+++ tests/resources/songbeamersongs/cp1252song.json	2017-03-29 22:05:48 +0000
@@ -0,0 +1,8 @@
+{
+"title": "Some Song",
+ "authors": ["Author"],
+ "verses" : [
+   ["Here are a couple of \"weird\" chars’’’.\n", "v"],
+   ["Here is another one….\n\n", "v"]
+ ]
+}

=== added file 'tests/resources/songbeamersongs/cp1252song.sng'
--- tests/resources/songbeamersongs/cp1252song.sng	1970-01-01 00:00:00 +0000
+++ tests/resources/songbeamersongs/cp1252song.sng	2017-03-29 22:05:48 +0000
@@ -0,0 +1,15 @@
+#LangCount=1
+#Editor=SongBeamer 4.28a
+#Version=3
+#Format=F/K//
+#TitleFormat=U
+#Title=Some Song
+#Author=Author
+#Melody=Author
+#(c)=No copyright
+#CCLI=0000000000
+---
+Here are a couple of "weird" chars���.
+---
+Here is another one�.
+


Follow ups