Use new strip_rtf routine and error trap

This commit is contained in:
Jonathan Corwin 2012-07-05 20:24:56 +01:00
parent 577be9a9c1
commit 614dc2648b
4 changed files with 12 additions and 3 deletions

View File

@ -476,7 +476,7 @@ def get_encoding(font, font_table, default_encoding, failed=False):
Dictionary of fonts and respective encodings.
``default_encoding``
The defaul encoding to use when font_table is empty or no font is used.
The default encoding to use when font_table is empty or no font is used.
``failed``
A boolean indicating whether the previous encoding didn't work.

View File

@ -28,6 +28,7 @@
"""
The :mod:`importer` modules provides the general song import functionality.
"""
import os
import logging
from openlp.core.lib import translate

View File

@ -56,8 +56,14 @@ class MediaShoutImport(SongImport):
"""
Receive a single file to import.
"""
conn = pyodbc.connect(u'DRIVER={Microsoft Access Driver (*.mdb)};'
try:
conn = pyodbc.connect(u'DRIVER={Microsoft Access Driver (*.mdb)};'
u'DBQ=%s;PWD=6NOZ4eHK7k' % self.importSource)
except: # Unfortunately no specific exception type
self.logError(self.importSource,
translate('SongsPlugin.MediaShoutImport',
'Unable to open the MediaShout database.'))
return
cursor = conn.cursor()
cursor.execute(u'SELECT Record, Title, Author, Copyright, '
u'SongID, CCLI, Notes FROM Songs ORDER BY Title')

View File

@ -81,6 +81,7 @@ class SongProImport(SongImport):
"""
Receive a single file or a list of files to import.
"""
self.encoding = None
with open(self.importSource, 'r') as songs_file:
self.importWizard.progressBar.setMaximum(0)
tag = u''
@ -112,7 +113,8 @@ class SongProImport(SongImport):
self.finish()
return
if u'rtf1' in text:
text = strip_rtf(text, u'cp1252').rstrip()
text, self.encoding = strip_rtf(text, self.encoding)
text = text.rstrip()
if not text:
return
if tag == u'A':