An attempt to fix the problems some folks are having.

This commit is contained in:
Raoul Snyman 2010-01-31 21:49:01 +02:00
parent ab7125c98e
commit 2b5ddb13a4
12 changed files with 80 additions and 95 deletions

View File

@ -45,7 +45,7 @@ class BiblePlugin(Plugin):
def initialise(self): def initialise(self):
log.info(u'bibles Initialising') log.info(u'bibles Initialising')
if self.biblemanager is None: if self.biblemanager is None:
self.biblemanager = BibleManager(self.config) self.biblemanager = BibleManager(self, self.config)
Plugin.initialise(self) Plugin.initialise(self)
self.insert_toolbox_item() self.insert_toolbox_item()
self.ImportBibleItem.setVisible(True) self.ImportBibleItem.setVisible(True)
@ -90,4 +90,4 @@ class BiblePlugin(Plugin):
about_text = self.trUtf8('<strong>Bible Plugin</strong><br />This ' about_text = self.trUtf8('<strong>Bible Plugin</strong><br />This '
'plugin allows bible verses from different sources to be ' 'plugin allows bible verses from different sources to be '
'displayed on the screen during the service.') 'displayed on the screen during the service.')
return about_text return about_text

View File

@ -91,15 +91,6 @@ class Ui_BibleImportWizard(object):
self.OsisLayout.setMargin(0) self.OsisLayout.setMargin(0)
self.OsisLayout.setSpacing(8) self.OsisLayout.setSpacing(8)
self.OsisLayout.setObjectName(u'OsisLayout') self.OsisLayout.setObjectName(u'OsisLayout')
self.OsisBibleNameLabel = QtGui.QLabel(self.OsisPage)
self.OsisBibleNameLabel.setIndent(0)
self.OsisBibleNameLabel.setObjectName(u'OsisBibleNameLabel')
self.OsisLayout.setWidget(0, QtGui.QFormLayout.LabelRole,
self.OsisBibleNameLabel)
self.OsisBibleNameEdit = QtGui.QLineEdit(self.OsisPage)
self.OsisBibleNameEdit.setObjectName(u'OsisBibleNameEdit')
self.OsisLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
self.OsisBibleNameEdit)
self.OsisLocationLabel = QtGui.QLabel(self.OsisPage) self.OsisLocationLabel = QtGui.QLabel(self.OsisPage)
self.OsisLocationLabel.setObjectName(u'OsisLocationLabel') self.OsisLocationLabel.setObjectName(u'OsisLocationLabel')
self.OsisLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.OsisLayout.setWidget(1, QtGui.QFormLayout.LabelRole,
@ -307,7 +298,6 @@ class Ui_BibleImportWizard(object):
self.ImportLayout.addWidget(self.ImportProgressBar) self.ImportLayout.addWidget(self.ImportProgressBar)
BibleImportWizard.addPage(self.ImportPage) BibleImportWizard.addPage(self.ImportPage)
self.retranslateUi(BibleImportWizard) self.retranslateUi(BibleImportWizard)
self.FormatWidget.setCurrentIndex(0) self.FormatWidget.setCurrentIndex(0)
self.WebDownloadTabWidget.setCurrentIndex(0) self.WebDownloadTabWidget.setCurrentIndex(0)
@ -333,7 +323,6 @@ class Ui_BibleImportWizard(object):
self.FormatComboBox.setItemText(1, self.trUtf8('CSV')) self.FormatComboBox.setItemText(1, self.trUtf8('CSV'))
self.FormatComboBox.setItemText(2, self.trUtf8('OpenSong')) self.FormatComboBox.setItemText(2, self.trUtf8('OpenSong'))
self.FormatComboBox.setItemText(3, self.trUtf8('Web Download')) self.FormatComboBox.setItemText(3, self.trUtf8('Web Download'))
self.OsisBibleNameLabel.setText(self.trUtf8('Bible Name:'))
self.OsisLocationLabel.setText(self.trUtf8('File Location:')) self.OsisLocationLabel.setText(self.trUtf8('File Location:'))
self.BooksLocationLabel.setText(self.trUtf8('Books Location:')) self.BooksLocationLabel.setText(self.trUtf8('Books Location:'))
self.VerseLocationLabel.setText(self.trUtf8('Verse Location:')) self.VerseLocationLabel.setText(self.trUtf8('Verse Location:'))
@ -361,4 +350,4 @@ class Ui_BibleImportWizard(object):
self.ImportPage.setSubTitle( self.ImportPage.setSubTitle(
self.trUtf8('Please wait while your Bible is imported.')) self.trUtf8('Please wait while your Bible is imported.'))
self.ImportProgressLabel.setText(self.trUtf8('Ready.')) self.ImportProgressLabel.setText(self.trUtf8('Ready.'))
#self.ImportProgressBar.setFormat(u'%p') self.ImportProgressBar.setFormat(u'%p%')

View File

@ -27,6 +27,7 @@ import logging
import os import os
import os.path import os.path
from time import sleep from time import sleep
import csv
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -107,14 +108,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
elif self.currentId() == 1: elif self.currentId() == 1:
# Select page # Select page
if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS: if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS:
if self.field(u'osis_biblename').toString() == u'':
QtGui.QMessageBox.critical(self,
self.trUtf8('Invalid Bible Name'),
self.trUtf8('You need to specify a name for your '
'Bible!'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
self.OsisBibleNameEdit.setFocus()
return False
if self.field(u'osis_location').toString() == u'': if self.field(u'osis_location').toString() == u'':
QtGui.QMessageBox.critical(self, QtGui.QMessageBox.critical(self,
self.trUtf8('Invalid Bible Location'), self.trUtf8('Invalid Bible Location'),
@ -218,8 +211,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
def registerFields(self): def registerFields(self):
self.SelectPage.registerField( self.SelectPage.registerField(
u'source_format', self.FormatComboBox) u'source_format', self.FormatComboBox)
self.SelectPage.registerField(
u'osis_biblename', self.OsisBibleNameEdit)
self.SelectPage.registerField( self.SelectPage.registerField(
u'osis_location', self.OSISLocationEdit) u'osis_location', self.OSISLocationEdit)
self.SelectPage.registerField( self.SelectPage.registerField(
@ -247,7 +238,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
def setDefaults(self): def setDefaults(self):
self.setField(u'source_format', 0) self.setField(u'source_format', 0)
self.setField(u'osis_biblename', u'')
self.setField(u'osis_location', u'') self.setField(u'osis_location', u'')
self.setField(u'csv_booksfile', u'') self.setField(u'csv_booksfile', u'')
self.setField(u'csv_versefile', u'') self.setField(u'csv_versefile', u'')
@ -276,29 +266,33 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
fbibles = None fbibles = None
try: try:
self.web_bible_list[DownloadLocation.Crosswalk] = {} self.web_bible_list[DownloadLocation.Crosswalk] = {}
fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') books_file = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r')
for line in fbibles: dialect = csv.Sniffer().sniff(books_file.read(1024))
parts = line.split(u',') books_file.seek(0)
self.web_bible_list[DownloadLocation.Crosswalk][parts[0]] = \ books_reader = csv.reader(books_file, dialect)
parts[1].rstrip() for line in books_reader:
self.web_bible_list[DownloadLocation.Crosswalk][line[0]] = \
unicode(line[1], u'utf-8').strip()
except: except:
log.exception(u'Crosswalk resources missing') log.exception(u'Crosswalk resources missing')
finally: finally:
if fbibles: if books_file:
fbibles.close() books_file.close()
#Load and store BibleGateway Bibles #Load and store BibleGateway Bibles
try: try:
self.web_bible_list[DownloadLocation.BibleGateway] = {} self.web_bible_list[DownloadLocation.BibleGateway] = {}
fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r') books_file = open(os.path.join(filepath, u'biblegateway.csv'), 'r')
for line in fbibles: dialect = csv.Sniffer().sniff(books_file.read(1024))
parts = line.split(u',') books_file.seek(0)
self.web_bible_list[DownloadLocation.BibleGateway][parts[0]] = \ books_reader = csv.reader(books_file, dialect)
parts[1].rstrip() for line in books_reader:
self.web_bible_list[DownloadLocation.BibleGateway][line[0]] = \
unicode(line[1], u'utf-8').strip()
except: except:
log.exception(u'Biblegateway resources missing') log.exception(u'Biblegateway resources missing')
finally: finally:
if fbibles: if books_file:
fbibles.close() books_file.close()
def getFileName(self, title, editbox): def getFileName(self, title, editbox):
filename = QtGui.QFileDialog.getOpenFileName(self, title, filename = QtGui.QFileDialog.getOpenFileName(self, title,

View File

@ -37,13 +37,13 @@ class CSVBible(BibleDB):
This class provides a specialisation for importing of CSV Bibles. This class provides a specialisation for importing of CSV Bibles.
""" """
def __init__(self, **kwargs): def __init__(self, parent, **kwargs):
""" """
Loads a Bible from a pair of CVS files passed in Loads a Bible from a pair of CVS files passed in
This class assumes the files contain all the information and This class assumes the files contain all the information and
a clean bible is being loaded. a clean bible is being loaded.
""" """
BibleDB.__init__(self, **kwargs) BibleDB.__init__(self, parent, **kwargs)
log.info(self.__class__.__name__) log.info(self.__class__.__name__)
if u'booksfile' not in kwargs: if u'booksfile' not in kwargs:
raise KeyError(u'You have to supply a file to import books from.') raise KeyError(u'You have to supply a file to import books from.')

View File

@ -42,7 +42,7 @@ class BibleDB(QtCore.QObject):
rather than depending on yet another object. rather than depending on yet another object.
""" """
def __init__(self, **kwargs): def __init__(self, parent, **kwargs):
""" """
The constructor loads up the database and creates and initialises the The constructor loads up the database and creates and initialises the
tables if the database doesn't exist. tables if the database doesn't exist.
@ -60,6 +60,7 @@ class BibleDB(QtCore.QObject):
The configuration object, passed in from the plugin. The configuration object, passed in from the plugin.
""" """
log.info(u'BibleDBimpl loaded') log.info(u'BibleDBimpl loaded')
QtCore.QObject.__init__(self)
if u'path' not in kwargs: if u'path' not in kwargs:
raise KeyError(u'Missing keyword argument "path".') raise KeyError(u'Missing keyword argument "path".')
if u'name' not in kwargs: if u'name' not in kwargs:

View File

@ -142,7 +142,7 @@ class CWExtract(BibleCommon):
class HTTPBible(BibleDB): class HTTPBible(BibleDB):
log.info(u'%s loaded', __name__) log.info(u'%s loaded', __name__)
def __init__(self, **kwargs): def __init__(self, parent, **kwargs):
""" """
Finds all the bibles defined for the system Finds all the bibles defined for the system
Creates an Interface Object for each bible containing connection Creates an Interface Object for each bible containing connection
@ -152,7 +152,7 @@ class HTTPBible(BibleDB):
Init confirms the bible exists and stores the database path. Init confirms the bible exists and stores the database path.
""" """
BibleDB.__init__(self, **kwargs) BibleDB.__init__(self, parent, **kwargs)
if u'download_source' not in kwargs: if u'download_source' not in kwargs:
raise KeyError(u'Missing keyword argument "download_source"') raise KeyError(u'Missing keyword argument "download_source"')
if u'download_name' not in kwargs: if u'download_name' not in kwargs:
@ -267,13 +267,10 @@ class HTTPBible(BibleDB):
def set_books(self, books): def set_books(self, books):
self.books = books self.books = books
def lookup_book(self, book): def lookup_book(self, name):
log.debug('Looking up "%s" in %s', (book, self.books)) log.debug('Looking up "%s" in %s', (name, self.books))
if book in self.books: for book in self.books:
return self.books[book] if book[u'name'] == name or book[u'abbr'] == name:
else: return book
for details in self.books: return None
if self.books[details][u'abbr'] == book:
return self.books[details]
return None

View File

@ -90,7 +90,7 @@ class BibleManager(object):
log = logging.getLogger(u'BibleManager') log = logging.getLogger(u'BibleManager')
log.info(u'Bible manager loaded') log.info(u'Bible manager loaded')
def __init__(self, config): def __init__(self, parent, config):
""" """
Finds all the bibles defined for the system and creates an interface Finds all the bibles defined for the system and creates an interface
object for each bible containing connection information. Throws object for each bible containing connection information. Throws
@ -101,8 +101,9 @@ class BibleManager(object):
``config`` ``config``
The plugin's configuration object. The plugin's configuration object.
""" """
self.config = config
log.debug(u'Bible Initialising') log.debug(u'Bible Initialising')
self.config = config
self.parent = parent
self.web = u'Web' self.web = u'Web'
self.db_cache = None self.db_cache = None
self.http_cache = None self.http_cache = None
@ -120,18 +121,19 @@ class BibleManager(object):
filepath, u'..', u'resources', u'httpbooks.csv')) filepath, u'..', u'resources', u'httpbooks.csv'))
books_file = None books_file = None
try: try:
self.http_books = {} self.http_books = []
books_file = open(filepath, u'r') books_file = open(filepath, u'r')
dialect = csv.Sniffer().sniff(books_file.read(1024)) dialect = csv.Sniffer().sniff(books_file.read(1024))
books_file.seek(0) books_file.seek(0)
books_reader = csv.reader(books_file, dialect) books_reader = csv.reader(books_file, dialect)
for line in books_reader: for line in books_reader:
self.http_books[line[0]] = { self.http_books.append({
u'name': line[0], u'name': unicode(line[0]),
u'abbr': line[1], u'abbr': unicode(line[1]),
u'test': line[2], u'test': line[2],
u'chap': line[3] u'chap': line[3],
} u'ordr': order
})
except: except:
log.exception(u'Failed to load http books.') log.exception(u'Failed to load http books.')
finally: finally:
@ -148,13 +150,13 @@ class BibleManager(object):
self.web_bibles_present = False self.web_bibles_present = False
for filename in files: for filename in files:
name, extension = os.path.splitext(filename) name, extension = os.path.splitext(filename)
self.db_cache[name] = BibleDB(path=self.path, name=name, config=self.config) self.db_cache[name] = BibleDB(self.parent, path=self.path, name=name, config=self.config)
# look to see if lazy load bible exists and get create getter. # look to see if lazy load bible exists and get create getter.
source = self.db_cache[name].get_meta(u'download source') source = self.db_cache[name].get_meta(u'download source')
if source: if source:
self.web_bibles_present = True self.web_bibles_present = True
download_name = self.db_cache[name].get_meta(u'download name').value download_name = self.db_cache[name].get_meta(u'download name').value
web_bible = HTTPBible(path=self.path, name=name, web_bible = HTTPBible(self.parent, path=self.path, name=name,
config=self.config, download_source=source.value, config=self.config, download_source=source.value,
download_name=download_name) download_name=download_name)
meta_proxy = self.db_cache[name].get_meta(u'proxy url') meta_proxy = self.db_cache[name].get_meta(u'proxy url')
@ -187,7 +189,7 @@ class BibleManager(object):
class_ = BibleFormat.get_class(type) class_ = BibleFormat.get_class(type)
kwargs['path'] = self.path kwargs['path'] = self.path
kwargs['config'] = self.config kwargs['config'] = self.config
importer = class_(**kwargs) importer = class_(self.parent, **kwargs)
name = importer.register(self.import_wizard) name = importer.register(self.import_wizard)
self.db_cache[name] = importer self.db_cache[name] = importer
return importer.do_import() return importer.do_import()
@ -381,8 +383,12 @@ class BibleManager(object):
""" """
Check cache to see if new bible Check cache to see if new bible
""" """
if not isinstance(name, unicode):
name = unicode(name, u'utf8')
for bible, db_object in self.db_cache.iteritems(): for bible, db_object in self.db_cache.iteritems():
log.debug(u'Bible from cache in is_new_bible %s', bible) log.debug(u'Bible from cache in is_new_bible %s', bible)
if not isinstance(bible, unicode):
bible = unicode(bible, u'utf8')
if bible == name: if bible == name:
return True return True
return False return False

View File

@ -357,7 +357,7 @@ class BibleMediaItem(MediaManagerItem):
def onNoBookFound(self): def onNoBookFound(self):
QtGui.QMessageBox.critical(self, QtGui.QMessageBox.critical(self,
self.trUtf8('No Book Found'), self.trUtf8('No Book Found'),
self.trUtf8('No matching Book could be found in this Bible.'), self.trUtf8('No matching book could be found in this Bible.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
QtGui.QMessageBox.Ok QtGui.QMessageBox.Ok
) )

View File

@ -42,18 +42,18 @@ class OpenSongBible(BibleDB):
OpenSong Bible format importer class. OpenSong Bible format importer class.
""" """
def __init__(self, **kwargs): def __init__(self, parent, **kwargs):
""" """
Constructor to create and set up an instance of the OpenSongBible Constructor to create and set up an instance of the OpenSongBible
class. This class is used to import Bibles from OpenSong's XML format. class. This class is used to import Bibles from OpenSong's XML format.
""" """
log.debug(__name__) log.debug(__name__)
BibleDB.__init__(self, **kwargs) BibleDB.__init__(self, parent, **kwargs)
if 'filename' not in kwargs: if 'filename' not in kwargs:
raise KeyError(u'You have to supply a file name to import from.') raise KeyError(u'You have to supply a file name to import from.')
self.filename = kwargs['filename'] self.filename = kwargs['filename']
#QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
# QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) QtCore.SIGNAL(u'openlpstopimport'), self.stop_import)
def stop_import(self): def stop_import(self):
""" """
@ -69,27 +69,20 @@ class OpenSongBible(BibleDB):
log.debug(u'Starting OpenSong import from "%s"' % self.filename) log.debug(u'Starting OpenSong import from "%s"' % self.filename)
self.filename = unicode(self.filename, u'utf-8') self.filename = unicode(self.filename, u'utf-8')
self.wizard.incrementProgressBar(u'Preparing for import...') self.wizard.incrementProgressBar(u'Preparing for import...')
detect_file = None
try:
detect_file = open(self.filename, u'r')
details = chardet.detect(detect_file.read())
except:
log.exception(u'Failed to detect OpenSong file encoding')
return False
finally:
if detect_file:
detect_file.close()
file = None file = None
success = True success = True
try: try:
file = codecs.open(self.filename, u'r', details['encoding']) # NOTE: We don't need to do any of the normal encoding detection
# here, because lxml does it's own encoding detection, and the two
# mechanisms together interfere with each other.
file = open(self.filename, u'r')
opensong = objectify.parse(file) opensong = objectify.parse(file)
bible = opensong.getroot() bible = opensong.getroot()
for book in bible.b: for book in bible.b:
if self.stop_import: if self.stop_import:
break break
db_book = self.create_book(book.attrib[u'n'], db_book = self.create_book(unicode(book.attrib[u'n']),
book.attrib[u'n'][:4]) unicode(book.attrib[u'n'][:4]))
for chapter in book.c: for chapter in book.c:
if self.stop_import: if self.stop_import:
break break
@ -100,12 +93,12 @@ class OpenSongBible(BibleDB):
db_book.id, db_book.id,
int(chapter.attrib[u'n']), int(chapter.attrib[u'n']),
int(verse.attrib[u'n']), int(verse.attrib[u'n']),
verse.text unicode(verse.text)
) )
Receiver.send_message(u'process_events') Receiver.send_message(u'process_events')
self.wizard.incrementProgressBar( self.wizard.incrementProgressBar(
QtCore.QString('Importing %s %s' % \ QtCore.QString('%s %s %s' % (self.trUtf8('Importing'),\
(db_book.name, chapter.attrib[u'n']))) db_book.name, chapter.attrib[u'n'])))
self.commit() self.commit()
except: except:
log.exception(u'Loading bible from OpenSong file failed') log.exception(u'Loading bible from OpenSong file failed')

View File

@ -43,13 +43,13 @@ class OSISBible(BibleDB):
log = logging.getLogger(u'BibleOSISImpl') log = logging.getLogger(u'BibleOSISImpl')
log.info(u'BibleOSISImpl loaded') log.info(u'BibleOSISImpl loaded')
def __init__(self, **kwargs): def __init__(self, parent, **kwargs):
""" """
Constructor to create and set up an instance of the OpenSongBible Constructor to create and set up an instance of the OpenSongBible
class. This class is used to import Bibles from OpenSong's XML format. class. This class is used to import Bibles from OpenSong's XML format.
""" """
log.debug(__name__) log.debug(__name__)
BibleDB.__init__(self, **kwargs) BibleDB.__init__(self, parent, **kwargs)
if u'filename' not in kwargs: if u'filename' not in kwargs:
raise KeyError(u'You have to supply a file name to import from.') raise KeyError(u'You have to supply a file name to import from.')
self.filename = kwargs[u'filename'] self.filename = kwargs[u'filename']

View File

@ -153,10 +153,10 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
sxml.add_verse_to_lyrics(u'custom', unicode(count), sxml.add_verse_to_lyrics(u'custom', unicode(count),
unicode(self.VerseListView.item(i).text())) unicode(self.VerseListView.item(i).text()))
count += 1 count += 1
self.customSlide.title = unicode(self.TitleEdit.displayText()) self.customSlide.title = unicode(self.TitleEdit.displayText(), u'utf-8')
self.customSlide.text = unicode(sxml.extract_xml()) self.customSlide.text = unicode(sxml.extract_xml(), u'utf-8')
self.customSlide.credits = unicode(self.CreditEdit.displayText()) self.customSlide.credits = unicode(self.CreditEdit.displayText(), u'utf-8')
self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText()) self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText(), u'utf-8')
self.custommanager.save_slide(self.customSlide) self.custommanager.save_slide(self.customSlide)
return True return True
@ -257,4 +257,4 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
if len(self.VerseTextEdit.toPlainText()) > 0: if len(self.VerseTextEdit.toPlainText()) > 0:
self.VerseTextEdit.setFocus() self.VerseTextEdit.setFocus()
return False, self.trUtf8('You have unsaved data') return False, self.trUtf8('You have unsaved data')
return True, u'' return True, u''

View File

@ -185,8 +185,13 @@ class SongMediaItem(MediaManagerItem):
if author_list != u'': if author_list != u'':
author_list = author_list + u', ' author_list = author_list + u', '
author_list = author_list + author.display_name author_list = author_list + author.display_name
song_detail = unicode(self.trUtf8('%s (%s)' % \ if not isinstance(author_list, unicode):
(unicode(song.title), unicode(author_list)))) author_list = unicode(author_list, u'utf8')
if isinstance(song.title, unicode):
song_title = song.title
else:
song_title = unicode(song.title, u'utf8')
song_detail = u'%s (%s)' % (song_title, author_list)
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
self.ListView.addItem(song_name) self.ListView.addItem(song_name)
@ -339,4 +344,4 @@ class SongMediaItem(MediaManagerItem):
service_item.audit = [ service_item.audit = [
song.title, author_audit, song.copyright, song.ccli_number song.title, author_audit, song.copyright, song.ccli_number
] ]
return True return True