← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~sam92/openlp/fix-songbeamer-import into lp:openlp

 

Samuel Mehrbrodt has proposed merging lp:~sam92/openlp/fix-songbeamer-import into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)
  Jonathan Corwin (j-corwin)

For more details, see:
https://code.launchpad.net/~sam92/openlp/fix-songbeamer-import/+merge/188206

Fix SongBeamer Import

The read() call failed when the file was not unicode. So I first open the file in binary mode without encoding. After the encoding has been detected, the file is read with the proper encoding.

I tested this with ~800 SongBeamer files.
-- 
https://code.launchpad.net/~sam92/openlp/fix-songbeamer-import/+merge/188206
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/songbeamerimport.py'
--- openlp/plugins/songs/lib/songbeamerimport.py	2013-08-31 18:17:38 +0000
+++ openlp/plugins/songs/lib/songbeamerimport.py	2013-09-28 20:27:30 +0000
@@ -105,7 +105,7 @@
         self.import_wizard.progress_bar.setMaximum(len(self.import_source))
         if not isinstance(self.import_source, list):
             return
-        for file in self.import_source:
+        for import_file in self.import_source:
             # TODO: check that it is a valid SongBeamer file
             if self.stop_import_flag:
                 return
@@ -113,12 +113,13 @@
             self.currentVerse = ''
             self.currentVerseType = VerseType.tags[VerseType.Verse]
             read_verses = False
-            file_name = os.path.split(file)[1]
-            if os.path.isfile(file):
-                detect_file = open(file, 'r')
+            file_name = os.path.split(import_file)[1]
+            if os.path.isfile(import_file):
+                # First open in binary mode to detect the encoding
+                detect_file = open(import_file, 'rb')
                 details = chardet.detect(detect_file.read())
                 detect_file.close()
-                infile = codecs.open(file, 'r', details['encoding'])
+                infile = codecs.open(import_file, 'r', details['encoding'])
                 song_data = infile.readlines()
                 infile.close()
             else:
@@ -149,7 +150,7 @@
                 self.replaceHtmlTags()
                 self.addVerse(self.currentVerse, self.currentVerseType)
             if not self.finish():
-                self.logError(file)
+                self.logError(import_file)
 
     def replaceHtmlTags(self):
         """


Follow ups