Fix Import for SongBeamer files

This commit is contained in:
s.mehrbrodt@gmail.com 2013-09-26 17:05:10 +02:00
parent f4ab0b23b8
commit 285508fd2d

View File

@ -33,6 +33,7 @@ import chardet
import codecs import codecs
import logging import logging
import os import os
import io
import re import re
from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib import VerseType
@ -105,7 +106,7 @@ class SongBeamerImport(SongImport):
self.import_wizard.progress_bar.setMaximum(len(self.import_source)) self.import_wizard.progress_bar.setMaximum(len(self.import_source))
if not isinstance(self.import_source, list): if not isinstance(self.import_source, list):
return return
for file in self.import_source: for _file in self.import_source:
# TODO: check that it is a valid SongBeamer file # TODO: check that it is a valid SongBeamer file
if self.stop_import_flag: if self.stop_import_flag:
return return
@ -113,12 +114,9 @@ class SongBeamerImport(SongImport):
self.currentVerse = '' self.currentVerse = ''
self.currentVerseType = VerseType.tags[VerseType.Verse] self.currentVerseType = VerseType.tags[VerseType.Verse]
read_verses = False read_verses = False
file_name = os.path.split(file)[1] file_name = os.path.split(_file)[1]
if os.path.isfile(file): if os.path.isfile(_file):
detect_file = open(file, 'r') infile = io.open(_file, 'r', encoding="Latin-1")
details = chardet.detect(detect_file.read())
detect_file.close()
infile = codecs.open(file, 'r', details['encoding'])
song_data = infile.readlines() song_data = infile.readlines()
infile.close() infile.close()
else: else:
@ -149,7 +147,7 @@ class SongBeamerImport(SongImport):
self.replaceHtmlTags() self.replaceHtmlTags()
self.addVerse(self.currentVerse, self.currentVerseType) self.addVerse(self.currentVerse, self.currentVerseType)
if not self.finish(): if not self.finish():
self.logError(file) self.logError(_file)
def replaceHtmlTags(self): def replaceHtmlTags(self):
""" """