From 34ab7ea901a50279dfd44bb224ef8bd32c9ca1d8 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 28 Dec 2009 01:54:00 +0200 Subject: [PATCH 01/20] Started moving Bible formats to a generic system. --- openlp/plugins/bibles/lib/common.py | 4 +- .../bibles/lib/{bibleCSVimpl.py => csv.py} | 21 ++--- .../bibles/lib/{bibleDBimpl.py => db.py} | 29 +++++-- .../bibles/lib/{bibleHTTPimpl.py => http.py} | 2 +- openlp/plugins/bibles/lib/manager.py | 78 ++++++++++++------- .../lib/{bibleOpenSongimpl.py => opensong.py} | 6 +- .../bibles/lib/{bibleOSISimpl.py => osis.py} | 2 +- 7 files changed, 92 insertions(+), 50 deletions(-) rename openlp/plugins/bibles/lib/{bibleCSVimpl.py => csv.py} (92%) rename openlp/plugins/bibles/lib/{bibleDBimpl.py => db.py} (89%) rename openlp/plugins/bibles/lib/{bibleHTTPimpl.py => http.py} (99%) rename openlp/plugins/bibles/lib/{bibleOpenSongimpl.py => opensong.py} (97%) rename openlp/plugins/bibles/lib/{bibleOSISimpl.py => osis.py} (99%) diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index fe8d18ff4..027cf6314 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -85,7 +85,9 @@ class BibleCommon(object): """ An empty constructor... not sure why I'm here. """ - pass + self.loadbible = True + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def _get_web_text(self, urlstring, proxyurl): """ diff --git a/openlp/plugins/bibles/lib/bibleCSVimpl.py b/openlp/plugins/bibles/lib/csv.py similarity index 92% rename from openlp/plugins/bibles/lib/bibleCSVimpl.py rename to openlp/plugins/bibles/lib/csv.py index 0f168bd10..e829f99a0 100644 --- a/openlp/plugins/bibles/lib/bibleCSVimpl.py +++ b/openlp/plugins/bibles/lib/csv.py @@ -26,23 +26,24 @@ import logging import chardet -from openlp.plugins.bibles.lib.common import BibleCommon +from openlp.plugins.bibles.lib.db import BibleDB from openlp.core.lib import Receiver -class BibleCSVImpl(BibleCommon): - global log - log = logging.getLogger(u'BibleCSVImpl') - log.info(u'BibleCVSImpl loaded') - def __init__(self, bibledb): +log = logging.getLogger(__name__) + +class CSVBible(BibleDB): + """ + This class provides a specialisation for importing of CSV Bibles. + """ + + def __init__(self, **kwargs): """ Loads a Bible from a pair of CVS files passed in This class assumes the files contain all the information and a clean bible is being loaded. """ - self.bibledb = bibledb - self.loadbible = True - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + log.info(__name__) + BibleDB.__init__(self, **kwargs) def stop_import(self): self.loadbible = False diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/db.py similarity index 89% rename from openlp/plugins/bibles/lib/bibleDBimpl.py rename to openlp/plugins/bibles/lib/db.py index ffc2f5c9b..260b3bda4 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/db.py @@ -27,17 +27,30 @@ import os import logging from common import BibleCommon -from openlp.plugins.bibles.lib.models import * +from models import * -class BibleDBImpl(BibleCommon): - global log - log = logging.getLogger(u'BibleDBImpl') - log.info(u'BibleDBimpl loaded') +log = logging.getLogger(__name__) - def __init__(self, biblepath, biblename, config): +class BibleDB(BibleCommon): + """ + This class represents a database-bound Bible. It is used as a base class + for all the custom importers, so that the can implement their own import + methods, but benefit from the database methods in here via inheritance, + rather than depending on yet another object. + """ + + def __init__(self, **kwargs): + log.info(u'BibleDBimpl loaded') + if u'biblepath' not in kwargs: + raise KeyError(u'Missing keyword argument "path".') + if u'biblename' not in kwargs: + raise KeyError(u'Missing keyword argument "name".') + if u'config' not in kwargs: + raise KeyError(u'Missing keyword argument "config".') # Connect to database - self.config = config - self.biblefile = os.path.join(biblepath, biblename + u'.sqlite') + self.config = kwargs[u'config'] + self.db_file = os.path.join(kwargs[u'path'], + u'%s.sqlite' % kwargs[u'biblename']) log.debug(u'Load bible %s on path %s', biblename, self.biblefile) db_type = self.config.get_config(u'db type', u'sqlite') db_url = u'' diff --git a/openlp/plugins/bibles/lib/bibleHTTPimpl.py b/openlp/plugins/bibles/lib/http.py similarity index 99% rename from openlp/plugins/bibles/lib/bibleHTTPimpl.py rename to openlp/plugins/bibles/lib/http.py index 6d57698c4..e20a2ca64 100644 --- a/openlp/plugins/bibles/lib/bibleHTTPimpl.py +++ b/openlp/plugins/bibles/lib/http.py @@ -171,7 +171,7 @@ class CWExtract(BibleCommon): bible[verse] = self._clean_text(verseText) return SearchResults(book_title, book_chapter, bible) -class BibleHTTPImpl(): +class HTTPBible(object): global log log = logging.getLogger(u'BibleHTTPMgr') log.info(u'BibleHTTP manager loaded') diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 9d0da8374..4d77bc32d 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -26,37 +26,59 @@ import logging import os -from bibleOpenSongimpl import BibleOpenSongImpl -from bibleOSISimpl import BibleOSISImpl -from bibleCSVimpl import BibleCSVImpl +from opensong import OpenSongBible +from osis import OSISBible +from csv import CSVBible from bibleDBimpl import BibleDBImpl from bibleHTTPimpl import BibleHTTPImpl class BibleMode(object): + """ + This is basically an enumeration class which specifies the mode of a Bible. + Mode refers to whether or not a Bible in OpenLP is a full Bible or needs to + be downloaded from the Internet on an as-needed basis. + """ Full = 1 Partial = 2 class BibleFormat(object): + """ + This is a special enumeration class that holds the various types of Bibles, + plus a few helper functions to facilitate generic handling of Bible types + for importing. + """ Unknown = -1 OSIS = 0 CSV = 1 OpenSong = 2 WebDownload = 3 - @classmethod - def get_handler(class_, id): - if id == class_.OSIS: + @staticmethod + def get_class(id): + """ + Return the appropriate imeplementation class. + """ + if id == BibleFormat.OSIS: return BibleOSISImpl - elif id == class_.CSV: + elif id == BibleFormat.CSV: return BibleCSVImpl - elif id == class_.OpenSong: + elif id == BibleFormat.OpenSong: return BibleOpenSongImpl - elif id == class_.WebDownload: + elif id == BibleFormat.WebDownload: return BibleHTTPImpl else: return None + @staticmethod + def list(): + return [ + BibleFormat.OSIS, + BibleFormat.CSV, + BibleFormat.OpenSong, + BibleFormat.WebDownload + ] + class BibleManager(object): """ @@ -84,11 +106,11 @@ class BibleManager(object): self.bible_db_cache = None # dict of bible http readers self.bible_http_cache = None - self.biblePath = self.config.get_data_path() + self.bible_path = self.config.get_data_path() #get proxy name for screen - self.proxyname = self.config.get_config(u'proxy name') - self.bibleSuffix = u'sqlite' - self.dialogobject = None + self.proxy_name = self.config.get_config(u'proxy name') + self.bible_suffix = u'sqlite' + self.import_wizard = None self.reload_bibles() self.media = None @@ -108,7 +130,7 @@ class BibleManager(object): for f in files: nme = f.split(u'.') bname = nme[0] - self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, + self.bible_db_cache[bname] = BibleDBImpl(self.bible_path, bname, self.config) # look to see if lazy load bible exists and get create getter. biblesource = self.bible_db_cache[bname].get_meta(u'WEB') @@ -139,7 +161,7 @@ class BibleManager(object): self.book_abbreviations = {} filepath = os.path.split(os.path.abspath(__file__))[0] filepath = os.path.abspath(os.path.join( - filepath, u'..', u'resources',u'httpbooks.csv')) + filepath, u'..', u'resources', u'httpbooks.csv')) fbibles = None try: fbibles = open(filepath, u'r') @@ -155,14 +177,14 @@ class BibleManager(object): fbibles.close() log.debug(u'Bible Initialised') - def set_process_dialog(self, dialogobject): + def set_process_dialog(self, wizard): """ Sets the reference to the dialog with the progress bar on it. - ``dialogobject`` - The reference to the dialog. + ``dialog`` + The reference to the import wizard. """ - self.dialogobject = dialogobject + self.import_wizard = wizard def import_bible(self, type, **kwargs): """ @@ -171,7 +193,11 @@ class BibleManager(object): ``type`` What type of Bible, """ - pass + impl_class = BibleFormat.get_handler(type) + bible_impl = impl_class(**kwargs) + bible_name = bible_impl.register() + BibleDBImpl(self.biblePath, bible_name, self.config) + bible_impl.do_import() def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None): @@ -202,7 +228,7 @@ class BibleManager(object): biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) if self._is_new_bible(biblename): # Create new Bible - nbible = BibleDBImpl(self.biblePath, biblename, self.config) + nbible = BibleDBImpl(self.bible_path, biblename, self.config) # Create Database nbible.create_tables() self.bible_db_cache[biblename] = nbible @@ -239,7 +265,7 @@ class BibleManager(object): biblename, booksfile, versefile) if self._is_new_bible(biblename): # Create new Bible - nbible = BibleDBImpl(self.biblePath, biblename, self.config) + nbible = BibleDBImpl(self.bible_path, biblename, self.config) # Create database nbible.create_tables() # Cache the database for use later @@ -261,13 +287,13 @@ class BibleManager(object): log.debug(u'register_OSIS_file_bible %s, %s', biblename, osisfile) if self._is_new_bible(biblename): # Create new Bible - nbible = BibleDBImpl(self.biblePath, biblename, self.config) + nbible = BibleDBImpl(self.bible_path, biblename, self.config) # Create Database nbible.create_tables() # Cache the database for use later self.bible_db_cache[biblename] = nbible # Create the loader and pass in the database - bosis = BibleOSISImpl(self.biblePath, nbible) + bosis = BibleOSISImpl(self.bible_path, nbible) return bosis.load_data(osisfile, self.dialogobject) else: log.debug( @@ -283,13 +309,13 @@ class BibleManager(object): log.debug(u'register_opensong_file_bible %s, %s', biblename, opensongfile) if self._is_new_bible(biblename): # Create new Bible - nbible = BibleDBImpl(self.biblePath, biblename, self.config) + nbible = BibleDBImpl(self.bible_path, biblename, self.config) # Create Database nbible.create_tables() # Cache the database for use later self.bible_db_cache[biblename] = nbible # Create the loader and pass in the database - bcsv = BibleOpenSongImpl(self.biblePath, nbible) + bcsv = BibleOpenSongImpl(self.bible_path, nbible) bcsv.load_data(opensongfile, self.dialogobject) return True else: diff --git a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py b/openlp/plugins/bibles/lib/opensong.py similarity index 97% rename from openlp/plugins/bibles/lib/bibleOpenSongimpl.py rename to openlp/plugins/bibles/lib/opensong.py index 58b9ffcd0..7ede58249 100644 --- a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -34,7 +34,7 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver -class BibleOpenSongImpl(): +class OpenSongBible(object): """ OSIS Bible format importer class. """ @@ -81,10 +81,10 @@ class BibleOpenSongImpl(): detect_file = None try: detect_file = open(bible_file, u'r') - details = chardet.detect(detect_file.read(2048)) + details = chardet.detect(detect_file.read(3000)) except: log.exception(u'Failed to detect OpenSong file encoding') - return + return False finally: if detect_file: detect_file.close() diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/osis.py similarity index 99% rename from openlp/plugins/bibles/lib/bibleOSISimpl.py rename to openlp/plugins/bibles/lib/osis.py index 15b16c072..62beb6e15 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -34,7 +34,7 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver -class BibleOSISImpl(): +class OSISBible(object): """ OSIS Bible format importer class. """ From 0374233db6137b2ea33c86a865ca8af6b3443e8e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 30 Dec 2009 19:29:08 +0200 Subject: [PATCH 02/20] Lots of changes here, I think. - Pluggable import system - The enumeration class provides the correct importer class - Reworked Bible verse parsing, using regular expressions - Reworked verse query method to accept multiple verse ranges - Renamed lots of methods, which is probably gonna break lots of stuff --- .../plugins/bibles/forms/importwizardform.py | 44 ++- openlp/plugins/bibles/lib/common.py | 65 +++- openlp/plugins/bibles/lib/csv.py | 52 ++- openlp/plugins/bibles/lib/db.py | 323 +++++++++++------- openlp/plugins/bibles/lib/http.py | 81 +++-- openlp/plugins/bibles/lib/manager.py | 111 +++--- openlp/plugins/bibles/lib/mediaitem.py | 9 +- openlp/plugins/bibles/lib/models.py | 4 +- openlp/plugins/bibles/lib/opensong.py | 84 ++--- openlp/plugins/bibles/lib/osis.py | 67 ++-- 10 files changed, 474 insertions(+), 366 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 22fbea989..9bf6b51c1 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -169,6 +169,15 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.CopyrightEdit.setFocus() return False + elif self.biblemanager.exists( + self.field(u'license_version').toString()): + QtGui.QMessageBox.critical(self, + self.trUtf8('Bible Exists'), + self.trUtf8('This Bible already exists! Please import ' + 'a different Bible or first delete the existing one.'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.VersionNameEdit.setFocus() + return False return True if self.currentId() == 3: # Progress page @@ -317,22 +326,22 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): success = False if bible_type == BibleFormat.OSIS: # Import an OSIS bible - success = self.biblemanager.register_osis_file_bible( - unicode(self.field(u'license_version').toString()), - unicode(self.field(u'osis_location').toString()) + success = self.biblemanager.import_bible(BibleFormat.OSIS, + name=unicode(self.field(u'license_version').toString()), + filename=unicode(self.field(u'osis_location').toString()) ) elif bible_type == BibleFormat.CSV: # Import a CSV bible - success = self.biblemanager.register_csv_file_bible( - unicode(self.field(u'license_version').toString()), - self.field(u'csv_booksfile').toString(), - self.field(u'csv_versefile').toString() + success = self.biblemanager.import_bible(BibleFormat.CSV, + name=unicode(self.field(u'license_version').toString()), + booksfile=self.field(u'csv_booksfile').toString(), + versefile=self.field(u'csv_versefile').toString() ) elif bible_type == BibleFormat.OpenSong: # Import an OpenSong bible - success = self.biblemanager.register_opensong_bible( - unicode(self.field(u'license_version').toString()), - self.field(u'opensong_file').toString() + success = self.biblemanager.import_bible(BibleFormat.OpenSong, + name=unicode(self.field(u'license_version').toString()), + filename=self.field(u'opensong_file').toString() ) elif bible_type == BibleFormat.WebDownload: # Import a bible from the web @@ -344,13 +353,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): elif download_location == DownloadLocation.BibleGateway: bible = self.web_bible_list[DownloadLocation.BibleGateway][ unicode(self.BibleComboBox.currentText())] - success = self.biblemanager.register_http_bible( - unicode(self.field(u'license_version').toString()), - unicode(DownloadLocation.get_name(download_location)), - unicode(bible), - unicode(self.field(u'proxy_server').toString()), - unicode(self.field(u'proxy_username').toString()), - unicode(self.field(u'proxy_password').toString()) + success = self.biblemanager.import_bible(BibleFormat.WebDownload, + name=unicode(self.field(u'license_version').toString()), + download_source=unicode(DownloadLocation.get_name(download_location)), + download_name=unicode(bible), + proxy_server=unicode(self.field(u'proxy_server').toString()), + proxy_username=unicode(self.field(u'proxy_username').toString()), + proxy_password=unicode(self.field(u'proxy_password').toString()) ) if success: self.biblemanager.save_meta_data( @@ -359,6 +368,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): unicode(self.field(u'license_copyright').toString()), unicode(self.field(u'license_permission').toString()) ) + self.biblemanager.reload_bibles() self.ImportProgressLabel.setText(self.trUtf8('Finished import.')) else: self.ImportProgressLabel.setText( diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index 027cf6314..b40c483ba 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -26,6 +26,63 @@ import urllib2 import chardet import logging +import re + +only_verses = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)' + r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?', + re.UNICODE) +chapter_range = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*' + r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)', + re.UNICODE) + +def parse_reference(reference): + """ + This is the über-awesome function that takes a person's typed in string + and converts it to a reference list, a list of references to be queried + from the Bible database files. + + The reference list is a list of tuples, with each tuple structured like + this:: + + (book, chapter, start_verse, end_verse) + """ + reference = reference.strip() + reference_list = [] + # We start with the most "complicated" match first, so that they are found + # first, and we don't have any "false positives". + match = chapter_range.match(reference) + if match: + reference_list.extend([ + (match.group(1), match.group(2), match.group(3), -1), + (match.group(1), match.group(4), 1, match.group(5)) + ]) + else: + match = only_verses.match(reference) + if match: + book = match.group(1) + chapter = match.group(2) + verse = match.group(3) + if match.group(4) is None: + reference_list.append((book, chapter, verse, verse)) + elif match.group(5) is None: + end_verse = match.group(4) + if end_verse == u'end': + end_verse = -1 + reference_list.append((book, chapter, verse, end_verse)) + elif match.group(6) is None: + reference_list.extend([ + (book, chapter, verse, match.group(4)), + (book, chapter, match.group(5), match.group(5)) + ]) + else: + end_verse = match.group(6) + if end_verse == u'end': + end_verse = -1 + reference_list.extend([ + (book, chapter, verse, match.group(4)), + (book, chapter, match.group(5), end_verse) + ]) + return reference_list class SearchResults: """ @@ -81,14 +138,6 @@ class BibleCommon(object): log = logging.getLogger(u'BibleCommon') log.info(u'BibleCommon') - def __init__(self): - """ - An empty constructor... not sure why I'm here. - """ - self.loadbible = True - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) - def _get_web_text(self, urlstring, proxyurl): """ Get the HTML from the web page. diff --git a/openlp/plugins/bibles/lib/csv.py b/openlp/plugins/bibles/lib/csv.py index e829f99a0..c74452fd3 100644 --- a/openlp/plugins/bibles/lib/csv.py +++ b/openlp/plugins/bibles/lib/csv.py @@ -26,8 +26,8 @@ import logging import chardet -from openlp.plugins.bibles.lib.db import BibleDB from openlp.core.lib import Receiver +from db import BibleDB log = logging.getLogger(__name__) @@ -44,20 +44,22 @@ class CSVBible(BibleDB): """ log.info(__name__) BibleDB.__init__(self, **kwargs) + if u'booksfile' not in kwargs: + raise KeyError(u'You have to supply a file to import books from.') + self.booksfile = kwargs[u'booksfile'] + if u'versesfile' not in kwargs: + raise KeyError(u'You have to supply a file to import verses from.') + self.versesfile = kwargs[u'versesfile'] - def stop_import(self): - self.loadbible = False - - def load_data(self, booksfile, versesfile, dialogobject): + def do_import(self): #Populate the Tables success = True fbooks = None try: - fbooks = open(booksfile, 'r') - count = 0 + fbooks = open(self.booksfile, 'r') for line in fbooks: # cancel pressed - if not self.loadbible: + if self.stop_import: break details = chardet.detect(line) line = unicode(line, details['encoding']) @@ -65,12 +67,8 @@ class CSVBible(BibleDB): p1 = p[1].replace(u'"', u'') p2 = p[2].replace(u'"', u'') p3 = p[3].replace(u'"', u'') - self.bibledb.create_book(p2, p3, int(p1)) - count += 1 - #Flush the screen events - if count % 3 == 0: - Receiver.send_message(u'process_events') - count = 0 + self.create_book(p2, p3, int(p1)) + Receiver.send_message(u'process_events') except: log.exception(u'Loading books from file failed') success = False @@ -82,10 +80,9 @@ class CSVBible(BibleDB): fverse = None try: fverse = open(versesfile, 'r') - count = 0 book_ptr = None for line in fverse: - if not self.loadbible: # cancel pressed + if self.stop_import: # cancel pressed break details = chardet.detect(line) line = unicode(line, details['encoding']) @@ -94,28 +91,23 @@ class CSVBible(BibleDB): p0 = p[0].replace(u'"', u'') p3 = p[3].replace(u'"', u'') if book_ptr is not p0: - book = self.bibledb.get_bible_book(p0) + book = self.get_book(p0) book_ptr = book.name # increament the progress bar - dialogobject.incrementProgressBar(u'Importing %s %s' % \ - book.name) - self.bibledb.add_verse(book.id, p[1], p[2], p3) - count += 1 - #Every x verses repaint the screen - if count % 3 == 0: - Receiver.send_message(u'process_events') - count = 0 - self.bibledb.save_verses() + self.wizard.incrementProgressBar( + u'Importing %s %s' % book.name) + self.commit() + self.add_verse(book.id, p[1], p[2], p3) + Receiver.send_message(u'process_events') + self.commit() except: log.exception(u'Loading verses from file failed') success = False finally: if fverse: fverse.close() - if not self.loadbible: - dialogobject.incrementProgressBar(u'Import canceled!') - dialogobject.ImportProgressBar.setValue( - dialogobject.ImportProgressBar.maximum()) + if self.stop_import: + self.wizard.incrementProgressBar(u'Import canceled!') return False else: return success diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 260b3bda4..b1e228ee4 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -26,12 +26,15 @@ import os import logging -from common import BibleCommon +from sqlalchemy import or_ +from PyQt4 import QtCore + +from openlp.core.lib import Receiver from models import * log = logging.getLogger(__name__) -class BibleDB(BibleCommon): +class BibleDB(): """ This class represents a database-bound Bible. It is used as a base class for all the custom importers, so that the can implement their own import @@ -40,22 +43,39 @@ class BibleDB(BibleCommon): """ def __init__(self, **kwargs): + """ + The constructor loads up the database and creates and initialises the + tables if the database doesn't exist. + + **Required keyword arguments:** + + ``path`` + The path to the bible database file. + + ``name`` + The name of the database. This is also used as the file name for + SQLite databases. + + ``config`` + The configuration object, passed in from the plugin. + """ log.info(u'BibleDBimpl loaded') - if u'biblepath' not in kwargs: + if u'path' not in kwargs: raise KeyError(u'Missing keyword argument "path".') - if u'biblename' not in kwargs: + if u'name' not in kwargs: raise KeyError(u'Missing keyword argument "name".') if u'config' not in kwargs: raise KeyError(u'Missing keyword argument "config".') - # Connect to database + self.stop_import = False + self.name = kwargs[u'name'] self.config = kwargs[u'config'] self.db_file = os.path.join(kwargs[u'path'], - u'%s.sqlite' % kwargs[u'biblename']) - log.debug(u'Load bible %s on path %s', biblename, self.biblefile) + u'%s.sqlite' % kwargs[u'name']) + log.debug(u'Load bible %s on path %s', kwargs[u'name'], self.db_file) db_type = self.config.get_config(u'db type', u'sqlite') db_url = u'' if db_type == u'sqlite': - db_url = u'sqlite:///' + self.biblefile + db_url = u'sqlite:///' + self.db_file else: db_url = u'%s://%s:%s@%s/%s' % \ (db_type, self.config.get_config(u'db username'), @@ -65,134 +85,200 @@ class BibleDB(BibleCommon): self.metadata, self.session = init_models(db_url) self.metadata.create_all(checkfirst=True) + def register(self): + """ + This method basically just initialialises the database. It is called + from the Bible Manager when a Bible is imported. Descendant classes + may want to override this method to supply their own custom + initialisation as well. + """ + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + self.create_tables() + return self.name + + def stop_import(self): + """ + Stops the import of the Bible. + """ + log.debug('Stopping import!') + self.stop_import = True + + def commit(self): + log.debug('Committing...') + self.session.commit() + def create_tables(self): log.debug(u'createTables') self.save_meta(u'dbversion', u'2') - self._load_testament(u'Old Testament') - self._load_testament(u'New Testament') - self._load_testament(u'Apocrypha') + self.create_testament(u'Old Testament') + self.create_testament(u'New Testament') + self.create_testament(u'Apocrypha') - def add_verse(self, bookid, chap, vse, text): - verse = Verse() - verse.book_id = bookid - verse.chapter = chap - verse.verse = vse - verse.text = text + def create_testament(self, testament): + log.debug(u'%s: %s', __name__, testament) + self.session.add(Testament.populate(name=testament)) + self.commit() + + def create_book(self, name, abbrev, testament=1): + log.debug(u'create_book %s,%s', bookname, bookabbrev) + book = Book.populate(name=name, abbreviation=abbrev, + testament_id=testament) + self.session.add(book) + self.commit() + return book + + def create_chapter(self, book_id, chapter, textlist): + log.debug(u'create_chapter %s,%s', bookid, chap) + #text list has book and chapter as first two elements of the array + for verse_number, verse_text in textlist.iteritems(): + verse = Verse.populate( + book_id = book_id, + chapter = chap, + verse = verse_number, + text = verse_text + ) + self.session.add(verse) + self.commit() + + def create_verse(self, book_id, chapter, verse, text): + verse = Verse.populate( + book_id=book_id, + chapter=chapter, + verse=verse, + text=text + ) self.session.add(verse) return verse - def save_verses(self): - log.debug('Saving verses...') - self.session.commit() - - def create_chapter(self, bookid, chap, textlist): - log.debug(u'create_chapter %s,%s', bookid, chap) - #text list has book and chapter as first to elements of the array - for verse_number, verse_text in textlist.iteritems(): - verse = Verse() - verse.book_id = bookid - verse.chapter = chap - verse.verse = verse_number - verse.text = verse_text - self.session.add(verse) - self.session.commit() - - def create_book(self, bookname, bookabbrev, testament=1): - log.debug(u'create_book %s,%s', bookname, bookabbrev) - book = Book() - book.testament_id = testament - book.name = bookname - book.abbreviation = bookabbrev - self.session.add(book) - self.session.commit() - return book - - def save_meta(self, key, value): + def create_meta(self, key, value): log.debug(u'save_meta %s/%s', key, value) - bmeta = BibleMeta() - bmeta.key = key - bmeta.value = value - self.session.add(bmeta) - self.session.commit() + self.session.add(BibleMeta.populate(key=key, value=value)) + self.commit() - def get_meta(self, metakey): - log.debug(u'get meta %s', metakey) - return self.session.query(BibleMeta).filter_by(key=metakey).first() + def get_books(self): + log.debug(__name__) + return self.session.query(Book).order_by(Book.id).all() + + def get_book(self, book): + log.debug(u'%s: %s', __name__, book) + db_book = self.session.query(Book)\ + .filter_by(Book.name.like(book + u'%'))\ + .first() + if db_book is None: + db_book = self.session.query(Book)\ + .filter(Book.abbreviation.like(book + u'%'))\ + .first() + return db_book + + def get_chapter(self, id, chapter): + log.debug(u'%s: %s, %s', __name__, id, chapter) + return self.session.query(Verse)\ + .filter_by(chapter=chapter)\ + .filter_by(book_id=id)\ + .first() + + def get_verses(self, reference_list): + """ + This is probably the most used function. It retrieves the list of + verses based on the user's query. + + ``reference_list`` + This is the list of references the media manager item wants. It is + a list of tuples, with the following format:: + + (book, chapter, start_verse, end_verse) + + Therefore, when you are looking for multiple items, simply break + them up into references like this, bundle them into a list. This + function then runs through the list, and returns an amalgamated + list of ``Verse`` objects. For example:: + + [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] + """ + log.debug(u'%s: %s', __name__, reference_list) + verse_list = [] + for book, chapter, start_verse, end_verse in reference_list: + db_book = self.get_book(book) + if end_verse == -1: + end_verse = self.get_chapter_count(book) + if db_book: + book = book.name + log.debug(u'Book name corrected to "%s"' % book) + verses = self.session.query(Verse)\ + .filter_by(book_id=book.id)\ + .filter_by(chapter=chapter)\ + .filter(Verse.verse >= start_verse)\ + .filter(Verse.verse <= end_verse)\ + .order_by(Verse.verse)\ + .all() + verse_list.extend(verses) + return verse_list + + def verse_search(self, text): + """ + Search for verses containing text ``text``. + + ``text`` + The text to search for. If the text contains commas, it will be + split apart and OR'd on the list of values. If the text just + contains spaces, it will split apart and AND'd on the list of + values. + """ + log.debug(u'%s: %s', __name__, text) + verses = self.session.query(Verse) + if text.find(u',') > -1: + or_clause = [] + keywords = [u'%%%s%%' % keyword.strip() for keyword in text.split(u',')] + for keyword in keywords: + or_clause.append(Verse.text.like(keyword)) + verses = verses.filter(or_(*or_clause)) + else: + keywords = [u'%%%s%%' % keyword.strip() for keyword in text.split(u' ')] + for keyword in keywords: + verses = verses.filter(Verse.text.like(keyword)) + verses = verses.all() + return verses + + def get_chapter_count(self, book): + log.debug(u'%s: %s', __name__, book) + count = self.session.query(Verse.chapter).join(Book)\ + .filter(Book.name==book)\ + .distinct().count() + #verse = self.session.query(Verse).join(Book).filter( + # Book.name == bookname).order_by(Verse.chapter.desc()).first() + if not count: + return 0 + else: + return count + + def get_verse_count(self, book, chapter): + log.debug(u'%s: %s, %s', __name__, book, chapter) + count = self.session.query(Verse).join(Book)\ + .filter(Book.name==book)\ + .filter(Verse.chapter==chapter)\ + .count() + #verse = self.session.query(Verse).join(Book).filter( + # Book.name == bookname).filter( + # Verse.chapter == chapter).order_by(Verse.verse.desc()).first() + if not count: + return 0 + else: + return count + + def get_meta(self, key): + log.debug(u'get meta %s', key) + return self.session.query(BibleMeta).get(key) def delete_meta(self, metakey): biblemeta = self.get_meta(metakey) try: self.session.delete(biblemeta) - self.session.commit() + self.commit() return True except: return False - def _load_testament(self, testament): - log.debug(u'load_testaments %s', testament) - test = ONTestament() - test.name = testament - self.session.add(test) - self.session.commit() - - def get_bible_books(self): - log.debug(u'get_bible_books') - return self.session.query(Book).order_by(Book.id).all() - - def get_max_bible_book_verses(self, bookname, chapter): - log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter) - verse = self.session.query(Verse).join(Book).filter( - Book.name == bookname).filter( - Verse.chapter == chapter).order_by(Verse.verse.desc()).first() - if verse == None: - return 0 - else: - return verse.verse - - def get_max_bible_book_chapter(self, bookname): - log.debug(u'get_max_bible_book_chapter %s', bookname) - verse = self.session.query(Verse).join(Book).filter( - Book.name == bookname).order_by(Verse.chapter.desc()).first() - if verse == None: - return 0 - else: - return verse.chapter - - def get_bible_book(self, bookname): - log.debug(u'get_bible_book %s', bookname) - book = self.session.query(Book).filter( - Book.name.like(bookname + u'%')).first() - if book is None: - book = self.session.query(Book).filter( - Book.abbreviation.like(bookname + u'%')).first() - return book - - def get_bible_chapter(self, id, chapter): - log.debug(u'get_bible_chapter %s, %s', id, chapter) - return self.session.query(Verse).filter_by(chapter=chapter).filter_by( - book_id=id).first() - - def get_bible_text(self, bookname, chapter, sverse, everse): - log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, - everse) - #Look up book name or abbreviation - book = self.get_bible_book(bookname) - if book: - bookname = book.name - log.debug(u'bookname corrected to %s' % bookname) - verses = self.session.query(Verse).join(Book).filter( - Book.name == bookname).filter(Verse.chapter == chapter).filter( - Verse.verse>=sverse).filter(Verse.verse<=everse).order_by( - Verse.verse).all() - return verses - - def get_verses_from_text(self, versetext): - log.debug(u'get_verses_from_text %s',versetext) - versetext = u'%%%s%%' % versetext - verses = self.session.query(Verse).filter( - Verse.text.like(versetext)).all() - return verses - def dump_bible(self): log.debug( u'.........Dumping Bible Database') log.debug( '...............................Books ') @@ -201,3 +287,4 @@ class BibleDB(BibleCommon): log.debug( u'...............................Verses ') verses = self.session.query(Verse).all() log.debug(verses) + diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index e20a2ca64..57e6e4a16 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -26,17 +26,18 @@ import logging from common import BibleCommon, SearchResults +from db import BibleDB class BGExtract(BibleCommon): global log log = logging.getLogger(u'BibleHTTPMgr(BG_extract)') log.info(u'BG_extract loaded') - def __init__(self, proxyurl= None): + def __init__(self, proxyurl=None): log.debug(u'init %s', proxyurl) self.proxyurl = proxyurl - def get_bible_chapter(self, version, bookname, chapter) : + def get_chapter(self, version, bookname, chapter) : """ Access and decode bibles via the BibleGateway website @@ -49,12 +50,10 @@ class BGExtract(BibleCommon): ``chapter`` Chapter number """ - log.debug(u'get_bible_chapter %s,%s,%s', - version, bookname, chapter) - urlstring = \ - u'http://www.biblegateway.com/passage/?search=%s+%d&version=%s' % \ - (bookname, chapter, version) - log.debug(u'BibleGateway urm = %s' % urlstring) + log.debug(u'get_bible_chapter %s, %s, %s', version, bookname, chapter) + urlstring = u'http://www.biblegateway.com/passage/?search=%s+%d' \ + u'&version=%s' % (bookname, chapter, version) + log.debug(u'BibleGateway url = %s' % urlstring) xml_string = self._get_web_text(urlstring, self.proxyurl) verseSearch = u'(.*?)') self.note_regex = re.compile(r'(.*?)') @@ -66,13 +65,11 @@ class OSISBible(object): self.w_regex = re.compile(r'') self.q_regex = re.compile(r'') self.spaces_regex = re.compile(r'([ ]{2,})') - self.bibledb = bibledb self.books = {} filepath = os.path.split(os.path.abspath(__file__))[0] filepath = os.path.abspath(os.path.join( filepath, u'..', u'resources', u'osisbooks.csv')) fbibles = None - self.loadbible = True try: fbibles = open(filepath, u'r') for line in fbibles: @@ -84,31 +81,15 @@ class OSISBible(object): finally: if fbibles: fbibles.close() - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) - def stop_import(self): - """ - Stops the import of the Bible. - """ - log.debug('Stopping import!') - self.loadbible = False - - def load_data(self, osisfile_record, dialogobject=None): + def do_import(self): """ Loads a Bible from file. - - ``osisfile_record`` - The file to import from. - - ``dialogobject`` - The Import dialog, so that we can increase the counter on - the progress bar. """ - log.info(u'Load data for %s' % osisfile_record) + log.debug(u'Starting OSIS import from "%s"' % self.filename) detect_file = None try: - detect_file = open(osisfile_record, u'r') + detect_file = open(self.filename, u'r') details = chardet.detect(detect_file.read(3000)) except: log.exception(u'Failed to detect OSIS file encoding') @@ -119,12 +100,12 @@ class OSISBible(object): osis = None success = True try: - osis = codecs.open(osisfile_record, u'r', details['encoding']) + osis = codecs.open(self.filename, u'r', details['encoding']) last_chapter = 0 testament = 1 db_book = None for file_record in osis: - if not self.loadbible: + if self.stop_import: break match = self.verse_regex.search(file_record) if match: @@ -142,13 +123,13 @@ class OSISBible(object): testament) if last_chapter == 0: if book == u'Gen': - dialogobject.ImportProgressBar.setMaximum(1188) + self.wizard.ImportProgressBar.setMaximum(1188) else: - dialogobject.ImportProgressBar.setMaximum(260) + self.wizard.ImportProgressBar.setMaximum(260) if last_chapter != chapter: if last_chapter != 0: self.bibledb.save_verses() - dialogobject.incrementProgressBar( + self.wizard.incrementProgressBar( u'Importing %s %s...' % \ (self.books[match.group(1)][0], chapter)) last_chapter = chapter @@ -170,20 +151,18 @@ class OSISBible(object): .replace(u'', u'').replace(u'', u'')\ .replace(u'', u'') verse_text = self.spaces_regex.sub(u' ', verse_text) - self.bibledb.add_verse(db_book.id, chapter, verse, verse_text) + self.add_verse(db_book.id, chapter, verse, verse_text) Receiver.send_message(u'process_events') - self.bibledb.save_verses() - dialogobject.incrementProgressBar(u'Finishing import...') + self.commit() + self.wizard.incrementProgressBar(u'Finishing import...') except: log.exception(u'Loading bible from OSIS file failed') success = False finally: if osis: osis.close() - if not self.loadbible: - dialogobject.incrementProgressBar(u'Import canceled!') - dialogobject.ImportProgressBar.setValue( - dialogobject.ImportProgressBar.maximum()) + if self.stop_import: + self.wizard.incrementProgressBar(u'Import canceled!') return False else: return success From 027d6d3e4e7a3fc91af217a8b53a0fe42c327ece Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Jan 2010 17:03:16 +0200 Subject: [PATCH 03/20] Moved the stop import out of the base class, since Qt doesn't like it. --- openlp/plugins/bibles/lib/csv.py | 9 +++++++++ openlp/plugins/bibles/lib/db.py | 12 +----------- openlp/plugins/bibles/lib/opensong.py | 9 +++++++++ openlp/plugins/bibles/lib/osis.py | 9 +++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/bibles/lib/csv.py b/openlp/plugins/bibles/lib/csv.py index c74452fd3..099b3f1fa 100644 --- a/openlp/plugins/bibles/lib/csv.py +++ b/openlp/plugins/bibles/lib/csv.py @@ -50,6 +50,15 @@ class CSVBible(BibleDB): if u'versesfile' not in kwargs: raise KeyError(u'You have to supply a file to import verses from.') self.versesfile = kwargs[u'versesfile'] + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + + def stop_import(self): + """ + Stops the import of the Bible. + """ + log.debug('Stopping import!') + self.stop_import = True def do_import(self): #Populate the Tables diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index b1e228ee4..088bd68e8 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -29,8 +29,7 @@ import logging from sqlalchemy import or_ from PyQt4 import QtCore -from openlp.core.lib import Receiver -from models import * +from openlp.plugins.bibles.lib.models import * log = logging.getLogger(__name__) @@ -92,18 +91,9 @@ class BibleDB(): may want to override this method to supply their own custom initialisation as well. """ - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) self.create_tables() return self.name - def stop_import(self): - """ - Stops the import of the Bible. - """ - log.debug('Stopping import!') - self.stop_import = True - def commit(self): log.debug('Committing...') self.session.commit() diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 2442040de..a73d0e3c6 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -52,6 +52,15 @@ class OpenSongBible(BibleDB): if u'filename' not in kwargs: raise KeyError(u'You have to supply a file name to import from.') self.filename = kwargs[u'filename'] + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + + def stop_import(self): + """ + Stops the import of the Bible. + """ + log.debug('Stopping import!') + self.stop_import = True def do_import(self): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 17cb34180..f16c1cd02 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -81,6 +81,15 @@ class OSISBible(BibleDB): finally: if fbibles: fbibles.close() + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + + def stop_import(self): + """ + Stops the import of the Bible. + """ + log.debug('Stopping import!') + self.stop_import = True def do_import(self): """ From a976d6b59ac54754c670175b182a5daa3f1af1ff Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 17 Jan 2010 18:48:45 +0200 Subject: [PATCH 04/20] A few fixes after renaming some functions. --- openlp/plugins/bibles/lib/csv.py | 5 +- openlp/plugins/bibles/lib/db.py | 11 +++-- openlp/plugins/bibles/lib/http.py | 3 +- openlp/plugins/bibles/lib/manager.py | 69 ++++++++++++++------------- openlp/plugins/bibles/lib/opensong.py | 25 ++++++---- openlp/plugins/bibles/lib/osis.py | 5 +- 6 files changed, 68 insertions(+), 50 deletions(-) diff --git a/openlp/plugins/bibles/lib/csv.py b/openlp/plugins/bibles/lib/csv.py index ac53f46cc..cd3b7efeb 100644 --- a/openlp/plugins/bibles/lib/csv.py +++ b/openlp/plugins/bibles/lib/csv.py @@ -106,7 +106,7 @@ class CSVBible(BibleDB): self.wizard.incrementProgressBar( u'Importing %s %s' % book.name) self.commit() - self.add_verse(book.id, p[1], p[2], p3) + self.create_verse(book.id, p[1], p[2], p3) Receiver.send_message(u'process_events') self.commit() except: @@ -119,4 +119,5 @@ class CSVBible(BibleDB): self.wizard.incrementProgressBar(u'Import canceled!') return False else: - return success \ No newline at end of file + return success + diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index cf272d6e9..6de5217bb 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -25,6 +25,7 @@ import os import logging +import chardet from sqlalchemy import or_ from PyQt4 import QtCore @@ -84,13 +85,14 @@ class BibleDB(): self.metadata, self.session = init_models(db_url) self.metadata.create_all(checkfirst=True) - def register(self): + def register(self, wizard): """ This method basically just initialialises the database. It is called from the Bible Manager when a Bible is imported. Descendant classes may want to override this method to supply their own custom initialisation as well. """ + self.wizard = wizard self.create_tables() return self.name @@ -100,7 +102,7 @@ class BibleDB(): def create_tables(self): log.debug(u'createTables') - self.save_meta(u'dbversion', u'2') + self.create_meta(u'dbversion', u'2') self.create_testament(u'Old Testament') self.create_testament(u'New Testament') self.create_testament(u'Apocrypha') @@ -111,7 +113,7 @@ class BibleDB(): self.commit() def create_book(self, name, abbrev, testament=1): - log.debug(u'create_book %s,%s', bookname, bookabbrev) + log.debug(u'create_book %s,%s', name, abbrev) book = Book.populate(name=name, abbreviation=abbrev, testament_id=testament) self.session.add(book) @@ -132,6 +134,9 @@ class BibleDB(): self.commit() def create_verse(self, book_id, chapter, verse, text): + if not isinstance(text, unicode): + details = chardet.detect(text) + text = unicode(text, details[u'encoding']) verse = Verse.populate( book_id=book_id, chapter=chapter, diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 7f1c835f8..5c3ac53b0 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -232,4 +232,5 @@ class HTTPBible(BibleDB): ev = BGExtract(self.proxyurl) return ev.get_bible_chapter(self.bibleid, book, chapter) except: - log.exception("Failed to get bible chapter") \ No newline at end of file + log.exception("Failed to get bible chapter") + diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 9a667d916..1a9d01d9d 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -61,13 +61,13 @@ class BibleFormat(object): Return the appropriate imeplementation class. """ if id == BibleFormat.OSIS: - return BibleOSISImpl + return OSISBible elif id == BibleFormat.CSV: - return BibleCSVImpl + return CSVBible elif id == BibleFormat.OpenSong: - return BibleOpenSongImpl + return OpenSongBible elif id == BibleFormat.WebDownload: - return BibleHTTPImpl + return HTTPBible else: return None @@ -161,10 +161,13 @@ class BibleManager(object): try: fbibles = open(filepath, u'r') for line in fbibles: - p = line.split(u',') - self.book_abbreviations[p[0]] = p[1].replace(u'\n', '') - self.book_testaments[p[0]] = p[2].replace(u'\n', '') - self.book_chapters.append({u'book':p[0], u'total':p[3].replace(u'\n', '')}) + parts = line.split(u',') + self.book_abbreviations[parts[0]] = parts[1].replace(u'\n', '') + self.book_testaments[parts[0]] = parts[2].replace(u'\n', '') + self.book_chapters.append({ + u'book': parts[0], + u'total': parts[3].replace(u'\n', '') + }) except: log.exception(u'Failed to load bible') finally: @@ -192,10 +195,10 @@ class BibleManager(object): Keyword arguments to send to the actualy importer class. """ class_ = BibleFormat.get_class(type) - kwargs[u'path'] = self.path - kwargs[u'config'] = self.config + kwargs['path'] = self.path + kwargs['config'] = self.config importer = class_(**kwargs) - name = importer.register() + name = importer.register(self.import_wizard) self.db_cache[name] = importer return importer.do_import() @@ -231,7 +234,7 @@ class BibleManager(object): nbible = BibleDBImpl(self.bible_path, biblename, self.config) # Create Database nbible.create_tables() - self.bible_db_cache[biblename] = nbible + self.db_cache[biblename] = nbible nhttp = BibleHTTPImpl() nhttp.set_bible_source(biblesource) self.bible_http_cache[biblename] = nhttp @@ -366,16 +369,16 @@ class BibleManager(object): log.debug(u'get_book_verse_count %s,%s,%s', bible, book, chapter) web, bible = self.is_bible_web(bible) if web: - count = self.bible_db_cache[bible].get_max_bible_book_verses( + count = self.db_cache[bible].get_max_bible_book_verses( book, chapter) if count == 0: # Make sure the first chapter has been downloaded self.get_verse_text(bible, book, chapter, chapter, 1, 1) - count = self.bible_db_cache[bible].get_max_bible_book_verses( + count = self.db_cache[bible].get_max_bible_book_verses( book, chapter) return count else: - return self.bible_db_cache[bible].get_max_bible_book_verses( + return self.db_cache[bible].get_max_bible_book_verses( book, chapter) def get_verses(self, bible, versetext): @@ -386,7 +389,7 @@ class BibleManager(object): log.debug(u'get_verses_from_text %s,%s', bible, versetext) reflist = parse_reference(versetext) web, bible = self.is_bible_web(bible) - return self.bible_db_cache[bible].get_verses(reflist) + return self.db_cache[bible].get_verses(reflist) def save_meta_data(self, bible, version, copyright, permissions): """ @@ -394,9 +397,9 @@ class BibleManager(object): """ log.debug(u'save_meta data %s,%s, %s,%s', bible, version, copyright, permissions) - self.bible_db_cache[bible].save_meta(u'Version', version) - self.bible_db_cache[bible].save_meta(u'Copyright', copyright) - self.bible_db_cache[bible].save_meta(u'Permissions', permissions) + self.db_cache[bible].create_meta(u'Version', version) + self.db_cache[bible].create_meta(u'Copyright', copyright) + self.db_cache[bible].create_meta(u'Permissions', permissions) def get_meta_data(self, bible, key): """ @@ -404,7 +407,7 @@ class BibleManager(object): """ log.debug(u'get_meta %s,%s', bible, key) web, bible = self.is_bible_web(bible) - return self.bible_db_cache[bible].get_meta(key) + return self.db_cache[bible].get_meta(key) def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse=0): @@ -425,8 +428,8 @@ class BibleManager(object): # check to see if book/chapter exists fow HTTP bibles and load cache # if necessary web, bible = self.is_bible_web(bible) - if self.bible_http_cache[bible]: - book = self.bible_db_cache[bible].get_bible_book(bookname) + if self.http_cache[bible]: + book = self.db_cache[bible].get_bible_book(bookname) if book is None: log.debug(u'get_verse_text : new book') for chapter in range(schapter, echapter + 1): @@ -434,7 +437,7 @@ class BibleManager(object): unicode(self.media.trUtf8('Downloading %s: %s')) % (bookname, chapter)) search_results = \ - self.bible_http_cache[bible].get_bible_chapter( + self.http_cache[bible].get_bible_chapter( bible, bookname, chapter) if search_results.has_verselist() : ## We have found a book of the bible lets check to see @@ -443,33 +446,33 @@ class BibleManager(object): ## to request ac and get Acts back. bookname = search_results.get_book() # check to see if book/chapter exists - book = self.bible_db_cache[bible].get_bible_book( + book = self.db_cache[bible].get_bible_book( bookname) if book is None: ## Then create book, chapter and text - book = self.bible_db_cache[bible].create_book( + book = self.db_cache[bible].create_book( bookname, self.book_abbreviations[bookname], self.book_testaments[bookname]) log.debug(u'New http book %s, %s, %s', book, book.id, book.name) - self.bible_db_cache[bible].create_chapter( + self.db_cache[bible].create_chapter( book.id, search_results.get_chapter(), search_results.get_verselist()) else: ## Book exists check chapter and texts only. - v = self.bible_db_cache[bible].get_bible_chapter( + v = self.db_cache[bible].get_bible_chapter( book.id, chapter) if v is None: self.media.setQuickMessage( unicode(self.media.trUtf8('%Downloading %s: %s'))\ % (bookname, chapter)) - self.bible_db_cache[bible].create_chapter( + self.db_cache[bible].create_chapter( book.id, chapter, search_results.get_verselist()) else: log.debug(u'get_verse_text : old book') for chapter in range(schapter, echapter + 1): - v = self.bible_db_cache[bible].get_bible_chapter( + v = self.db_cache[bible].get_bible_chapter( book.id, chapter) if v is None: try: @@ -477,17 +480,17 @@ class BibleManager(object): unicode(self.media.trUtf8('Downloading %s: %s')) % (bookname, chapter)) search_results = \ - self.bible_http_cache[bible].get_bible_chapter( + self.http_cache[bible].get_bible_chapter( bible, bookname, chapter) if search_results.has_verselist(): - self.bible_db_cache[bible].create_chapter( + self.db_cache[bible].create_chapter( book.id, search_results.get_chapter(), search_results.get_verselist()) except: log.exception(u'Problem getting scripture online') #Now get verses from database if schapter == echapter: - text = self.bible_db_cache[bible].get_bible_text(bookname, + text = self.db_cache[bible].get_bible_text(bookname, schapter, sverse, everse) else: for i in range (schapter, echapter + 1): @@ -501,7 +504,7 @@ class BibleManager(object): start = 1 end = self.get_book_verse_count(bible, bookname, i) - txt = self.bible_db_cache[bible].get_bible_text( + txt = self.db_cache[bible].get_bible_text( bookname, i, start, end) text.extend(txt) return text diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 93820be48..64eeeb0f9 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -49,11 +49,11 @@ class OpenSongBible(BibleDB): """ log.debug(__name__) BibleDB.__init__(self, **kwargs) - if u'filename' not in kwargs: + if 'filename' not in kwargs: raise KeyError(u'You have to supply a file name to import from.') - self.filename = kwargs[u'filename'] - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + self.filename = kwargs['filename'] + #QtCore.QObject.connect(Receiver.get_receiver(), + # QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): """ @@ -67,10 +67,12 @@ class OpenSongBible(BibleDB): Loads a Bible from file. """ log.debug(u'Starting OpenSong import from "%s"' % self.filename) + self.filename = unicode(self.filename, u'utf-8') + self.wizard.incrementProgressBar(u'Preparing for import...') detect_file = None try: detect_file = open(self.filename, u'r') - details = chardet.detect(detect_file.read(3000)) + details = chardet.detect(detect_file.read()) except: log.exception(u'Failed to detect OpenSong file encoding') return False @@ -94,11 +96,16 @@ class OpenSongBible(BibleDB): for verse in chapter.v: if self.stop_import: break - self.add_verse(db_book.id, chapter.attrib[u'n'], - verse.attrib[u'n'], verse.text) + self.create_verse( + db_book.id, + int(chapter.attrib[u'n']), + int(verse.attrib[u'n']), + verse.text + ) Receiver.send_message(u'process_events') - self.wizard.incrementProgressBar(u'Importing %s %s' % \ - (dbbook.name, str(chapter.attrib[u'n']))) + self.wizard.incrementProgressBar( + QtCore.QString('Importing %s %s' % \ + (db_book.name, chapter.attrib[u'n']))) self.commit() except: log.exception(u'Loading bible from OpenSong file failed') diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 4f18b27c5..a7e4ba374 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -160,7 +160,7 @@ class OSISBible(BibleDB): .replace(u'', u'').replace(u'', u'')\ .replace(u'', u'') verse_text = self.spaces_regex.sub(u' ', verse_text) - self.add_verse(db_book.id, chapter, verse, verse_text) + self.create_verse(db_book.id, chapter, verse, verse_text) Receiver.send_message(u'process_events') self.commit() self.wizard.incrementProgressBar(u'Finishing import...') @@ -174,4 +174,5 @@ class OSISBible(BibleDB): self.wizard.incrementProgressBar(u'Import canceled!') return False else: - return success \ No newline at end of file + return success + From 4a9a8149c425e9ac5d7fdc61d406a38019f6ee72 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 24 Jan 2010 09:08:14 +0200 Subject: [PATCH 05/20] Fixed up web Bibles. Renamed "csv.py" to "csvbible.py" to resolve a namespace conflict with the Python csv module. --- .../bibles/lib/{csv.py => csvbible.py} | 56 ++-- openlp/plugins/bibles/lib/db.py | 12 +- openlp/plugins/bibles/lib/http.py | 172 ++++++---- openlp/plugins/bibles/lib/manager.py | 306 +++++------------- openlp/plugins/bibles/lib/mediaitem.py | 198 ++++++------ 5 files changed, 328 insertions(+), 416 deletions(-) rename openlp/plugins/bibles/lib/{csv.py => csvbible.py} (76%) diff --git a/openlp/plugins/bibles/lib/csv.py b/openlp/plugins/bibles/lib/csvbible.py similarity index 76% rename from openlp/plugins/bibles/lib/csv.py rename to openlp/plugins/bibles/lib/csvbible.py index cd3b7efeb..f98ef0c86 100644 --- a/openlp/plugins/bibles/lib/csv.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -25,6 +25,7 @@ import logging import chardet +import csv from openlp.core.lib import Receiver from db import BibleDB @@ -42,8 +43,8 @@ class CSVBible(BibleDB): This class assumes the files contain all the information and a clean bible is being loaded. """ - log.info(__name__) BibleDB.__init__(self, **kwargs) + log.info(self.__class__.__name__) if u'booksfile' not in kwargs: raise KeyError(u'You have to supply a file to import books from.') self.booksfile = kwargs[u'booksfile'] @@ -63,58 +64,55 @@ class CSVBible(BibleDB): def do_import(self): #Populate the Tables success = True - fbooks = None + books_file = None try: - fbooks = open(self.booksfile, 'r') - for line in fbooks: + books_file = open(self.booksfile, 'r') + dialect = csv.Sniffer().sniff(books_file.read(1024)) + books_file.seek(0) + books_reader = csv.reader(books_file, dialect) + for line in books_reader: # cancel pressed if self.stop_import: break - details = chardet.detect(line) - line = unicode(line, details['encoding']) - p = line.split(u',') - p1 = p[1].replace(u'"', u'') - p2 = p[2].replace(u'"', u'') - p3 = p[3].replace(u'"', u'') - self.create_book(p2, p3, int(p1)) + details = chardet.detect(line[1]) + self.create_book(unicode(line[1], details['encoding']), + line[2], int(line[0])) Receiver.send_message(u'process_events') except: log.exception(u'Loading books from file failed') success = False finally: - if fbooks: - fbooks.close() + if books_file: + books_file.close() if not success: return False - fverse = None + verse_file = None try: - fverse = open(versesfile, 'r') book_ptr = None - for line in fverse: + verse_file = open(versesfile, 'r') + dialect = csv.Sniffer().sniff(verse_file.read(1024)) + verse_file.seek(0) + verse_reader = csv.reader(verse_file, dialect) + for line in verse_reader: if self.stop_import: # cancel pressed break - details = chardet.detect(line) - line = unicode(line, details['encoding']) - # split into 3 units and leave the rest as a single field - p = line.split(u',', 3) - p0 = p[0].replace(u'"', u'') - p3 = p[3].replace(u'"', u'') - if book_ptr is not p0: - book = self.get_book(p0) + details = chardet.detect(line[3]) + if book_ptr != line[0]: + book = self.get_book(line[0]) book_ptr = book.name - # increament the progress bar self.wizard.incrementProgressBar( - u'Importing %s %s' % book.name) + u'Importing %s %s' % (book.name, line[1])) self.commit() - self.create_verse(book.id, p[1], p[2], p3) + self.create_verse(book.id, line[1], line[2], + unicode(line[3], details['encoding'])) Receiver.send_message(u'process_events') self.commit() except: log.exception(u'Loading verses from file failed') success = False finally: - if fverse: - fverse.close() + if verse_file: + verse_file.close() if self.stop_import: self.wizard.incrementProgressBar(u'Import canceled!') return False diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 6de5217bb..2131737fd 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -34,7 +34,7 @@ from openlp.plugins.bibles.lib.models import * log = logging.getLogger(__name__) -class BibleDB(): +class BibleDB(QtCore.QObject): """ This class represents a database-bound Bible. It is used as a base class for all the custom importers, so that the can implement their own import @@ -121,12 +121,12 @@ class BibleDB(): return book def create_chapter(self, book_id, chapter, textlist): - log.debug(u'create_chapter %s,%s', bookid, chap) + log.debug(u'create_chapter %s,%s', book_id, chapter) #text list has book and chapter as first two elements of the array for verse_number, verse_text in textlist.iteritems(): verse = Verse.populate( book_id = book_id, - chapter = chap, + chapter = chapter, verse = verse_number, text = verse_text ) @@ -158,7 +158,7 @@ class BibleDB(): def get_book(self, book): log.debug(u'%s: %s', __name__, book) db_book = self.session.query(Book)\ - .filter_by(Book.name.like(book + u'%'))\ + .filter(Book.name.like(book + u'%'))\ .first() if db_book is None: db_book = self.session.query(Book)\ @@ -198,10 +198,10 @@ class BibleDB(): if end_verse == -1: end_verse = self.get_chapter_count(book) if db_book: - book = book.name + book = db_book.name log.debug(u'Book name corrected to "%s"' % book) verses = self.session.query(Verse)\ - .filter_by(book_id=book.id)\ + .filter_by(book_id=db_book.id)\ .filter_by(chapter=chapter)\ .filter(Verse.verse >= start_verse)\ .filter(Verse.verse <= end_verse)\ diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 5c3ac53b0..ff3045107 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -24,9 +24,13 @@ ############################################################################### import logging +import urllib2 + +from BeautifulSoup import BeautifulSoup from common import BibleCommon, SearchResults from db import BibleDB +from openlp.plugins.bibles.lib.models import Book class BGExtract(BibleCommon): global log @@ -51,7 +55,7 @@ class BGExtract(BibleCommon): Chapter number """ log.debug(u'get_bible_chapter %s, %s, %s', version, bookname, chapter) - urlstring = u'http://www.biblegateway.com/passage/?search=%s+%d' \ + urlstring = u'http://www.biblegateway.com/passage/?search=%s+%s' \ u'&version=%s' % (bookname, chapter, version) log.debug(u'BibleGateway url = %s' % urlstring) xml_string = self._get_web_text(urlstring, self.proxyurl) @@ -94,17 +98,14 @@ class BGExtract(BibleCommon): return SearchResults(bookname, chapter, bible) class CWExtract(BibleCommon): - global log - log = logging.getLogger(u'BibleHTTPMgr(CWExtract)') - log.info(u'CWExtract loaded') + log.info(u'%s loaded', __name__) def __init__(self, proxyurl=None): log.debug(u'init %s', proxyurl) self.proxyurl = proxyurl - def get_bible_chapter(self, version, bookname, chapter) : - log.debug(u'getBibleChapter %s,%s,%s', - version,bookname, chapter) + def get_bible_chapter(self, version, bookname, chapter): + log.debug(u'%s %s, %s, %s', __name__, version, bookname, chapter) """ Access and decode bibles via the Crosswalk website @@ -120,60 +121,24 @@ class CWExtract(BibleCommon): log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter) bookname = bookname.replace(u' ', u'') - urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word=%s+%d&version=%s'\ - % (bookname, chapter, version) - xml_string = self._get_web_text(urlstring, self.proxyurl) - ## Strip Book Title from Heading to return it to system - ## - i = xml_string.find(u'') - j = xml_string.find(u'-', i) - book_title = xml_string[i + 7:j] - book_title = book_title.rstrip() - log.debug(u'Book Title %s', book_title) - i = book_title.rfind(u' ') - book_chapter = book_title[i+1:len(book_title)].rstrip() - book_title = book_title[:i].rstrip() - log.debug(u'Book Title %s', book_title) - log.debug(u'Book Chapter %s', book_chapter) - # Strip Verse Data from Page and build an array + page = urllib2.urlopen(u'http://www.biblestudytools.com/%s/%s/%s.html' % \ + (version, bookname.lower(), chapter)) + soup = BeautifulSoup(page) + htmlverses = soup.findAll(u'span', u'versetext') + verses = {} + for verse in htmlverses: + versenumber = int(verse.contents[0].contents[0]) + versetext = u'' + for part in verse.contents: + if str(part)[0] != u'<': + versetext = versetext + part + versetext = versetext.strip(u'\n\r\t ') + verses[versenumber] = versetext + return SearchResults(bookname, chapter, verses) - i = xml_string.find(u'NavCurrentChapter') - xml_string = xml_string[i:len(xml_string)] - i = xml_string.find(u'<TABLE') - xml_string = xml_string[i:len(xml_string)] - i = xml_string.find(u'<B>') - #remove the <B> at the front - xml_string = xml_string[i + 3 :len(xml_string)] - # Remove the heading for the book - i = xml_string.find(u'<B>') - #remove the <B> at the front - xml_string = xml_string[i + 3 :len(xml_string)] - versePos = xml_string.find(u'<BLOCKQUOTE>') - bible = {} - while versePos > 0: - verseText = u'' - versePos = xml_string.find(u'<B><I>', versePos) + 6 - i = xml_string.find(u'</I></B>', versePos) - # Got the Chapter - verse = xml_string[versePos:i] - # move the starting position to begining of the text - versePos = i + 8 - # find the start of the next verse - i = xml_string.find(u'<B><I>', versePos) - if i == -1: - i = xml_string.find(u'</BLOCKQUOTE>',versePos) - verseText = xml_string[versePos: i] - versePos = 0 - else: - verseText = xml_string[versePos: i] - versePos = i - bible[verse] = self._clean_text(verseText) - return SearchResults(book_title, book_chapter, bible) class HTTPBible(BibleDB): - global log - log = logging.getLogger(u'BibleHTTPMgr') - log.info(u'BibleHTTP manager loaded') + log.info(u'%s loaded', __name__) def __init__(self, **kwargs): """ @@ -185,6 +150,7 @@ class HTTPBible(BibleDB): Init confirms the bible exists and stores the database path. """ + BibleDB.__init__(self, **kwargs) if u'download_source' not in kwargs: raise KeyError(u'Missing keyword argument "download_source"') if u'download_name' not in kwargs: @@ -204,8 +170,9 @@ class HTTPBible(BibleDB): else: self.proxy_password = None - def register(self): - name = BibleDB.register(self) + def do_import(self): + self.wizard.ImportProgressBar.setMaximum(2) + self.wizard.incrementProgressBar('Registering bible...') self.create_meta(u'download source', self.download_source) self.create_meta(u'download name', self.download_name) if self.proxy_server: @@ -216,21 +183,88 @@ class HTTPBible(BibleDB): if self.proxy_password: # store the proxy password self.create_meta(u'proxy password', self.proxy_password) - return name + self.wizard.incrementProgressBar('Registered.') + return True - def get_bible_chapter(self, version, book, chapter): + def get_verses(self, reference_list): + """ + A reimplementation of the ``BibleDB.get_verses`` method, this one is + specifically for web Bibles. It first checks to see if the particular + chapter exists in the DB, and if not it pulls it from the web. If the + chapter DOES exist, it simply pulls the verses from the DB using the + ancestor method. + + ``reference_list`` + This is the list of references the media manager item wants. It is + a list of tuples, with the following format:: + + (book, chapter, start_verse, end_verse) + + Therefore, when you are looking for multiple items, simply break + them up into references like this, bundle them into a list. This + function then runs through the list, and returns an amalgamated + list of ``Verse`` objects. For example:: + + [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] + """ + for reference in reference_list: + log.debug('Reference: %s', reference) + book = reference[0] + db_book = self.get_book(book) + if not db_book: + book_details = self.lookup_book(book) + db_book = self.create_book(book_details[u'name'], + book_details[u'abbr'], book_details[u'test']) + book = db_book.name + if self.get_verse_count(book, reference[1]) == 0: + search_results = self.get_chapter(self.name, book, reference[1]) + if search_results and search_results.has_verselist(): + ## We have found a book of the bible lets check to see + ## if it was there. By reusing the returned book name + ## we get a correct book. For example it is possible + ## to request ac and get Acts back. + bookname = search_results.get_book() + # check to see if book/chapter exists + db_book = self.get_book(bookname) + self.create_chapter(db_book.id, search_results.get_chapter(), + search_results.get_verselist()) + return BibleDB.get_verses(self, reference_list) + + def get_chapter(self, version, book, chapter): """ Receive the request and call the relevant handler methods """ - log.debug(u'get_bible_chapter %s,%s,%s', - version, book, chapter) - log.debug(u'biblesource = %s', self.biblesource) + log.debug(u'get_chapter %s, %s, %s', version, book, chapter) + log.debug(u'source = %s', self.download_source) try: - if self.biblesource.lower() == u'crosswalk': - ev = CWExtract(self.proxyurl) + if self.download_source.lower() == u'crosswalk': + ev = CWExtract(self.proxy_server) else: - ev = BGExtract(self.proxyurl) - return ev.get_bible_chapter(self.bibleid, book, chapter) + ev = BGExtract(self.proxy_server) + return ev.get_bible_chapter(self.download_name, book, chapter) except: log.exception("Failed to get bible chapter") + return None + + def get_books(self): + return [Book.populate(name=book[u'name']) for book in self.books] + + def get_chapter_count(self, book): + return self.books[book][u'chap'] + + def set_proxy_server(self, server): + self.proxy_server = server + + def set_books(self, books): + self.books = books + + def lookup_book(self, book): + log.debug('Looking up "%s" in %s', (book, self.books)) + if book in self.books: + return self.books[book] + else: + for details in self.books: + if details[u'abbr'] == book: + return details + return None diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 1a9d01d9d..f6e7fc4ea 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -25,11 +25,12 @@ import logging import os +import csv from common import parse_reference from opensong import OpenSongBible from osis import OSISBible -from csv import CSVBible +from csvbible import CSVBible from db import BibleDB from http import HTTPBible @@ -103,77 +104,66 @@ class BibleManager(object): self.config = config log.debug(u'Bible Initialising') self.web = u'Web' - # dict of bible database objects self.db_cache = None - # dict of bible http readers self.http_cache = None + self.http_books = {} self.path = self.config.get_data_path() - #get proxy name for screen self.proxy_name = self.config.get_config(u'proxy name') self.suffix = u'sqlite' self.import_wizard = None self.reload_bibles() self.media = None + def load_http_books(self): + filepath = os.path.split(os.path.abspath(__file__))[0] + filepath = os.path.abspath(os.path.join( + filepath, u'..', u'resources', u'httpbooks.csv')) + books_file = None + try: + self.http_books = {} + books_file = open(filepath, u'r') + dialect = csv.Sniffer().sniff(books_file.read(1024)) + books_file.seek(0) + books_reader = csv.reader(books_file, dialect) + for line in books_reader: + self.http_books[line[0]] = { + u'name': line[0], + u'abbr': line[1], + u'test': line[2], + u'chap': line[3] + } + except: + log.exception(u'Failed to load http books.') + finally: + if books_file: + books_file.close() + def reload_bibles(self): log.debug(u'Reload bibles') files = self.config.get_files(self.suffix) log.debug(u'Bible Files %s', files) self.db_cache = {} self.http_cache = {} - # books of the bible with testaments - self.book_testaments = {} - # books of the bible with chapter count - self.book_chapters = [] - # books of the bible with abbreviation - self.book_abbreviations = {} + self.load_http_books() self.web_bibles_present = False for filename in files: name, extension = os.path.splitext(filename) self.db_cache[name] = BibleDB(path=self.path, name=name, config=self.config) # look to see if lazy load bible exists and get create getter. - source = self.db_cache[name].get_meta(u'web') + source = self.db_cache[name].get_meta(u'download source') if source: self.web_bibles_present = True - web_bible = HTTPBible() - # tell The Server where to get the verses from. - web_bible.set_source(source.value) - self.http_cache[name] = web_bible - # look to see if lazy load bible exists and get create getter. + download_name = self.db_cache[name].get_meta(u'download name').value + web_bible = HTTPBible(path=self.path, name=name, + config=self.config, download_source=source.value, + download_name=download_name) meta_proxy = self.db_cache[name].get_meta(u'proxy url') - proxy_url = None if meta_proxy: - proxy_url = meta_proxy.value - # tell The Server where to get the verses from. - web_bible.set_proxy_url(proxy_url) - # look to see if lazy load bible exists and get create getter. - bible_id = self.db_cache[name].get_meta(u'bible id').value - # tell The Server where to get the verses from. - web_bible.set_bible_id(bible_id) - #else: - # # makes the Full / partial code easier. - # self.http_cache[name] = None - if self.web_bibles_present: - filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join( - filepath, u'..', u'resources', u'httpbooks.csv')) - fbibles = None - try: - fbibles = open(filepath, u'r') - for line in fbibles: - parts = line.split(u',') - self.book_abbreviations[parts[0]] = parts[1].replace(u'\n', '') - self.book_testaments[parts[0]] = parts[2].replace(u'\n', '') - self.book_chapters.append({ - u'book': parts[0], - u'total': parts[3].replace(u'\n', '') - }) - except: - log.exception(u'Failed to load bible') - finally: - if fbibles: - fbibles.close() - log.debug(u'Bible Initialised') + web_bible.set_proxy_server(meta_proxy.value) + web_bible.set_books(self.http_books) + del self.db_cache[name] + self.db_cache[name] = web_bible + log.debug(u'Bibles reloaded') def set_process_dialog(self, wizard): """ @@ -202,130 +192,6 @@ class BibleManager(object): self.db_cache[name] = importer return importer.do_import() - def register_http_bible(self, biblename, biblesource, bibleid, - proxyurl=None, proxyid=None, proxypass=None): - """ - Return a list of bibles from a given URL. The selected Bible - can then be registered and LazyLoaded into a database. - - ``biblename`` - The name of the bible to register. - - ``biblesource`` - Where this Bible stores it's verses. - - ``bibleid`` - The identifier for a Bible. - - ``proxyurl`` - Defaults to *None*. An optional URL to a proxy server. - - ``proxyid`` - Defaults to *None*. A username for logging into the proxy - server. - - ``proxypass`` - Defaults to *None*. The password to accompany the username. - """ - log.debug(u'register_HTTP_bible %s, %s, %s, %s, %s, %s', - biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) - if self._is_new_bible(biblename): - # Create new Bible - nbible = BibleDBImpl(self.bible_path, biblename, self.config) - # Create Database - nbible.create_tables() - self.db_cache[biblename] = nbible - nhttp = BibleHTTPImpl() - nhttp.set_bible_source(biblesource) - self.bible_http_cache[biblename] = nhttp - # register a lazy loading interest - nbible.create_meta(u'WEB', biblesource) - # store the web id of the bible - nbible.create_meta(u'bibleid', bibleid) - if proxyurl: - # store the proxy URL - nbible.save_meta(u'proxy', proxyurl) - nhttp.set_proxy(proxyurl) - if proxyid: - # store the proxy userid - nbible.save_meta(u'proxyid', proxyid) - if proxypass: - # store the proxy password - nbible.save_meta(u'proxypass', proxypass) - return True - else: - log.debug(u'register_http_file_bible %s not created already exists', - biblename) - return False - - def register_csv_file_bible(self, biblename, booksfile, versefile): - """ - Method to load a bible from a set of files into a database. - If the database exists it is deleted and the database is reloaded - from scratch. - """ - log.debug(u'register_CSV_file_bible %s,%s,%s', - biblename, booksfile, versefile) - if self._is_new_bible(biblename): - # Create new Bible - nbible = BibleDBImpl(self.bible_path, biblename, self.config) - # Create database - nbible.create_tables() - # Cache the database for use later - self.bible_db_cache[biblename] = nbible - # Create the loader and pass in the database - bcsv = BibleCSVImpl(nbible) - return bcsv.load_data(booksfile, versefile, self.dialogobject) - else: - log.debug(u'register_csv_file_bible %s not created already exists', - biblename) - return False - - def register_osis_file_bible(self, biblename, osisfile): - """ - Method to load a bible from a osis xml file extracted from Sword bible - viewer. If the database exists it is deleted and the database is - reloaded from scratch. - """ - log.debug(u'register_OSIS_file_bible %s, %s', biblename, osisfile) - if self._is_new_bible(biblename): - # Create new Bible - nbible = BibleDBImpl(self.bible_path, biblename, self.config) - # Create Database - nbible.create_tables() - # Cache the database for use later - self.bible_db_cache[biblename] = nbible - # Create the loader and pass in the database - bosis = BibleOSISImpl(self.bible_path, nbible) - return bosis.load_data(osisfile, self.dialogobject) - else: - log.debug( - u'register_OSIS_file_bible %s, %s not created already exists', - biblename, osisfile) - return False - - def register_opensong_bible(self, biblename, opensongfile): - """ - Method to load a bible from an OpenSong xml file. If the database - exists it is deleted and the database is reloaded from scratch. - """ - log.debug(u'register_opensong_file_bible %s, %s', biblename, opensongfile) - if self._is_new_bible(biblename): - # Create new Bible - nbible = BibleDBImpl(self.bible_path, biblename, self.config) - # Create Database - nbible.create_tables() - # Cache the database for use later - self.bible_db_cache[biblename] = nbible - # Create the loader and pass in the database - bcsv = BibleOpenSongImpl(self.bible_path, nbible) - bcsv.load_data(opensongfile, self.dialogobject) - return True - else: - log.debug(u'register_opensong_file_bible %s, %s not created ' - u'already exists', biblename, opensongfile) - return False - def get_bibles(self, mode=BibleMode.Full): """ Returns a list of Books of the bible. When ``mode`` is set to @@ -336,7 +202,7 @@ class BibleManager(object): log.debug(u'get_bibles') bible_list = [] for bible_name, bible_object in self.db_cache.iteritems(): - if bible_name in self.http_cache and self.http_cache[bible_name]: + if getattr(bible_object, 'download_source', None): bible_name = u'%s (%s)' % (bible_name, self.web) bible_list.append(bible_name) return bible_list @@ -347,12 +213,12 @@ class BibleManager(object): return True, bible[:pos_end] return False, bible - def get_bible_books(self): + def get_bible_books(self, bible): """ Returns a list of the books of the bible """ log.debug(u'get_bible_books') - return self.book_chapters + return [{'name': book.name, 'total': self.db_cache[bible].get_chapter_count(book.name)} for book in self.db_cache[bible].get_books()] def get_book_chapter_count(self, book): """ @@ -369,17 +235,14 @@ class BibleManager(object): log.debug(u'get_book_verse_count %s,%s,%s', bible, book, chapter) web, bible = self.is_bible_web(bible) if web: - count = self.db_cache[bible].get_max_bible_book_verses( - book, chapter) + count = self.db_cache[bible].get_verse_count(book, chapter) if count == 0: # Make sure the first chapter has been downloaded self.get_verse_text(bible, book, chapter, chapter, 1, 1) - count = self.db_cache[bible].get_max_bible_book_verses( - book, chapter) + count = self.db_cache[bible].get_verse_count(book, chapter) return count else: - return self.db_cache[bible].get_max_bible_book_verses( - book, chapter) + return self.db_cache[bible].get_verse_count(book, chapter) def get_verses(self, bible, versetext): """ @@ -388,7 +251,14 @@ class BibleManager(object): """ log.debug(u'get_verses_from_text %s,%s', bible, versetext) reflist = parse_reference(versetext) - web, bible = self.is_bible_web(bible) + web_index = bible.find('(%s)' % self.web) + if web_index >= 0: + bible = bible[:web_index - 1] + log.debug('Updated bible name: %s', bible) + #web, bible = self.is_bible_web(bible) + #if web: + # return self.http_cache[bible].get_verses(reflist) + #else: return self.db_cache[bible].get_verses(reflist) def save_meta_data(self, bible, version, copyright, permissions): @@ -409,8 +279,7 @@ class BibleManager(object): web, bible = self.is_bible_web(bible) return self.db_cache[bible].get_meta(key) - def get_verse_text(self, bible, bookname, schapter, echapter, sverse, - everse=0): + def get_verse_text(self, bible, book, schapter, echapter, sverse, everse=0): """ Returns a list of verses for a given Book, Chapter and ranges of verses. If the end verse(everse) is less then the start verse(sverse) @@ -424,89 +293,88 @@ class BibleManager(object): text = [] self.media.setQuickMessage(u'') log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', - bible, bookname, schapter, echapter, sverse, everse) + bible, book, schapter, echapter, sverse, everse) # check to see if book/chapter exists fow HTTP bibles and load cache # if necessary web, bible = self.is_bible_web(bible) + web_bible = False + log.debug('Web Bibles: %s', self.http_cache) if self.http_cache[bible]: - book = self.db_cache[bible].get_bible_book(bookname) - if book is None: - log.debug(u'get_verse_text : new book') + web_bible = True + db_book = self.db_cache[bible].get_book(book) + if db_book is None: + log.debug(u'get_verse_text: new book') for chapter in range(schapter, echapter + 1): self.media.setQuickMessage( unicode(self.media.trUtf8('Downloading %s: %s')) % - (bookname, chapter)) + (book, chapter)) search_results = \ - self.http_cache[bible].get_bible_chapter( - bible, bookname, chapter) - if search_results.has_verselist() : + self.http_cache[bible].get_chapter(bible, book, chapter) + if search_results and search_results.has_verselist(): ## We have found a book of the bible lets check to see ## if it was there. By reusing the returned book name ## we get a correct book. For example it is possible ## to request ac and get Acts back. bookname = search_results.get_book() # check to see if book/chapter exists - book = self.db_cache[bible].get_bible_book( - bookname) - if book is None: + db_book = self.db_cache[bible].get_book(bookname) + if db_book is None: ## Then create book, chapter and text - book = self.db_cache[bible].create_book( + db_book = self.db_cache[bible].create_book( bookname, self.book_abbreviations[bookname], self.book_testaments[bookname]) log.debug(u'New http book %s, %s, %s', - book, book.id, book.name) + db_book, db_book.id, db_book.name) self.db_cache[bible].create_chapter( - book.id, search_results.get_chapter(), + db_book.id, search_results.get_chapter(), search_results.get_verselist()) else: ## Book exists check chapter and texts only. - v = self.db_cache[bible].get_bible_chapter( - book.id, chapter) + v = self.db_cache[bible].get_chapter( + db_book.id, chapter) if v is None: self.media.setQuickMessage( unicode(self.media.trUtf8('%Downloading %s: %s'))\ - % (bookname, chapter)) + % (book, chapter)) self.db_cache[bible].create_chapter( - book.id, chapter, + db_book.id, chapter, search_results.get_verselist()) else: log.debug(u'get_verse_text : old book') for chapter in range(schapter, echapter + 1): - v = self.db_cache[bible].get_bible_chapter( - book.id, chapter) + v = self.db_cache[bible].get_chapter(db_book.id, chapter) if v is None: try: self.media.setQuickMessage(\ unicode(self.media.trUtf8('Downloading %s: %s')) - % (bookname, chapter)) + % (book, chapter)) search_results = \ - self.http_cache[bible].get_bible_chapter( - bible, bookname, chapter) + self.http_cache[bible].get_chapter( + bible, bookn, chapter) if search_results.has_verselist(): self.db_cache[bible].create_chapter( - book.id, search_results.get_chapter(), + db_book.id, search_results.get_chapter(), search_results.get_verselist()) except: log.exception(u'Problem getting scripture online') #Now get verses from database if schapter == echapter: - text = self.db_cache[bible].get_bible_text(bookname, - schapter, sverse, everse) + text = self.db_cache[bible].get_verses( + [(book, schapter, sverse, everse)]) else: - for i in range (schapter, echapter + 1): - if i == schapter: + verse_list = [] + for chapter in range(schapter, echapter + 1): + if chapter == schapter: start = sverse - end = self.get_book_verse_count(bible, bookname, i) - elif i == echapter: + end = self.get_verse_count(bible, book, chapter) + elif chapter == echapter: start = 1 end = everse else: start = 1 - end = self.get_book_verse_count(bible, bookname, i) - - txt = self.db_cache[bible].get_bible_text( - bookname, i, start, end) - text.extend(txt) + end = self.get_verse_count(bible, book, chapter) + verse_list.append((bible, chapter, start, end)) + text = self.db_cache[bible].get_verses(verse_list) return text def exists(self, name): diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 64a4e2462..cc2cb90e8 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -308,7 +308,7 @@ class BibleMediaItem(MediaManagerItem): self.QuickVersionComboBox.addItem(bible) self.QuickSecondBibleComboBox.addItem(bible) # Without HTTP - bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial) + #bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial) first = True # load bibles into the combo boxes for bible in bibles: @@ -362,8 +362,9 @@ class BibleMediaItem(MediaManagerItem): chapter_to = int(self.AdvancedToChapter.currentText()) verse_from = int(self.AdvancedFromVerse.currentText()) verse_to = int(self.AdvancedToVerse.currentText()) - self.search_results = self.parent.biblemanager.get_verse_text( - bible, book, chapter_from, chapter_to, verse_from, verse_to) + versetext = u'%s %s:%s-%s:%s' % (book, chapter_from, verse_from, \ + chapter_to, verse_to) + self.search_results = self.parent.manager.get_verses(bible, versetext) if self.ClearAdvancedSearchComboBox.currentIndex() == 0: self.ListView.clear() self.displayResults(bible) @@ -384,11 +385,12 @@ class BibleMediaItem(MediaManagerItem): text = unicode(self.QuickSearchEdit.displayText()) if self.ClearQuickSearchComboBox.currentIndex() == 0: self.ListView.clear() - if self.QuickSearchComboBox.currentIndex() == 1: - self.search_results = \ - self.parent.biblemanager.get_verses(bible, text) - else: - self.searchByReference(bible, text) + #if self.QuickSearchComboBox.currentIndex() == 1: + # self.search_results = \ + # self.parent.biblemanager.get_verses(bible, text) + #else: + # self.searchByReference(bible, text) + self.search_results = self.parent.biblemanager.get_verses(bible, text) if self.search_results: self.displayResults(bible) @@ -484,18 +486,18 @@ class BibleMediaItem(MediaManagerItem): def initialiseBible(self, bible): log.debug(u'initialiseBible %s', bible) - book_data = self.parent.biblemanager.get_bible_books() + book_data = self.parent.biblemanager.get_bible_books(bible) self.AdvancedBookComboBox.clear() first = True for book in book_data: row = self.AdvancedBookComboBox.count() - self.AdvancedBookComboBox.addItem(book[u'book']) + self.AdvancedBookComboBox.addItem(book[u'name']) self.AdvancedBookComboBox.setItemData( row, QtCore.QVariant(book[u'total'])) if first: first = False self.initialiseChapterVerse( - bible, book[u'book'], book[u'total']) + bible, book[u'name'], book[u'total']) def initialiseChapterVerse(self, bible, book, chapters): log.debug(u'initialiseChapterVerse %s, %s', bible, book) @@ -533,85 +535,95 @@ class BibleMediaItem(MediaManagerItem): def searchByReference(self, bible, search): log.debug(u'searchByReference %s, %s', bible, search) - book = u'' - start_chapter = u'' - end_chapter = u'' - start_verse = u'' - end_verse = u'' - search = search.replace(u' ', u' ').strip() - #original = search - message = None - # Remove book beware 0 index arrays - for i in range (len(search)-1, 0, - 1): - if search[i] == u' ': - book = search[:i] - # remove book from string - search = search[i:] - break - # allow V or v for verse instead of : - search = search.replace(u'v', ':') - search = search.replace(u'V', ':') - search = search.strip() - colon = search.find(u':') - if colon == -1: - # number : found - i = search.rfind(u' ') - if i == -1: - chapter = u'' - else: - chapter = search[i:len(search)] - hyphen = chapter.find(u'-') - if hyphen != -1: - start_chapter= chapter[:hyphen] - end_chapter= chapter[hyphen + 1:len(chapter)] - else: - start_chapter = chapter - else: - # more complex - sp = search.split(u'-') #find first - sp1 = sp[0].split(u':') - if len(sp1) == 1: - start_chapter = sp1[0] - start_verse = 1 - else: - start_chapter = sp1[0] - start_verse = sp1[1] - if len(sp)== 1: - end_chapter = start_chapter - end_verse = start_verse - else: - sp1 = sp[1].split(u':') - if len(sp1) == 1: - end_chapter = start_chapter - end_verse = sp1[0] - else: - end_chapter = sp1[0] - end_verse = sp1[1] - if end_chapter == u'': - end_chapter = start_chapter.rstrip() - if start_verse == u'': - if end_verse == u'': - start_verse = 1 - else: - start_verse = end_verse - if end_verse == u'': - end_verse = 99 - if start_chapter == u'': - message = self.trUtf8('No chapter found for search criteria') - log.debug(u'results = %s @ %s : %s @ %s : %s'% \ - (unicode(book), unicode(start_chapter), unicode(end_chapter), - unicode(start_verse), unicode(end_verse))) - if message is None: - self.search_results = None - self.search_results = self.parent.biblemanager.get_verse_text( - bible, book, int(start_chapter), int(end_chapter), - int(start_verse), int(end_verse)) - self.copyright = unicode(self.parent.biblemanager.get_meta_data( - bible, u'Copyright').value) - self.permissions = unicode(self.parent.biblemanager.get_meta_data( - bible, u'Permissions').value) - self.version = unicode(self.parent.biblemanager.get_meta_data( - bible, u'Version').value) - else: - QtGui.QMessageBox.information( - self, self.trUtf8('Information'), message) \ No newline at end of file + self.search_results = self.parent.biblemanager.get_verses(bible, search) + self.copyright = unicode(self.parent.biblemanager.get_meta_data( + bible, u'Copyright').value) + self.permissions = unicode(self.parent.biblemanager.get_meta_data( + bible, u'Permissions').value) + self.version = unicode(self.parent.biblemanager.get_meta_data( + bible, u'Version').value) + +# def searchByReference(self, bible, search): +# log.debug(u'searchByReference %s, %s', bible, search) +# book = u'' +# start_chapter = u'' +# end_chapter = u'' +# start_verse = u'' +# end_verse = u'' +# search = search.replace(u' ', u' ').strip() +# #original = search +# message = None +# # Remove book beware 0 index arrays +# for i in range (len(search)-1, 0, - 1): +# if search[i] == u' ': +# book = search[:i] +# # remove book from string +# search = search[i:] +# break +# # allow V or v for verse instead of : +# search = search.replace(u'v', ':') +# search = search.replace(u'V', ':') +# search = search.strip() +# colon = search.find(u':') +# if colon == -1: +# # number : found +# i = search.rfind(u' ') +# if i == -1: +# chapter = u'' +# else: +# chapter = search[i:len(search)] +# hyphen = chapter.find(u'-') +# if hyphen != -1: +# start_chapter= chapter[:hyphen] +# end_chapter= chapter[hyphen + 1:len(chapter)] +# else: +# start_chapter = chapter +# else: +# # more complex +# sp = search.split(u'-') #find first +# sp1 = sp[0].split(u':') +# if len(sp1) == 1: +# start_chapter = sp1[0] +# start_verse = 1 +# else: +# start_chapter = sp1[0] +# start_verse = sp1[1] +# if len(sp)== 1: +# end_chapter = start_chapter +# end_verse = start_verse +# else: +# sp1 = sp[1].split(u':') +# if len(sp1) == 1: +# end_chapter = start_chapter +# end_verse = sp1[0] +# else: +# end_chapter = sp1[0] +# end_verse = sp1[1] +# if end_chapter == u'': +# end_chapter = start_chapter.rstrip() +# if start_verse == u'': +# if end_verse == u'': +# start_verse = 1 +# else: +# start_verse = end_verse +# if end_verse == u'': +# end_verse = 99 +# if start_chapter == u'': +# message = self.trUtf8('No chapter found for search criteria') +# log.debug(u'results = %s @ %s : %s @ %s : %s'% \ +# (unicode(book), unicode(start_chapter), unicode(end_chapter), +# unicode(start_verse), unicode(end_verse))) +# if message is None: +# self.search_results = None +# self.search_results = self.parent.biblemanager.get_verse_text( +# bible, book, int(start_chapter), int(end_chapter), +# int(start_verse), int(end_verse)) +# self.copyright = unicode(self.parent.biblemanager.get_meta_data( +# bible, u'Copyright').value) +# self.permissions = unicode(self.parent.biblemanager.get_meta_data( +# bible, u'Permissions').value) +# self.version = unicode(self.parent.biblemanager.get_meta_data( +# bible, u'Version').value) +# else: +# QtGui.QMessageBox.information( +# self, self.trUtf8('Information'), message) From 0e29d0b4afd0863cb41e3bd4f7e53e2a2ae5f7ac Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Fri, 29 Jan 2010 22:20:30 +0200 Subject: [PATCH 06/20] Show a small progress bar rather than a "downloading" message. --- openlp/core/lib/baselistwithdnd.py | 4 +++- openlp/core/lib/eventreceiver.py | 3 ++- openlp/core/lib/mediamanageritem.py | 4 ++-- openlp/plugins/bibles/lib/http.py | 2 +- openlp/plugins/bibles/lib/manager.py | 4 ++-- openlp/plugins/bibles/lib/mediaitem.py | 30 ++++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/baselistwithdnd.py b/openlp/core/lib/baselistwithdnd.py index d2537e0e4..f7095550a 100644 --- a/openlp/core/lib/baselistwithdnd.py +++ b/openlp/core/lib/baselistwithdnd.py @@ -32,6 +32,7 @@ class BaseListWithDnD(QtGui.QListWidget): def __init__(self, parent=None): QtGui.QListWidget.__init__(self, parent) + self.parent = parent # this must be set by the class which is inheriting assert(self.PluginName) @@ -47,4 +48,5 @@ class BaseListWithDnD(QtGui.QListWidget): mimeData = QtCore.QMimeData() drag.setMimeData(mimeData) mimeData.setText(self.PluginName) - dropAction = drag.start(QtCore.Qt.CopyAction) \ No newline at end of file + dropAction = drag.start(QtCore.Qt.CopyAction) + diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index f3b43d2b7..41a18287e 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -161,4 +161,5 @@ class Receiver(): """ Get the global ``eventreceiver`` instance. """ - return Receiver.eventreceiver \ No newline at end of file + return Receiver.eventreceiver + diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 6f6f82818..5f490eed1 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -253,7 +253,7 @@ class MediaManagerItem(QtGui.QWidget): def addListViewToToolBar(self): #Add the List widget - self.ListView = self.ListViewWithDnD_class() + self.ListView = self.ListViewWithDnD_class(self) self.ListView.uniformItemSizes = True self.ListView.setGeometry(QtCore.QRect(10, 100, 256, 591)) self.ListView.setSpacing(1) @@ -400,4 +400,4 @@ class MediaManagerItem(QtGui.QWidget): if self.generateSlideData(service_item): return service_item else: - return None \ No newline at end of file + return None diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index ff3045107..bd8833105 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -247,7 +247,7 @@ class HTTPBible(BibleDB): return None def get_books(self): - return [Book.populate(name=book[u'name']) for book in self.books] + return [Book.populate(name=self.books[book]['name']) for book in self.books] def get_chapter_count(self, book): return self.books[book][u'chap'] diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index f6e7fc4ea..88982a8bf 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -202,8 +202,8 @@ class BibleManager(object): log.debug(u'get_bibles') bible_list = [] for bible_name, bible_object in self.db_cache.iteritems(): - if getattr(bible_object, 'download_source', None): - bible_name = u'%s (%s)' % (bible_name, self.web) + #if getattr(bible_object, 'download_source', None): + # bible_name = u'%s (%s)' % (bible_name, self.web) bible_list.append(bible_name) return bible_list diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index cc2cb90e8..49cede58a 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -42,6 +42,9 @@ class BibleListView(BaseListWithDnD): self.PluginName = u'Bibles' BaseListWithDnD.__init__(self, parent) + def resizeEvent(self, event): + self.parent.onListViewResize(event.size().width(), event.size().width()) + class BibleMediaItem(MediaManagerItem): """ @@ -242,6 +245,20 @@ class BibleMediaItem(MediaManagerItem): QtCore.SIGNAL(u'pressed()'), self.onQuickSearchButton) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated) + # Other stuff + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'')) + + def addListViewToToolBar(self): + MediaManagerItem.addListViewToToolBar(self) + # Progress Bar + self.SearchProgress = QtGui.QProgressBar(self) + self.SearchProgress.setFormat('%p%') + self.SearchProgress.setMaximum(3) + self.SearchProgress.setGeometry(self.ListView.geometry().left(), + self.ListView.geometry().top(), 81, 23) + self.SearchProgress.setVisible(False) + self.SearchProgress.setObjectName(u'SearchProgress') def configUpdated(self): if str_to_bool( @@ -319,6 +336,19 @@ class BibleMediaItem(MediaManagerItem): # use the first bible as the trigger self.initialiseBible(bible) + def onListViewResize(self, width, height): + self.SearchProgress.setGeometry(self.ListView.geometry().x(), + (self.ListView.geometry().y() + self.ListView.geometry().height())\ + - 23, 81, 23) + + def onSearchProgressShow(self, value): + self.SearchProgress.setVisible(True) + self.SearchProgress.setValue(value) + + def onSearchProgressHide(self, value): + self.SearchProgress.setVisible(True) + self.SearchProgress.setValue(value) + def onAdvancedVersionComboBox(self): self.initialiseBible( unicode(self.AdvancedVersionComboBox.currentText())) From 0cbb079aa3d73df174df61474b7406bd7142222d Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Fri, 29 Jan 2010 23:26:24 +0200 Subject: [PATCH 07/20] Added the little progress bar back in. --- openlp/plugins/bibles/lib/http.py | 10 ++++++++-- openlp/plugins/bibles/lib/mediaitem.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 5c9610bf6..a4caeb0f3 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -28,6 +28,7 @@ import urllib2 from BeautifulSoup import BeautifulSoup +from openlp.core.lib import Receiver from common import BibleCommon, SearchResults from db import BibleDB from openlp.plugins.bibles.lib.models import Book @@ -208,12 +209,17 @@ class HTTPBible(BibleDB): [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] """ Receiver.send_message(u'bible_showprogress') + Receiver.send_message(u'process_events') for reference in reference_list: log.debug('Reference: %s', reference) book = reference[0] db_book = self.get_book(book) if not db_book: book_details = self.lookup_book(book) + if not book_details: + Receiver.send_message(u'bible_hideprogress') + Receiver.send_message(u'bible_nobook') + return [] db_book = self.create_book(book_details[u'name'], book_details[u'abbr'], book_details[u'test']) book = db_book.name @@ -266,7 +272,7 @@ class HTTPBible(BibleDB): return self.books[book] else: for details in self.books: - if details[u'abbr'] == book: - return details + if self.books[details][u'abbr'] == book: + return self.books[details] return None diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 9f9840fef..9390cf642 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -250,6 +250,8 @@ class BibleMediaItem(MediaManagerItem): QtCore.SIGNAL(u'bible_showprogress'), self.onSearchProgressShow) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'bible_hideprogress'), self.onSearchProgressHide) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'bible_nobook'), self.onNoBookFound) def addListViewToToolBar(self): MediaManagerItem.addListViewToToolBar(self) @@ -351,6 +353,14 @@ class BibleMediaItem(MediaManagerItem): def onSearchProgressHide(self): self.SearchProgress.setVisible(False) + def onNoBookFound(self): + QtGui.QMessageBox.critical(self, + self.trUtf8('No Book Found'), + self.trUtf8('No matching Book could be found in this Bible.'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), + QtGui.QMessageBox.Ok + ) + def onAdvancedVersionComboBox(self): self.initialiseBible( unicode(self.AdvancedVersionComboBox.currentText())) From baabcba2905ac7f034c5a57f8e0beefbe81fce10 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Fri, 29 Jan 2010 23:35:02 +0200 Subject: [PATCH 08/20] Changed the value of the progress bar to look a little more "active" --- openlp/plugins/bibles/lib/http.py | 2 ++ openlp/plugins/bibles/lib/mediaitem.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index a4caeb0f3..a1041d98f 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -128,6 +128,7 @@ class CWExtract(BibleCommon): htmlverses = soup.findAll(u'span', u'versetext') verses = {} for verse in htmlverses: + Receiver.send_message(u'process_events') versenumber = int(verse.contents[0].contents[0]) versetext = u'' for part in verse.contents: @@ -235,6 +236,7 @@ class HTTPBible(BibleDB): db_book = self.get_book(bookname) self.create_chapter(db_book.id, search_results.get_chapter(), search_results.get_verselist()) + Receiver.send_message(u'process_events') Receiver.send_message(u'bible_hideprogress') return BibleDB.get_verses(self, reference_list) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 9390cf642..341d36c6f 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -348,7 +348,8 @@ class BibleMediaItem(MediaManagerItem): def onSearchProgressShow(self): self.SearchProgress.setVisible(True) self.SearchProgress.setMinimum(0) - self.SearchProgress.setMaximum(0) + self.SearchProgress.setMaximum(2) + self.SearchProgress.setValue(1) def onSearchProgressHide(self): self.SearchProgress.setVisible(False) From d45a9733af5dcac5f1882339d8ab142b5de96d63 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 30 Jan 2010 00:26:30 +0200 Subject: [PATCH 09/20] Fixed a bug in Windows and other versions of PyQt4 where "setProperty" was not available. Changed it to "setValue" which is what it's meant to be anyways. --- openlp/plugins/bibles/forms/bibleimportwizard.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py index 1f655a52d..ec190182a 100644 --- a/openlp/plugins/bibles/forms/bibleimportwizard.py +++ b/openlp/plugins/bibles/forms/bibleimportwizard.py @@ -302,8 +302,7 @@ class Ui_BibleImportWizard(object): self.ImportProgressLabel.setObjectName(u'ImportProgressLabel') self.ImportLayout.addWidget(self.ImportProgressLabel) self.ImportProgressBar = QtGui.QProgressBar(self.ImportPage) - self.ImportProgressBar.setProperty(u'value', 0) - self.ImportProgressBar.setInvertedAppearance(False) + self.ImportProgressBar.setValue(0) self.ImportProgressBar.setObjectName(u'ImportProgressBar') self.ImportLayout.addWidget(self.ImportProgressBar) BibleImportWizard.addPage(self.ImportPage) From ab7125c98ec6b2d19b661a831eb44d080e61efc5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 30 Jan 2010 10:42:03 +0200 Subject: [PATCH 10/20] Make the progress bar only pop up when we *actually* fetch a verse from the Internet --- openlp/plugins/bibles/lib/http.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index a1041d98f..5b75407be 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -209,8 +209,6 @@ class HTTPBible(BibleDB): [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] """ - Receiver.send_message(u'bible_showprogress') - Receiver.send_message(u'process_events') for reference in reference_list: log.debug('Reference: %s', reference) book = reference[0] @@ -218,13 +216,14 @@ class HTTPBible(BibleDB): if not db_book: book_details = self.lookup_book(book) if not book_details: - Receiver.send_message(u'bible_hideprogress') Receiver.send_message(u'bible_nobook') return [] db_book = self.create_book(book_details[u'name'], book_details[u'abbr'], book_details[u'test']) book = db_book.name if self.get_verse_count(book, reference[1]) == 0: + Receiver.send_message(u'bible_showprogress') + Receiver.send_message(u'process_events') search_results = self.get_chapter(self.name, book, reference[1]) if search_results and search_results.has_verselist(): ## We have found a book of the bible lets check to see @@ -236,8 +235,8 @@ class HTTPBible(BibleDB): db_book = self.get_book(bookname) self.create_chapter(db_book.id, search_results.get_chapter(), search_results.get_verselist()) + Receiver.send_message(u'bible_hideprogress') Receiver.send_message(u'process_events') - Receiver.send_message(u'bible_hideprogress') return BibleDB.get_verses(self, reference_list) def get_chapter(self, version, book, chapter): From 2b5ddb13a430779d7a093ba5164d4b4d6d9eaf91 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sun, 31 Jan 2010 21:49:01 +0200 Subject: [PATCH 11/20] An attempt to fix the problems some folks are having. --- openlp/plugins/bibles/bibleplugin.py | 4 +- .../plugins/bibles/forms/bibleimportwizard.py | 13 +----- .../plugins/bibles/forms/importwizardform.py | 44 ++++++++----------- openlp/plugins/bibles/lib/csvbible.py | 4 +- openlp/plugins/bibles/lib/db.py | 3 +- openlp/plugins/bibles/lib/http.py | 19 ++++---- openlp/plugins/bibles/lib/manager.py | 28 +++++++----- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/bibles/lib/opensong.py | 33 ++++++-------- openlp/plugins/bibles/lib/osis.py | 4 +- openlp/plugins/custom/forms/editcustomform.py | 10 ++--- openlp/plugins/songs/lib/mediaitem.py | 11 +++-- 12 files changed, 80 insertions(+), 95 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 912a02212..5fafac65b 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -45,7 +45,7 @@ class BiblePlugin(Plugin): def initialise(self): log.info(u'bibles Initialising') if self.biblemanager is None: - self.biblemanager = BibleManager(self.config) + self.biblemanager = BibleManager(self, self.config) Plugin.initialise(self) self.insert_toolbox_item() self.ImportBibleItem.setVisible(True) @@ -90,4 +90,4 @@ class BiblePlugin(Plugin): about_text = self.trUtf8('<strong>Bible Plugin</strong><br />This ' 'plugin allows bible verses from different sources to be ' 'displayed on the screen during the service.') - return about_text \ No newline at end of file + return about_text diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py index ec190182a..59e38e39a 100644 --- a/openlp/plugins/bibles/forms/bibleimportwizard.py +++ b/openlp/plugins/bibles/forms/bibleimportwizard.py @@ -91,15 +91,6 @@ class Ui_BibleImportWizard(object): self.OsisLayout.setMargin(0) self.OsisLayout.setSpacing(8) 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.setObjectName(u'OsisLocationLabel') self.OsisLayout.setWidget(1, QtGui.QFormLayout.LabelRole, @@ -307,7 +298,6 @@ class Ui_BibleImportWizard(object): self.ImportLayout.addWidget(self.ImportProgressBar) BibleImportWizard.addPage(self.ImportPage) - self.retranslateUi(BibleImportWizard) self.FormatWidget.setCurrentIndex(0) self.WebDownloadTabWidget.setCurrentIndex(0) @@ -333,7 +323,6 @@ class Ui_BibleImportWizard(object): self.FormatComboBox.setItemText(1, self.trUtf8('CSV')) self.FormatComboBox.setItemText(2, self.trUtf8('OpenSong')) self.FormatComboBox.setItemText(3, self.trUtf8('Web Download')) - self.OsisBibleNameLabel.setText(self.trUtf8('Bible Name:')) self.OsisLocationLabel.setText(self.trUtf8('File Location:')) self.BooksLocationLabel.setText(self.trUtf8('Books Location:')) self.VerseLocationLabel.setText(self.trUtf8('Verse Location:')) @@ -361,4 +350,4 @@ class Ui_BibleImportWizard(object): self.ImportPage.setSubTitle( self.trUtf8('Please wait while your Bible is imported.')) self.ImportProgressLabel.setText(self.trUtf8('Ready.')) - #self.ImportProgressBar.setFormat(u'%p') + self.ImportProgressBar.setFormat(u'%p%') diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 4fcb18ad4..8be453db0 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -27,6 +27,7 @@ import logging import os import os.path from time import sleep +import csv from PyQt4 import QtCore, QtGui @@ -107,14 +108,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): elif self.currentId() == 1: # Select page 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'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Bible Location'), @@ -218,8 +211,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): def registerFields(self): self.SelectPage.registerField( u'source_format', self.FormatComboBox) - self.SelectPage.registerField( - u'osis_biblename', self.OsisBibleNameEdit) self.SelectPage.registerField( u'osis_location', self.OSISLocationEdit) self.SelectPage.registerField( @@ -247,7 +238,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): def setDefaults(self): self.setField(u'source_format', 0) - self.setField(u'osis_biblename', u'') self.setField(u'osis_location', u'') self.setField(u'csv_booksfile', u'') self.setField(u'csv_versefile', u'') @@ -276,29 +266,33 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): fbibles = None try: self.web_bible_list[DownloadLocation.Crosswalk] = {} - fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') - for line in fbibles: - parts = line.split(u',') - self.web_bible_list[DownloadLocation.Crosswalk][parts[0]] = \ - parts[1].rstrip() + books_file = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') + dialect = csv.Sniffer().sniff(books_file.read(1024)) + books_file.seek(0) + books_reader = csv.reader(books_file, dialect) + for line in books_reader: + self.web_bible_list[DownloadLocation.Crosswalk][line[0]] = \ + unicode(line[1], u'utf-8').strip() except: log.exception(u'Crosswalk resources missing') finally: - if fbibles: - fbibles.close() + if books_file: + books_file.close() #Load and store BibleGateway Bibles try: self.web_bible_list[DownloadLocation.BibleGateway] = {} - fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r') - for line in fbibles: - parts = line.split(u',') - self.web_bible_list[DownloadLocation.BibleGateway][parts[0]] = \ - parts[1].rstrip() + books_file = open(os.path.join(filepath, u'biblegateway.csv'), 'r') + dialect = csv.Sniffer().sniff(books_file.read(1024)) + books_file.seek(0) + books_reader = csv.reader(books_file, dialect) + for line in books_reader: + self.web_bible_list[DownloadLocation.BibleGateway][line[0]] = \ + unicode(line[1], u'utf-8').strip() except: log.exception(u'Biblegateway resources missing') finally: - if fbibles: - fbibles.close() + if books_file: + books_file.close() def getFileName(self, title, editbox): filename = QtGui.QFileDialog.getOpenFileName(self, title, diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index f98ef0c86..d0db5159d 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -37,13 +37,13 @@ class CSVBible(BibleDB): 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 This class assumes the files contain all the information and a clean bible is being loaded. """ - BibleDB.__init__(self, **kwargs) + BibleDB.__init__(self, parent, **kwargs) log.info(self.__class__.__name__) if u'booksfile' not in kwargs: raise KeyError(u'You have to supply a file to import books from.') diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 2131737fd..5c7229f4a 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -42,7 +42,7 @@ class BibleDB(QtCore.QObject): 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 tables if the database doesn't exist. @@ -60,6 +60,7 @@ class BibleDB(QtCore.QObject): The configuration object, passed in from the plugin. """ log.info(u'BibleDBimpl loaded') + QtCore.QObject.__init__(self) if u'path' not in kwargs: raise KeyError(u'Missing keyword argument "path".') if u'name' not in kwargs: diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 5b75407be..4472000d5 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -142,7 +142,7 @@ class CWExtract(BibleCommon): class HTTPBible(BibleDB): log.info(u'%s loaded', __name__) - def __init__(self, **kwargs): + def __init__(self, parent, **kwargs): """ Finds all the bibles defined for the system 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. """ - BibleDB.__init__(self, **kwargs) + BibleDB.__init__(self, parent, **kwargs) if u'download_source' not in kwargs: raise KeyError(u'Missing keyword argument "download_source"') if u'download_name' not in kwargs: @@ -267,13 +267,10 @@ class HTTPBible(BibleDB): def set_books(self, books): self.books = books - def lookup_book(self, book): - log.debug('Looking up "%s" in %s', (book, self.books)) - if book in self.books: - return self.books[book] - else: - for details in self.books: - if self.books[details][u'abbr'] == book: - return self.books[details] - return None + def lookup_book(self, name): + log.debug('Looking up "%s" in %s', (name, self.books)) + for book in self.books: + if book[u'name'] == name or book[u'abbr'] == name: + return book + return None diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 88982a8bf..3ca76bbab 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -90,7 +90,7 @@ class BibleManager(object): log = logging.getLogger(u'BibleManager') 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 object for each bible containing connection information. Throws @@ -101,8 +101,9 @@ class BibleManager(object): ``config`` The plugin's configuration object. """ - self.config = config log.debug(u'Bible Initialising') + self.config = config + self.parent = parent self.web = u'Web' self.db_cache = None self.http_cache = None @@ -120,18 +121,19 @@ class BibleManager(object): filepath, u'..', u'resources', u'httpbooks.csv')) books_file = None try: - self.http_books = {} + self.http_books = [] books_file = open(filepath, u'r') dialect = csv.Sniffer().sniff(books_file.read(1024)) books_file.seek(0) books_reader = csv.reader(books_file, dialect) for line in books_reader: - self.http_books[line[0]] = { - u'name': line[0], - u'abbr': line[1], + self.http_books.append({ + u'name': unicode(line[0]), + u'abbr': unicode(line[1]), u'test': line[2], - u'chap': line[3] - } + u'chap': line[3], + u'ordr': order + }) except: log.exception(u'Failed to load http books.') finally: @@ -148,13 +150,13 @@ class BibleManager(object): self.web_bibles_present = False for filename in files: 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. source = self.db_cache[name].get_meta(u'download source') if source: self.web_bibles_present = True 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, download_name=download_name) meta_proxy = self.db_cache[name].get_meta(u'proxy url') @@ -187,7 +189,7 @@ class BibleManager(object): class_ = BibleFormat.get_class(type) kwargs['path'] = self.path kwargs['config'] = self.config - importer = class_(**kwargs) + importer = class_(self.parent, **kwargs) name = importer.register(self.import_wizard) self.db_cache[name] = importer return importer.do_import() @@ -381,8 +383,12 @@ class BibleManager(object): """ 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(): 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: return True return False diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 341d36c6f..213c79c54 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -357,7 +357,7 @@ class BibleMediaItem(MediaManagerItem): def onNoBookFound(self): QtGui.QMessageBox.critical(self, 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.Ok ) diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 64eeeb0f9..9e0c77b13 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -42,18 +42,18 @@ class OpenSongBible(BibleDB): 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 class. This class is used to import Bibles from OpenSong's XML format. """ log.debug(__name__) - BibleDB.__init__(self, **kwargs) + BibleDB.__init__(self, parent, **kwargs) if 'filename' not in kwargs: raise KeyError(u'You have to supply a file name to import from.') self.filename = kwargs['filename'] - #QtCore.QObject.connect(Receiver.get_receiver(), - # QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): """ @@ -69,27 +69,20 @@ class OpenSongBible(BibleDB): log.debug(u'Starting OpenSong import from "%s"' % self.filename) self.filename = unicode(self.filename, u'utf-8') 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 success = True 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) bible = opensong.getroot() for book in bible.b: if self.stop_import: break - db_book = self.create_book(book.attrib[u'n'], - book.attrib[u'n'][:4]) + db_book = self.create_book(unicode(book.attrib[u'n']), + unicode(book.attrib[u'n'][:4])) for chapter in book.c: if self.stop_import: break @@ -100,12 +93,12 @@ class OpenSongBible(BibleDB): db_book.id, int(chapter.attrib[u'n']), int(verse.attrib[u'n']), - verse.text + unicode(verse.text) ) Receiver.send_message(u'process_events') self.wizard.incrementProgressBar( - QtCore.QString('Importing %s %s' % \ - (db_book.name, chapter.attrib[u'n']))) + QtCore.QString('%s %s %s' % (self.trUtf8('Importing'),\ + db_book.name, chapter.attrib[u'n']))) self.commit() except: log.exception(u'Loading bible from OpenSong file failed') diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index a7e4ba374..b68bd5ff5 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -43,13 +43,13 @@ class OSISBible(BibleDB): log = logging.getLogger(u'BibleOSISImpl') 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 class. This class is used to import Bibles from OpenSong's XML format. """ log.debug(__name__) - BibleDB.__init__(self, **kwargs) + BibleDB.__init__(self, parent, **kwargs) if u'filename' not in kwargs: raise KeyError(u'You have to supply a file name to import from.') self.filename = kwargs[u'filename'] diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 98eb5598a..e701c0938 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -153,10 +153,10 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): sxml.add_verse_to_lyrics(u'custom', unicode(count), unicode(self.VerseListView.item(i).text())) count += 1 - self.customSlide.title = unicode(self.TitleEdit.displayText()) - self.customSlide.text = unicode(sxml.extract_xml()) - self.customSlide.credits = unicode(self.CreditEdit.displayText()) - self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText()) + self.customSlide.title = unicode(self.TitleEdit.displayText(), u'utf-8') + self.customSlide.text = unicode(sxml.extract_xml(), u'utf-8') + self.customSlide.credits = unicode(self.CreditEdit.displayText(), u'utf-8') + self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText(), u'utf-8') self.custommanager.save_slide(self.customSlide) return True @@ -257,4 +257,4 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): if len(self.VerseTextEdit.toPlainText()) > 0: self.VerseTextEdit.setFocus() return False, self.trUtf8('You have unsaved data') - return True, u'' \ No newline at end of file + return True, u'' diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 9aef321e5..f5fe0686b 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -185,8 +185,13 @@ class SongMediaItem(MediaManagerItem): if author_list != u'': author_list = author_list + u', ' author_list = author_list + author.display_name - song_detail = unicode(self.trUtf8('%s (%s)' % \ - (unicode(song.title), unicode(author_list)))) + if not isinstance(author_list, unicode): + 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.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) self.ListView.addItem(song_name) @@ -339,4 +344,4 @@ class SongMediaItem(MediaManagerItem): service_item.audit = [ song.title, author_audit, song.copyright, song.ccli_number ] - return True \ No newline at end of file + return True From db534dc2e84a61234a5f51b30c2a8e3d91bd74ef Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sun, 31 Jan 2010 21:51:23 +0200 Subject: [PATCH 12/20] Removed signals while they're still not working. --- openlp/plugins/bibles/lib/csvbible.py | 4 ++-- openlp/plugins/bibles/lib/opensong.py | 4 ++-- openlp/plugins/bibles/lib/osis.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index d0db5159d..94ebf3ce7 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -51,8 +51,8 @@ class CSVBible(BibleDB): if u'versesfile' not in kwargs: raise KeyError(u'You have to supply a file to import verses from.') self.versesfile = kwargs[u'versesfile'] - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + #QtCore.QObject.connect(Receiver.get_receiver(), + # QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): """ diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 9e0c77b13..f9f445973 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -52,8 +52,8 @@ class OpenSongBible(BibleDB): if 'filename' not in kwargs: raise KeyError(u'You have to supply a file name to import from.') self.filename = kwargs['filename'] - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + #QtCore.QObject.connect(Receiver.get_receiver(), + # QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index b68bd5ff5..dbcb1d57f 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -81,8 +81,8 @@ class OSISBible(BibleDB): finally: if fbibles: fbibles.close() - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) + #QtCore.QObject.connect(Receiver.get_receiver(), + # QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): """ From 01ec0f407fc6bffd4c836e7183e5a0fed00cbe49 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sun, 31 Jan 2010 22:36:54 +0200 Subject: [PATCH 13/20] Fixed up some of the Bible loading --- .../plugins/bibles/forms/importwizardform.py | 22 +++++++++---------- openlp/plugins/bibles/lib/db.py | 16 +++++++------- openlp/plugins/bibles/lib/http.py | 8 +++---- openlp/plugins/bibles/lib/manager.py | 3 +-- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 8be453db0..c490e960e 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -97,9 +97,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged) - def show(self): + def exec_(self): self.setDefaults() - return QtGui.QWizard.show() + return QtGui.QWizard.exec_(self) def validateCurrentPage(self): if self.currentId() == 0: @@ -238,22 +238,22 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): def setDefaults(self): self.setField(u'source_format', 0) - self.setField(u'osis_location', u'') - self.setField(u'csv_booksfile', u'') - self.setField(u'csv_versefile', u'') - self.setField(u'opensong_file', u'') - self.setField(u'web_location', 0) + self.setField(u'osis_location', '') + self.setField(u'csv_booksfile', '') + self.setField(u'csv_versefile', '') + self.setField(u'opensong_file', '') + self.setField(u'web_location', DownloadLocation.Crosswalk) self.setField(u'web_biblename', self.BibleComboBox) self.setField(u'proxy_server', - self.config.get_config(u'proxy address', u'')) + self.config.get_config(u'proxy address', '')) self.setField(u'proxy_username', - self.config.get_config(u'proxy username',u'')) + self.config.get_config(u'proxy username','')) self.setField(u'proxy_password', - self.config.get_config(u'proxy password',u'')) + self.config.get_config(u'proxy password','')) self.setField(u'license_version', self.VersionNameEdit) self.setField(u'license_copyright', self.CopyrightEdit) self.setField(u'license_permission', self.PermissionEdit) - self.onLocationComboBoxChanged(0) + self.onLocationComboBoxChanged(DownloadLocation.Crosswalk) def loadWebBibles(self): """ diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 5c7229f4a..bd29001e2 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -109,7 +109,7 @@ class BibleDB(QtCore.QObject): self.create_testament(u'Apocrypha') def create_testament(self, testament): - log.debug(u'%s: %s', __name__, testament) + log.debug(u'BibleDB.create_testament("%s")', testament) self.session.add(Testament.populate(name=testament)) self.commit() @@ -153,11 +153,11 @@ class BibleDB(QtCore.QObject): self.commit() def get_books(self): - log.debug(__name__) + log.debug(u'BibleDB.get_books()') return self.session.query(Book).order_by(Book.id).all() def get_book(self, book): - log.debug(u'%s: %s', __name__, book) + log.debug(u'BibleDb.get_book("%s")', __name__, book) db_book = self.session.query(Book)\ .filter(Book.name.like(book + u'%'))\ .first() @@ -168,7 +168,7 @@ class BibleDB(QtCore.QObject): return db_book def get_chapter(self, id, chapter): - log.debug(u'%s: %s, %s', __name__, id, chapter) + log.debug(u'BibleDB.get_chapter("%s", %s)', id, chapter) return self.session.query(Verse)\ .filter_by(chapter=chapter)\ .filter_by(book_id=id)\ @@ -192,7 +192,7 @@ class BibleDB(QtCore.QObject): [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] """ - log.debug(u'%s: %s', __name__, reference_list) + log.debug(u'BibleDB.get_verses: %s', reference_list) verse_list = [] for book, chapter, start_verse, end_verse in reference_list: db_book = self.get_book(book) @@ -221,7 +221,7 @@ class BibleDB(QtCore.QObject): contains spaces, it will split apart and AND'd on the list of values. """ - log.debug(u'%s: %s', __name__, text) + log.debug(u'BibleDB.verse_search("%s")', text) verses = self.session.query(Verse) if text.find(u',') > -1: or_clause = [] @@ -237,7 +237,7 @@ class BibleDB(QtCore.QObject): return verses def get_chapter_count(self, book): - log.debug(u'%s: %s', __name__, book) + log.debug(u'BibleDB.get_chapter_count("%s")', book) count = self.session.query(Verse.chapter).join(Book)\ .filter(Book.name==book)\ .distinct().count() @@ -249,7 +249,7 @@ class BibleDB(QtCore.QObject): return count def get_verse_count(self, book, chapter): - log.debug(u'%s: %s, %s', __name__, book, chapter) + log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter) count = self.session.query(Verse).join(Book)\ .filter(Book.name==book)\ .filter(Verse.chapter==chapter)\ diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 4472000d5..607c94f0d 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -42,7 +42,7 @@ class BGExtract(BibleCommon): log.debug(u'init %s', proxyurl) self.proxyurl = proxyurl - def get_chapter(self, version, bookname, chapter) : + def get_bible_chapter(self, version, bookname, chapter) : """ Access and decode bibles via the BibleGateway website @@ -256,10 +256,10 @@ class HTTPBible(BibleDB): return None def get_books(self): - return [Book.populate(name=self.books[book]['name']) for book in self.books] + return [Book.populate(name=book['name']) for book in self.books] def get_chapter_count(self, book): - return self.books[book][u'chap'] + return self.lookup_book(book)[u'chap'] def set_proxy_server(self, server): self.proxy_server = server @@ -268,7 +268,7 @@ class HTTPBible(BibleDB): self.books = books def lookup_book(self, name): - log.debug('Looking up "%s" in %s', (name, self.books)) + log.debug('Looking up "%s" in %s', name, self.books) for book in self.books: if book[u'name'] == name or book[u'abbr'] == name: return book diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 3ca76bbab..4c67dc289 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -131,8 +131,7 @@ class BibleManager(object): u'name': unicode(line[0]), u'abbr': unicode(line[1]), u'test': line[2], - u'chap': line[3], - u'ordr': order + u'chap': line[3] }) except: log.exception(u'Failed to load http books.') From e465264630ee51eb5d04ddf8e9d9d1908a71340e Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Thu, 4 Feb 2010 19:38:21 +0200 Subject: [PATCH 14/20] Standardised manager name to "manager" --- openlp/plugins/bibles/bibleplugin.py | 7 ++-- .../plugins/bibles/forms/importwizardform.py | 22 +++++----- openlp/plugins/bibles/lib/manager.py | 4 +- openlp/plugins/bibles/lib/mediaitem.py | 42 +++++++++---------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 5fafac65b..d560b0bce 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -40,12 +40,12 @@ class BiblePlugin(Plugin): self.weight = -9 self.icon = build_icon(u':/media/media_bible.png') #Register the bible Manager - self.biblemanager = None + self.manager = None def initialise(self): log.info(u'bibles Initialising') - if self.biblemanager is None: - self.biblemanager = BibleManager(self, self.config) + if self.manager is None: + self.manager = BibleManager(self, self.config) Plugin.initialise(self) self.insert_toolbox_item() self.ImportBibleItem.setVisible(True) @@ -91,3 +91,4 @@ class BiblePlugin(Plugin): 'plugin allows bible verses from different sources to be ' 'displayed on the screen during the service.') return about_text + diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index c490e960e..a684c01a3 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -60,7 +60,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): log = logging.getLogger(u'BibleImportForm') log.info(u'BibleImportForm loaded') - def __init__(self, parent, config, biblemanager, bibleplugin): + def __init__(self, parent, config, manager, bibleplugin): ''' Constructor ''' @@ -69,10 +69,10 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.registerFields() self.finishButton = self.button(QtGui.QWizard.FinishButton) self.cancelButton = self.button(QtGui.QWizard.CancelButton) - self.biblemanager = biblemanager + self.manager = manager self.config = config self.bibleplugin = bibleplugin - self.biblemanager.set_process_dialog(self) + self.manager.set_process_dialog(self) self.web_bible_list = {} self.loadWebBibles() QtCore.QObject.connect(self.LocationComboBox, @@ -162,7 +162,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.CopyrightEdit.setFocus() return False - elif self.biblemanager.exists( + elif self.manager.exists( self.field(u'license_version').toString()): QtGui.QMessageBox.critical(self, self.trUtf8('Bible Exists'), @@ -320,20 +320,20 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): success = False if bible_type == BibleFormat.OSIS: # Import an OSIS bible - success = self.biblemanager.import_bible(BibleFormat.OSIS, + success = self.manager.import_bible(BibleFormat.OSIS, name=unicode(self.field(u'license_version').toString()), filename=unicode(self.field(u'osis_location').toString()) ) elif bible_type == BibleFormat.CSV: # Import a CSV bible - success = self.biblemanager.import_bible(BibleFormat.CSV, + success = self.manager.import_bible(BibleFormat.CSV, name=unicode(self.field(u'license_version').toString()), booksfile=self.field(u'csv_booksfile').toString(), versefile=self.field(u'csv_versefile').toString() ) elif bible_type == BibleFormat.OpenSong: # Import an OpenSong bible - success = self.biblemanager.import_bible(BibleFormat.OpenSong, + success = self.manager.import_bible(BibleFormat.OpenSong, name=unicode(self.field(u'license_version').toString()), filename=self.field(u'opensong_file').toString() ) @@ -347,7 +347,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): elif download_location == DownloadLocation.BibleGateway: bible = self.web_bible_list[DownloadLocation.BibleGateway][ unicode(self.BibleComboBox.currentText())] - success = self.biblemanager.import_bible(BibleFormat.WebDownload, + success = self.manager.import_bible(BibleFormat.WebDownload, name=unicode(self.field(u'license_version').toString()), download_source=unicode(DownloadLocation.get_name(download_location)), download_name=unicode(bible), @@ -356,13 +356,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): proxy_password=unicode(self.field(u'proxy_password').toString()) ) if success: - self.biblemanager.save_meta_data( + self.manager.save_meta_data( unicode(self.field(u'license_version').toString()), unicode(self.field(u'license_version').toString()), unicode(self.field(u'license_copyright').toString()), unicode(self.field(u'license_permission').toString()) ) - self.biblemanager.reload_bibles() + self.manager.reload_bibles() self.ImportProgressLabel.setText(self.trUtf8('Finished import.')) else: self.ImportProgressLabel.setText( @@ -372,4 +372,4 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.ImportProgressBar.setValue(self.ImportProgressBar.maximum()) self.finishButton.setVisible(True) self.cancelButton.setVisible(False) - Receiver.send_message(u'process_events') + Receiver.send_message(u'process_events') \ No newline at end of file diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 4c67dc289..7ac99530c 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -383,11 +383,11 @@ class BibleManager(object): Check cache to see if new bible """ if not isinstance(name, unicode): - name = unicode(name, u'utf8') + name = unicode(name) for bible, db_object in self.db_cache.iteritems(): log.debug(u'Bible from cache in is_new_bible %s', bible) if not isinstance(bible, unicode): - bible = unicode(bible, u'utf8') + bible = unicode(bible) if bible == name: return True return False diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 213c79c54..fb6b2eafa 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -303,7 +303,7 @@ class BibleMediaItem(MediaManagerItem): def initialise(self): log.debug(u'bible manager initialise') - self.parent.biblemanager.media = self + self.parent.manager.media = self self.loadBibles() self.configUpdated() log.debug(u'bible manager initialise complete') @@ -323,13 +323,13 @@ class BibleMediaItem(MediaManagerItem): self.AdvancedSecondBibleComboBox.clear() self.QuickSecondBibleComboBox.addItem(u'') self.AdvancedSecondBibleComboBox.addItem(u'') - bibles = self.parent.biblemanager.get_bibles(BibleMode.Full) + bibles = self.parent.manager.get_bibles(BibleMode.Full) # load bibles into the combo boxes for bible in bibles: self.QuickVersionComboBox.addItem(bible) self.QuickSecondBibleComboBox.addItem(bible) # Without HTTP - #bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial) + #bibles = self.parent.manager.get_bibles(BibleMode.Partial) first = True # load bibles into the combo boxes for bible in bibles: @@ -375,10 +375,10 @@ class BibleMediaItem(MediaManagerItem): def onNewClick(self): #self.bibleimportform = BibleImportForm( - # self.parent.config, self.parent.biblemanager, self) + # self.parent.config, self.parent.manager, self) #self.bibleimportform.exec_() self.bibleimportform = ImportWizardForm(self, self.parent.config, - self.parent.biblemanager, self.parent) + self.parent.manager, self.parent) self.bibleimportform.exec_() self.reloadBibles() @@ -393,7 +393,7 @@ class BibleMediaItem(MediaManagerItem): bible = unicode(self.AdvancedVersionComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText()) # get the verse count for new chapter - verses = self.parent.biblemanager.get_book_verse_count( + verses = self.parent.manager.get_book_verse_count( bible, book, int(text2)) self.adjustComboBox(1, verses, self.AdvancedToVerse) @@ -418,7 +418,7 @@ class BibleMediaItem(MediaManagerItem): cf = int(self.AdvancedFromChapter.currentText()) self.adjustComboBox(cf, self.chapters_from, self.AdvancedToChapter) # get the verse count for new chapter - vse = self.parent.biblemanager.get_book_verse_count(bible, book, cf) + vse = self.parent.manager.get_book_verse_count(bible, book, cf) self.adjustComboBox(1, vse, self.AdvancedFromVerse) self.adjustComboBox(1, vse, self.AdvancedToVerse) @@ -430,10 +430,10 @@ class BibleMediaItem(MediaManagerItem): self.ListView.clear() #if self.QuickSearchComboBox.currentIndex() == 1: # self.search_results = \ - # self.parent.biblemanager.get_verses(bible, text) + # self.parent.manager.get_verses(bible, text) #else: # self.searchByReference(bible, text) - self.search_results = self.parent.biblemanager.get_verses(bible, text) + self.search_results = self.parent.manager.get_verses(bible, text) if self.search_results: self.displayResults(bible) @@ -524,12 +524,12 @@ class BibleMediaItem(MediaManagerItem): def reloadBibles(self): log.debug(u'Reloading Bibles') - self.parent.biblemanager.reload_bibles() + self.parent.manager.reload_bibles() self.loadBibles() def initialiseBible(self, bible): log.debug(u'initialiseBible %s', bible) - book_data = self.parent.biblemanager.get_bible_books(bible) + book_data = self.parent.manager.get_bible_books(bible) self.AdvancedBookComboBox.clear() first = True for book in book_data: @@ -545,7 +545,7 @@ class BibleMediaItem(MediaManagerItem): def initialiseChapterVerse(self, bible, book, chapters): log.debug(u'initialiseChapterVerse %s, %s', bible, book) self.chapters_from = chapters - self.verses = self.parent.biblemanager.get_book_verse_count(bible, + self.verses = self.parent.manager.get_book_verse_count(bible, book, 1) if self.verses == 0: self.AdvancedSearchButton.setEnabled(False) @@ -578,12 +578,12 @@ class BibleMediaItem(MediaManagerItem): def searchByReference(self, bible, search): log.debug(u'searchByReference %s, %s', bible, search) - self.search_results = self.parent.biblemanager.get_verses(bible, search) - self.copyright = unicode(self.parent.biblemanager.get_meta_data( + self.search_results = self.parent.manager.get_verses(bible, search) + self.copyright = unicode(self.parent.manager.get_meta_data( bible, u'Copyright').value) - self.permissions = unicode(self.parent.biblemanager.get_meta_data( + self.permissions = unicode(self.parent.manager.get_meta_data( bible, u'Permissions').value) - self.version = unicode(self.parent.biblemanager.get_meta_data( + self.version = unicode(self.parent.manager.get_meta_data( bible, u'Version').value) # def searchByReference(self, bible, search): @@ -658,15 +658,15 @@ class BibleMediaItem(MediaManagerItem): # unicode(start_verse), unicode(end_verse))) # if message is None: # self.search_results = None -# self.search_results = self.parent.biblemanager.get_verse_text( +# self.search_results = self.parent.manager.get_verse_text( # bible, book, int(start_chapter), int(end_chapter), # int(start_verse), int(end_verse)) -# self.copyright = unicode(self.parent.biblemanager.get_meta_data( +# self.copyright = unicode(self.parent.manager.get_meta_data( # bible, u'Copyright').value) -# self.permissions = unicode(self.parent.biblemanager.get_meta_data( +# self.permissions = unicode(self.parent.manager.get_meta_data( # bible, u'Permissions').value) -# self.version = unicode(self.parent.biblemanager.get_meta_data( +# self.version = unicode(self.parent.manager.get_meta_data( # bible, u'Version').value) # else: # QtGui.QMessageBox.information( -# self, self.trUtf8('Information'), message) +# self, self.trUtf8('Information'), message) \ No newline at end of file From ce6738a976e7e36f72b0eeabd7b5f423f93a1a4f Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Thu, 4 Feb 2010 21:34:12 +0200 Subject: [PATCH 15/20] Fixed up searching for non-latin characters in Bible book names. Removed an annoying exception to do with debug logging. --- openlp/plugins/bibles/lib/common.py | 13 ++++++++++--- openlp/plugins/bibles/lib/db.py | 10 +++++----- openlp/plugins/bibles/lib/manager.py | 10 +++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index 3190b5d8d..962a1271f 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -28,13 +28,15 @@ import chardet import logging import re -only_verses = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)' +only_verses = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)' r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?', re.UNICODE) -chapter_range = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*' +chapter_range = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*' r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)', re.UNICODE) +log = logging.getLogger(__name__) + def parse_reference(reference): """ This is the über-awesome function that takes a person's typed in string @@ -47,11 +49,13 @@ def parse_reference(reference): (book, chapter, start_verse, end_verse) """ reference = reference.strip() + log.debug('parse_reference("%s")', reference) reference_list = [] # We start with the most "complicated" match first, so that they are found # first, and we don't have any "false positives". match = chapter_range.match(reference) if match: + log.debug('Found a chapter range.') reference_list.extend([ (match.group(1), match.group(2), match.group(3), -1), (match.group(1), match.group(4), 1, match.group(5)) @@ -59,6 +63,7 @@ def parse_reference(reference): else: match = only_verses.match(reference) if match: + log.debug('Found a verse range.') book = match.group(1) chapter = match.group(2) verse = match.group(3) @@ -82,6 +87,8 @@ def parse_reference(reference): (book, chapter, verse, match.group(4)), (book, chapter, match.group(5), end_verse) ]) + else: + log.debug('Didn\'t find anything.') return reference_list class SearchResults: @@ -216,4 +223,4 @@ class BibleCommon(object): text = text[:start_tag] + text[end_tag + 1:] start_tag = text.find(u'<') text = text.replace(u'>', u'') - return text.rstrip().lstrip() \ No newline at end of file + return text.rstrip().lstrip() diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index bd29001e2..413f2ca1f 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -157,7 +157,7 @@ class BibleDB(QtCore.QObject): return self.session.query(Book).order_by(Book.id).all() def get_book(self, book): - log.debug(u'BibleDb.get_book("%s")', __name__, book) + log.debug(u'BibleDb.get_book("%s")', book) db_book = self.session.query(Book)\ .filter(Book.name.like(book + u'%'))\ .first() @@ -200,7 +200,7 @@ class BibleDB(QtCore.QObject): end_verse = self.get_chapter_count(book) if db_book: book = db_book.name - log.debug(u'Book name corrected to "%s"' % book) + log.debug(u'Book name corrected to "%s"', book) verses = self.session.query(Verse)\ .filter_by(book_id=db_book.id)\ .filter_by(chapter=chapter)\ @@ -276,11 +276,11 @@ class BibleDB(QtCore.QObject): return False def dump_bible(self): - log.debug( u'.........Dumping Bible Database') - log.debug( '...............................Books ') + log.debug(u'.........Dumping Bible Database') + log.debug('...............................Books ') books = self.session.query(Book).all() log.debug(books) - log.debug( u'...............................Verses ') + log.debug(u'...............................Verses ') verses = self.session.query(Verse).all() log.debug(verses) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 7ac99530c..92e6cda9a 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -250,12 +250,12 @@ class BibleManager(object): Returns all the number of verses for a given book and chapterMaxBibleBookVerses """ - log.debug(u'get_verses_from_text %s,%s', bible, versetext) + log.debug(u'get_verses_from_text %s, %s', bible, versetext) reflist = parse_reference(versetext) - web_index = bible.find('(%s)' % self.web) - if web_index >= 0: - bible = bible[:web_index - 1] - log.debug('Updated bible name: %s', bible) + #web_index = bible.find('(%s)' % self.web) + #if web_index >= 0: + # bible = bible[:web_index - 1] + # log.debug('Updated bible name: %s', bible) #web, bible = self.is_bible_web(bible) #if web: # return self.http_cache[bible].get_verses(reflist) From 78c525ab760dfe35755962ae7b68090c45be11b5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 6 Feb 2010 12:22:20 +0200 Subject: [PATCH 16/20] Moved data for web bibles to am SQLite database. --- openlp.pyw | 2 +- openlp/plugins/bibles/lib/common.py | 36 +++- openlp/plugins/bibles/lib/db.py | 2 +- openlp/plugins/bibles/lib/http.py | 107 +++++++++-- openlp/plugins/bibles/lib/manager.py | 225 +++++------------------ openlp/plugins/bibles/lib/mediaitem.py | 237 ++++++++----------------- openlp/plugins/bibles/lib/models.py | 2 +- 7 files changed, 249 insertions(+), 362 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 58925fdb9..914dbce50 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -148,7 +148,7 @@ def main(): usage = u'Usage: %prog [options] [qt-options]' parser = OptionParser(usage=usage) parser.add_option("-l", "--log-level", dest="loglevel", - default="info", metavar="LEVEL", + default="warning", metavar="LEVEL", help="Set logging to LEVEL level. Valid values are " "\"debug\", \"info\", \"warning\".") parser.add_option("-p", "--portable", dest="portable", diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index 962a1271f..5152ca496 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -27,6 +27,7 @@ import urllib2 import chardet import logging import re +import sqlite3 only_verses = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)' r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?', @@ -56,10 +57,33 @@ def parse_reference(reference): match = chapter_range.match(reference) if match: log.debug('Found a chapter range.') - reference_list.extend([ - (match.group(1), match.group(2), match.group(3), -1), - (match.group(1), match.group(4), 1, match.group(5)) - ]) + book = match.group(1) + from_verse = match.group(3) + to_verse = match.group(5) + if int(match.group(2)) == int(match.group(4)): + reference_list.append( + (match.group(1), int(match.group(2)), from_verse, to_verse) + ) + else: + if int(match.group(2)) > int(match.group(4)): + from_chapter = int(match.group(4)) + to_chapter = int(match.group(2)) + else: + from_chapter = int(match.group(2)) + to_chapter = int(match.group(4)) + for chapter in xrange(from_chapter, to_chapter + 1): + if chapter == from_chapter: + reference_list.append( + (match.group(1), chapter, from_verse, -1) + ) + elif chapter == to_chapter: + reference_list.append( + (match.group(1), chapter, 1, to_verse) + ) + else: + reference_list.append( + (match.group(1), chapter, 1, -1) + ) else: match = only_verses.match(reference) if match: @@ -89,9 +113,11 @@ def parse_reference(reference): ]) else: log.debug('Didn\'t find anything.') + log.debug(reference_list) return reference_list -class SearchResults: + +class SearchResults(object): """ Encapsulate a set of search results. This is Bible-type independant. """ diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 413f2ca1f..deedf9d21 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -197,7 +197,7 @@ class BibleDB(QtCore.QObject): for book, chapter, start_verse, end_verse in reference_list: db_book = self.get_book(book) if end_verse == -1: - end_verse = self.get_chapter_count(book) + end_verse = self.get_verse_count(book, chapter) if db_book: book = db_book.name log.debug(u'Book name corrected to "%s"', book) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 607c94f0d..eb140b710 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -25,6 +25,8 @@ import logging import urllib2 +import os +import sqlite3 from BeautifulSoup import BeautifulSoup @@ -33,6 +35,89 @@ from common import BibleCommon, SearchResults from db import BibleDB from openlp.plugins.bibles.lib.models import Book +class HTTPBooks(object): + cursor = None + + @staticmethod + def get_cursor(): + if HTTPBooks.cursor is None: + filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), + u'..', u'resources', u'httpbooks.sqlite') + conn = sqlite3.connect(filepath) + HTTPBooks.cursor = conn.cursor() + return HTTPBooks.cursor + + @staticmethod + def run_sql(query, parameters=()): + cursor = HTTPBooks.get_cursor() + cursor.execute(query, parameters) + return cursor.fetchall() + + @staticmethod + def get_books(): + books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, ' + u'abbreviation, chapters FROM books ORDER BY id') + book_list = [] + for book in books: + book_list.append({ + u'id': book[0], + u'testament_id': book[1], + u'name': unicode(book[2]), + u'abbreviation': unicode(book[3]), + u'chapters': book[4] + }) + return book_list + + @staticmethod + def get_book(name): + if not isinstance(name, unicode): + name = unicode(name) + books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, ' + u'abbreviation, chapters FROM books WHERE name = ? OR ' + u'abbreviation = ?', (name, name)) + if len(books) > 0: + return { + u'id': books[0][0], + u'testament_id': books[0][1], + u'name': unicode(books[0][2]), + u'abbreviation': unicode(books[0][3]), + u'chapters': books[0][4] + } + else: + return None + + @staticmethod + def get_chapter(name, chapter): + if not isinstance(name, int): + chapter = int(chapter) + book = HTTPBooks.get_book(name) + chapters = HTTPBooks.run_sql(u'SELECT id, book_id, chapter, ' + u'verses FROM chapters WHERE book_id = ?', (book[u'id'],)) + if len(chapters) > 0: + return { + u'id': chapters[0][0], + u'book_id': chapters[0][1], + u'chapter': chapters[0][2], + u'verses': chapters[0][3] + } + else: + return None + + @staticmethod + def get_chapter_count(book): + details = HTTPBooks.get_book(book) + if details: + return details[u'chapters'] + return 0 + + @staticmethod + def get_verse_count(book, chapter): + details = HTTPBooks.get_chapter(book, chapter) + if details: + return details[u'verses'] + return 0 + + class BGExtract(BibleCommon): global log log = logging.getLogger(u'BibleHTTPMgr(BG_extract)') @@ -219,7 +304,7 @@ class HTTPBible(BibleDB): Receiver.send_message(u'bible_nobook') return [] db_book = self.create_book(book_details[u'name'], - book_details[u'abbr'], book_details[u'test']) + book_details[u'abbreviation'], book_details[u'testament_id']) book = db_book.name if self.get_verse_count(book, reference[1]) == 0: Receiver.send_message(u'bible_showprogress') @@ -256,21 +341,17 @@ class HTTPBible(BibleDB): return None def get_books(self): - return [Book.populate(name=book['name']) for book in self.books] + return [Book.populate(name=book['name']) for book in HTTPBooks.get_books()] + + def lookup_book(self, book): + return HTTPBooks.get_book(book) def get_chapter_count(self, book): - return self.lookup_book(book)[u'chap'] + return HTTPBooks.get_chapter_count(book) + + def get_verse_count(self, book, chapter): + return HTTPBooks.get_verse_count(book, chapter) def set_proxy_server(self, server): self.proxy_server = server - def set_books(self, books): - self.books = books - - def lookup_book(self, name): - log.debug('Looking up "%s" in %s', name, self.books) - for book in self.books: - if book[u'name'] == name or book[u'abbr'] == name: - return book - return None - diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 92e6cda9a..db70ac6db 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -106,8 +106,6 @@ class BibleManager(object): self.parent = parent self.web = u'Web' self.db_cache = None - self.http_cache = None - self.http_books = {} self.path = self.config.get_data_path() self.proxy_name = self.config.get_config(u'proxy name') self.suffix = u'sqlite' @@ -115,54 +113,30 @@ class BibleManager(object): self.reload_bibles() self.media = None - def load_http_books(self): - filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join( - filepath, u'..', u'resources', u'httpbooks.csv')) - books_file = None - try: - self.http_books = [] - books_file = open(filepath, u'r') - dialect = csv.Sniffer().sniff(books_file.read(1024)) - books_file.seek(0) - books_reader = csv.reader(books_file, dialect) - for line in books_reader: - self.http_books.append({ - u'name': unicode(line[0]), - u'abbr': unicode(line[1]), - u'test': line[2], - u'chap': line[3] - }) - except: - log.exception(u'Failed to load http books.') - finally: - if books_file: - books_file.close() - def reload_bibles(self): + """ + Reloads the Bibles from the available Bible databases on disk. If a web + Bible is encountered, an instance of HTTPBible is loaded instead of the + BibleDB class. + """ log.debug(u'Reload bibles') files = self.config.get_files(self.suffix) log.debug(u'Bible Files %s', files) self.db_cache = {} - self.http_cache = {} - self.load_http_books() - self.web_bibles_present = False for filename in files: name, extension = os.path.splitext(filename) 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. source = self.db_cache[name].get_meta(u'download source') if source: - self.web_bibles_present = True download_name = self.db_cache[name].get_meta(u'download name').value + meta_proxy = self.db_cache[name].get_meta(u'proxy url') web_bible = HTTPBible(self.parent, path=self.path, name=name, config=self.config, download_source=source.value, download_name=download_name) - meta_proxy = self.db_cache[name].get_meta(u'proxy url') if meta_proxy: web_bible.set_proxy_server(meta_proxy.value) - web_bible.set_books(self.http_books) - del self.db_cache[name] + #del self.db_cache[name] self.db_cache[name] = web_bible log.debug(u'Bibles reloaded') @@ -180,10 +154,10 @@ class BibleManager(object): Register a bible in the bible cache, and then import the verses. ``type`` - What type of Bible, one of the BibleFormat values. + What type of Bible, one of the ``BibleFormat`` values. ``**kwargs`` - Keyword arguments to send to the actualy importer class. + Keyword arguments to send to the actual importer class. """ class_ = BibleFormat.get_class(type) kwargs['path'] = self.path @@ -193,73 +167,61 @@ class BibleManager(object): self.db_cache[name] = importer return importer.do_import() - def get_bibles(self, mode=BibleMode.Full): + def get_bibles(self): """ - Returns a list of Books of the bible. When ``mode`` is set to - ``BibleMode.Full`` this method returns all the Bibles for the Advanced - Search, and when the mode is ``BibleMode.Partial`` this method returns - all the bibles for the Quick Search. + Returns a list of the names of available Bibles. """ log.debug(u'get_bibles') - bible_list = [] - for bible_name, bible_object in self.db_cache.iteritems(): - #if getattr(bible_object, 'download_source', None): - # bible_name = u'%s (%s)' % (bible_name, self.web) - bible_list.append(bible_name) - return bible_list + return [name for name, bible in self.db_cache.iteritems()] - def is_bible_web(self, bible): - pos_end = bible.find(u' (%s)' % self.web) - if pos_end != -1: - return True, bible[:pos_end] - return False, bible - - def get_bible_books(self, bible): + def get_books(self, bible): """ - Returns a list of the books of the bible - """ - log.debug(u'get_bible_books') - return [{'name': book.name, 'total': self.db_cache[bible].get_chapter_count(book.name)} for book in self.db_cache[bible].get_books()] + Returns a list of Bible books, and the number of chapters in that book. - def get_book_chapter_count(self, book): + ``bible`` + Unicode. The Bible to get the list of books from. + """ + log.debug(u'BibleManager.get_books("%s")', bible) + return [ + { + u'name': book.name, + u'chapters': self.db_cache[bible].get_chapter_count(book.name) + } + for book in self.db_cache[bible].get_books() + ] + + def get_chapter_count(self, bible, book): """ Returns the number of Chapters for a given book """ log.debug(u'get_book_chapter_count %s', book) - return self.book_chapters[book] + return self.db_cache[bible].get_chapter_count(book) - def get_book_verse_count(self, bible, book, chapter): + def get_verse_count(self, bible, book, chapter): """ Returns all the number of verses for a given book and chapterMaxBibleBookVerses """ - log.debug(u'get_book_verse_count %s,%s,%s', bible, book, chapter) - web, bible = self.is_bible_web(bible) - if web: - count = self.db_cache[bible].get_verse_count(book, chapter) - if count == 0: - # Make sure the first chapter has been downloaded - self.get_verse_text(bible, book, chapter, chapter, 1, 1) - count = self.db_cache[bible].get_verse_count(book, chapter) - return count - else: - return self.db_cache[bible].get_verse_count(book, chapter) + log.debug(u'BibleManager.get_verse_count("%s", "%s", %s)', bible, book, chapter) + return self.db_cache[bible].get_verse_count(book, chapter) def get_verses(self, bible, versetext): """ - Returns all the number of verses for a given - book and chapterMaxBibleBookVerses + Parses a scripture reference, fetches the verses from the Bible + specified, and returns a list of ``Verse`` objects. + + ``bible`` + Unicode. The Bible to use. + + ``versetext`` + Unicode. The scripture reference. Valid scripture references are: + + - Genesis 1:1 + - Genesis 1:1-10 + - Genesis 1:1-2:10 """ - log.debug(u'get_verses_from_text %s, %s', bible, versetext) + log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext) reflist = parse_reference(versetext) - #web_index = bible.find('(%s)' % self.web) - #if web_index >= 0: - # bible = bible[:web_index - 1] - # log.debug('Updated bible name: %s', bible) - #web, bible = self.is_bible_web(bible) - #if web: - # return self.http_cache[bible].get_verses(reflist) - #else: return self.db_cache[bible].get_verses(reflist) def save_meta_data(self, bible, version, copyright, permissions): @@ -277,107 +239,8 @@ class BibleManager(object): Returns the meta data for a given key """ log.debug(u'get_meta %s,%s', bible, key) - web, bible = self.is_bible_web(bible) return self.db_cache[bible].get_meta(key) - def get_verse_text(self, bible, book, schapter, echapter, sverse, everse=0): - """ - Returns a list of verses for a given Book, Chapter and ranges of verses. - If the end verse(everse) is less then the start verse(sverse) - then only one verse is returned - - ``bible`` - The name of the bible to be used - - Rest can be guessed at ! - """ - text = [] - self.media.setQuickMessage(u'') - log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', - bible, book, schapter, echapter, sverse, everse) - # check to see if book/chapter exists fow HTTP bibles and load cache - # if necessary - web, bible = self.is_bible_web(bible) - web_bible = False - log.debug('Web Bibles: %s', self.http_cache) - if self.http_cache[bible]: - web_bible = True - db_book = self.db_cache[bible].get_book(book) - if db_book is None: - log.debug(u'get_verse_text: new book') - for chapter in range(schapter, echapter + 1): - self.media.setQuickMessage( - unicode(self.media.trUtf8('Downloading %s: %s')) % - (book, chapter)) - search_results = \ - self.http_cache[bible].get_chapter(bible, book, chapter) - if search_results and search_results.has_verselist(): - ## We have found a book of the bible lets check to see - ## if it was there. By reusing the returned book name - ## we get a correct book. For example it is possible - ## to request ac and get Acts back. - bookname = search_results.get_book() - # check to see if book/chapter exists - db_book = self.db_cache[bible].get_book(bookname) - if db_book is None: - ## Then create book, chapter and text - db_book = self.db_cache[bible].create_book( - bookname, self.book_abbreviations[bookname], - self.book_testaments[bookname]) - log.debug(u'New http book %s, %s, %s', - db_book, db_book.id, db_book.name) - self.db_cache[bible].create_chapter( - db_book.id, search_results.get_chapter(), - search_results.get_verselist()) - else: - ## Book exists check chapter and texts only. - v = self.db_cache[bible].get_chapter( - db_book.id, chapter) - if v is None: - self.media.setQuickMessage( - unicode(self.media.trUtf8('%Downloading %s: %s'))\ - % (book, chapter)) - self.db_cache[bible].create_chapter( - db_book.id, chapter, - search_results.get_verselist()) - else: - log.debug(u'get_verse_text : old book') - for chapter in range(schapter, echapter + 1): - v = self.db_cache[bible].get_chapter(db_book.id, chapter) - if v is None: - try: - self.media.setQuickMessage(\ - unicode(self.media.trUtf8('Downloading %s: %s')) - % (book, chapter)) - search_results = \ - self.http_cache[bible].get_chapter( - bible, bookn, chapter) - if search_results.has_verselist(): - self.db_cache[bible].create_chapter( - db_book.id, search_results.get_chapter(), - search_results.get_verselist()) - except: - log.exception(u'Problem getting scripture online') - #Now get verses from database - if schapter == echapter: - text = self.db_cache[bible].get_verses( - [(book, schapter, sverse, everse)]) - else: - verse_list = [] - for chapter in range(schapter, echapter + 1): - if chapter == schapter: - start = sverse - end = self.get_verse_count(bible, book, chapter) - elif chapter == echapter: - start = 1 - end = everse - else: - start = 1 - end = self.get_verse_count(bible, book, chapter) - verse_list.append((bible, chapter, start, end)) - text = self.db_cache[bible].get_verses(verse_list) - return text - def exists(self, name): """ Check cache to see if new bible diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fb6b2eafa..45c417130 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -60,6 +60,7 @@ class BibleMediaItem(MediaManagerItem): self.IconPath = u'songs/song' self.ListViewWithDnD_class = BibleListView self.servicePath = None + self.lastReference = u'' MediaManagerItem.__init__(self, parent, icon, title) # place to store the search results self.search_results = {} @@ -323,21 +324,16 @@ class BibleMediaItem(MediaManagerItem): self.AdvancedSecondBibleComboBox.clear() self.QuickSecondBibleComboBox.addItem(u'') self.AdvancedSecondBibleComboBox.addItem(u'') - bibles = self.parent.manager.get_bibles(BibleMode.Full) + bibles = self.parent.manager.get_bibles() # load bibles into the combo boxes + first = True for bible in bibles: self.QuickVersionComboBox.addItem(bible) self.QuickSecondBibleComboBox.addItem(bible) - # Without HTTP - #bibles = self.parent.manager.get_bibles(BibleMode.Partial) - first = True - # load bibles into the combo boxes - for bible in bibles: self.AdvancedVersionComboBox.addItem(bible) self.AdvancedSecondBibleComboBox.addItem(bible) if first: first = False - # use the first bible as the trigger self.initialiseBible(bible) def onListViewResize(self, width, height): @@ -374,9 +370,6 @@ class BibleMediaItem(MediaManagerItem): self.AdvancedBookComboBox.itemData(item).toInt()[0]) def onNewClick(self): - #self.bibleimportform = BibleImportForm( - # self.parent.config, self.parent.manager, self) - #self.bibleimportform.exec_() self.bibleimportform = ImportWizardForm(self, self.parent.config, self.parent.manager, self.parent) self.bibleimportform.exec_() @@ -387,14 +380,13 @@ class BibleMediaItem(MediaManagerItem): self.adjustComboBox(frm, self.verses, self.AdvancedToVerse) def onAdvancedToChapter(self): - text1 = unicode(self.AdvancedFromChapter.currentText()) - text2 = unicode(self.AdvancedToChapter.currentText()) - if text1 != text2: + frm = unicode(self.AdvancedFromChapter.currentText()) + to = unicode(self.AdvancedToChapter.currentText()) + if frm != to: bible = unicode(self.AdvancedVersionComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText()) # get the verse count for new chapter - verses = self.parent.manager.get_book_verse_count( - bible, book, int(text2)) + verses = self.parent.manager.get_verse_count(bible, book, int(to)) self.adjustComboBox(1, verses, self.AdvancedToVerse) def onAdvancedSearchButton(self): @@ -408,6 +400,7 @@ class BibleMediaItem(MediaManagerItem): versetext = u'%s %s:%s-%s:%s' % (book, chapter_from, verse_from, \ chapter_to, verse_to) self.search_results = self.parent.manager.get_verses(bible, versetext) + self.lastReference = versetext if self.ClearAdvancedSearchComboBox.currentIndex() == 0: self.ListView.clear() self.displayResults(bible) @@ -418,7 +411,7 @@ class BibleMediaItem(MediaManagerItem): cf = int(self.AdvancedFromChapter.currentText()) self.adjustComboBox(cf, self.chapters_from, self.AdvancedToChapter) # get the verse count for new chapter - vse = self.parent.manager.get_book_verse_count(bible, book, cf) + vse = self.parent.manager.get_verse_count(bible, book, cf) self.adjustComboBox(1, vse, self.AdvancedFromVerse) self.adjustComboBox(1, vse, self.AdvancedToVerse) @@ -428,12 +421,8 @@ class BibleMediaItem(MediaManagerItem): text = unicode(self.QuickSearchEdit.displayText()) if self.ClearQuickSearchComboBox.currentIndex() == 0: self.ListView.clear() - #if self.QuickSearchComboBox.currentIndex() == 1: - # self.search_results = \ - # self.parent.manager.get_verses(bible, text) - #else: - # self.searchByReference(bible, text) self.search_results = self.parent.manager.get_verses(bible, text) + self.lastReference = text if self.search_results: self.displayResults(bible) @@ -446,60 +435,62 @@ class BibleMediaItem(MediaManagerItem): raw_slides = [] raw_footer = [] bible_text = u'' + #If we want to use a 2nd translation / version + bible2 = u'' + if self.SearchTabWidget.currentIndex() == 0: + bible2 = unicode(self.QuickSecondBibleComboBox.currentText()) + else: + bible2 = unicode(self.AdvancedSecondBibleComboBox.currentText()) + if bible2: + self.searchByReference(bible2, self.lastReference) + bible2_verses = self.search_results + bible2_version = self.parent.manager.get_meta_data(bible2, u'Version') + bible2_copyright = self.parent.manager.get_meta_data(bible2, u'Copyright') + bible2_permission = self.parent.manager.get_meta_data(bible2, u'Permission') + # Let's loop through the main lot, and assemble our verses for item in items: bitem = self.ListView.item(item.row()) - text = unicode((bitem.data(QtCore.Qt.UserRole)).toString()) - search_verse = text[:text.find(u'(')] - bible = text[text.find(u'(') + 1:-1] - self.searchByReference(bible, search_verse) - book = self.search_results[0].book.name - chapter = unicode(self.search_results[0].chapter) - verse = unicode(self.search_results[0].verse) - text = self.search_results[0].text + reference = bitem.data(QtCore.Qt.UserRole).toPyObject() + bible = unicode(reference[QtCore.QString('bible')]) + book = unicode(reference[QtCore.QString('book')]) + chapter = unicode(reference[QtCore.QString('chapter')]) + verse = unicode(reference[QtCore.QString('verse')]) + text = unicode(reference[QtCore.QString('text')]) + version = unicode(reference[QtCore.QString('version')]) + copyright = unicode(reference[QtCore.QString('copyright')]) + permission = unicode(reference[QtCore.QString('permission')]) if self.parent.settings_tab.display_style == 1: - loc = self.formatVerse(old_chapter, chapter, verse, u'(u', u')') + verse_text = self.formatVerse(old_chapter, chapter, verse, u'(u', u')') elif self.parent.settings_tab.display_style == 2: - loc = self.formatVerse(old_chapter, chapter, verse, u'{', u'}') + verse_text = self.formatVerse(old_chapter, chapter, verse, u'{', u'}') elif self.parent.settings_tab.display_style == 3: - loc = self.formatVerse(old_chapter, chapter, verse, u'[', u']') + verse_text = self.formatVerse(old_chapter, chapter, verse, u'[', u']') else: - loc = self.formatVerse(old_chapter, chapter, verse, u'', u'') + verse_text = self.formatVerse(old_chapter, chapter, verse, u'', u'') old_chapter = chapter - footer = u'%s (%s %s)' % (book, self.version, self.copyright) + footer = u'%s (%s %s)' % (book, version, copyright) #If not found throws and error so add.s - try: - raw_footer.index(footer) - except: + if footer not in raw_footer: raw_footer.append(footer) - #If we want to use a 2nd translation / version - bible2 = u'' - if self.SearchTabWidget.currentIndex() == 0: - bible2 = unicode(self.QuickSecondBibleComboBox.currentText()) - else: - bible2 = unicode(self.AdvancedSecondBibleComboBox.currentText()) - if len(bible2) > 0: - self.searchByReference(bible2, search_verse) - footer = u'%s (%s %s)' % (book, self.version, self.copyright) + if bible2: + footer = u'%s (%s %s)' % (book, version, copyright) #If not found throws and error so add.s - try: - raw_footer.index(footer) - except: + if footer not in raw_footer: raw_footer.append(footer) - bible_text = u'%s %s \n\n\n %s %s)' % \ - (loc, text, loc, self.search_results[0].text) + bible_text = u'%s %s \n\n %s %s)' % \ + (verse_text, text, verse_text, bible2_verses[item.row()].text) raw_slides.append(bible_text) bible_text = u'' else: #Paragraph style force new line per verse if self.parent.settings_tab.layout_style == 1: text = text + u'\n\n' - bible_text = u'%s %s %s' % (bible_text, loc, text) + bible_text = u'%s %s %s' % (bible_text, verse_text, text) #if we are verse per slide then create slide if self.parent.settings_tab.layout_style == 0: raw_slides.append(bible_text) bible_text = u'' - service_item.title = u'%s %s' % (book, loc) - + service_item.title = u'%s %s' % (book, verse_text) if len(self.parent.settings_tab.bible_theme) == 0: service_item.theme = None else: @@ -513,14 +504,14 @@ class BibleMediaItem(MediaManagerItem): return True def formatVerse(self, old_chapter, chapter, verse, opening, closing): - loc = opening + verse_text = opening if old_chapter != chapter: - loc += chapter + u':' + verse_text += chapter + u':' elif not self.parent.settings_tab.show_new_chapters: - loc += chapter + u':' - loc += verse - loc += closing - return loc + verse_text += chapter + u':' + verse_text += verse + verse_text += closing + return verse_text def reloadBibles(self): log.debug(u'Reloading Bibles') @@ -529,24 +520,23 @@ class BibleMediaItem(MediaManagerItem): def initialiseBible(self, bible): log.debug(u'initialiseBible %s', bible) - book_data = self.parent.manager.get_bible_books(bible) + book_data = self.parent.manager.get_books(bible) self.AdvancedBookComboBox.clear() first = True for book in book_data: row = self.AdvancedBookComboBox.count() self.AdvancedBookComboBox.addItem(book[u'name']) self.AdvancedBookComboBox.setItemData( - row, QtCore.QVariant(book[u'total'])) + row, QtCore.QVariant(book[u'chapters'])) if first: first = False self.initialiseChapterVerse( - bible, book[u'name'], book[u'total']) + bible, book[u'name'], book[u'chapters']) def initialiseChapterVerse(self, bible, book, chapters): log.debug(u'initialiseChapterVerse %s, %s', bible, book) self.chapters_from = chapters - self.verses = self.parent.manager.get_book_verse_count(bible, - book, 1) + self.verses = self.parent.manager.get_verse_count(bible, book, 1) if self.verses == 0: self.AdvancedSearchButton.setEnabled(False) self.AdvancedMessage.setText(self.trUtf8('Bible not fully loaded')) @@ -565,12 +555,30 @@ class BibleMediaItem(MediaManagerItem): combo.addItem(unicode(i)) def displayResults(self, bible): + version = self.parent.manager.get_meta_data(bible, u'Version') + copyright = self.parent.manager.get_meta_data(bible, u'Copyright') + permission = self.parent.manager.get_meta_data(bible, u'Permission') + if not permission: + permission = u'' + else: + permission = permission.value for count, verse in enumerate(self.search_results): - bible_text = u' %s %d:%d (%s)' % (verse.book.name, - verse.chapter, verse.verse, bible) + bible_text = u' %s %d:%d (%s)' % \ + (verse.book.name, verse.chapter, verse.verse, bible) bible_verse = QtGui.QListWidgetItem(bible_text) - bible_verse.setData(QtCore.Qt.UserRole, - QtCore.QVariant(bible_text)) + #bible_verse.setData(QtCore.Qt.UserRole, + # QtCore.QVariant(bible_text)) + vdict = { + 'bible': QtCore.QVariant(bible), + 'version': QtCore.QVariant(version.value), + 'copyright': QtCore.QVariant(copyright.value), + 'permission': QtCore.QVariant(permission), + 'book': QtCore.QVariant(verse.book.name), + 'chapter': QtCore.QVariant(verse.chapter), + 'verse': QtCore.QVariant(verse.verse), + 'text': QtCore.QVariant(verse.text) + } + bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(vdict)) self.ListView.addItem(bible_verse) row = self.ListView.setCurrentRow(count) if row: @@ -579,94 +587,3 @@ class BibleMediaItem(MediaManagerItem): def searchByReference(self, bible, search): log.debug(u'searchByReference %s, %s', bible, search) self.search_results = self.parent.manager.get_verses(bible, search) - self.copyright = unicode(self.parent.manager.get_meta_data( - bible, u'Copyright').value) - self.permissions = unicode(self.parent.manager.get_meta_data( - bible, u'Permissions').value) - self.version = unicode(self.parent.manager.get_meta_data( - bible, u'Version').value) - -# def searchByReference(self, bible, search): -# log.debug(u'searchByReference %s, %s', bible, search) -# book = u'' -# start_chapter = u'' -# end_chapter = u'' -# start_verse = u'' -# end_verse = u'' -# search = search.replace(u' ', u' ').strip() -# #original = search -# message = None -# # Remove book beware 0 index arrays -# for i in range (len(search)-1, 0, - 1): -# if search[i] == u' ': -# book = search[:i] -# # remove book from string -# search = search[i:] -# break -# # allow V or v for verse instead of : -# search = search.replace(u'v', ':') -# search = search.replace(u'V', ':') -# search = search.strip() -# colon = search.find(u':') -# if colon == -1: -# # number : found -# i = search.rfind(u' ') -# if i == -1: -# chapter = u'' -# else: -# chapter = search[i:len(search)] -# hyphen = chapter.find(u'-') -# if hyphen != -1: -# start_chapter= chapter[:hyphen] -# end_chapter= chapter[hyphen + 1:len(chapter)] -# else: -# start_chapter = chapter -# else: -# # more complex -# sp = search.split(u'-') #find first -# sp1 = sp[0].split(u':') -# if len(sp1) == 1: -# start_chapter = sp1[0] -# start_verse = 1 -# else: -# start_chapter = sp1[0] -# start_verse = sp1[1] -# if len(sp)== 1: -# end_chapter = start_chapter -# end_verse = start_verse -# else: -# sp1 = sp[1].split(u':') -# if len(sp1) == 1: -# end_chapter = start_chapter -# end_verse = sp1[0] -# else: -# end_chapter = sp1[0] -# end_verse = sp1[1] -# if end_chapter == u'': -# end_chapter = start_chapter.rstrip() -# if start_verse == u'': -# if end_verse == u'': -# start_verse = 1 -# else: -# start_verse = end_verse -# if end_verse == u'': -# end_verse = 99 -# if start_chapter == u'': -# message = self.trUtf8('No chapter found for search criteria') -# log.debug(u'results = %s @ %s : %s @ %s : %s'% \ -# (unicode(book), unicode(start_chapter), unicode(end_chapter), -# unicode(start_verse), unicode(end_verse))) -# if message is None: -# self.search_results = None -# self.search_results = self.parent.manager.get_verse_text( -# bible, book, int(start_chapter), int(end_chapter), -# int(start_verse), int(end_verse)) -# self.copyright = unicode(self.parent.manager.get_meta_data( -# bible, u'Copyright').value) -# self.permissions = unicode(self.parent.manager.get_meta_data( -# bible, u'Permissions').value) -# self.version = unicode(self.parent.manager.get_meta_data( -# bible, u'Version').value) -# else: -# QtGui.QMessageBox.information( -# self, self.trUtf8('Information'), message) \ No newline at end of file diff --git a/openlp/plugins/bibles/lib/models.py b/openlp/plugins/bibles/lib/models.py index d9c43d1df..2802cb27f 100644 --- a/openlp/plugins/bibles/lib/models.py +++ b/openlp/plugins/bibles/lib/models.py @@ -105,4 +105,4 @@ mapper(Testament, testament_table, properties={'books': relation(Book, backref='testament')}) mapper(Book, book_table, properties={'verses': relation(Verse, backref='book')}) -mapper(Verse, verse_table) \ No newline at end of file +mapper(Verse, verse_table) From cf95b81a497f10e5f56f76ce911c8457a94a2c41 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 6 Feb 2010 12:42:47 +0200 Subject: [PATCH 17/20] Last few fixes --- openlp/plugins/bibles/lib/http.py | 10 +++++++--- .../plugins/bibles/resources/httpbooks.sqlite | Bin 0 -> 45056 bytes 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 openlp/plugins/bibles/resources/httpbooks.sqlite diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index eb140b710..1cf92e4d2 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -207,8 +207,12 @@ class CWExtract(BibleCommon): log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter) bookname = bookname.replace(u' ', u'') - page = urllib2.urlopen(u'http://www.biblestudytools.com/%s/%s/%s.html' % \ - (version, bookname.lower(), chapter)) + chapter_url = u'http://www.biblestudytools.com/%s/%s/%s.html' % \ + (version, bookname.lower(), chapter) + log.debug(u'URL: %s', chapter_url) + page = urllib2.urlopen(chapter_url) + if not page: + return None soup = BeautifulSoup(page) htmlverses = soup.findAll(u'span', u'versetext') verses = {} @@ -306,7 +310,7 @@ class HTTPBible(BibleDB): db_book = self.create_book(book_details[u'name'], book_details[u'abbreviation'], book_details[u'testament_id']) book = db_book.name - if self.get_verse_count(book, reference[1]) == 0: + if BibleDB.get_verse_count(self, book, reference[1]) == 0: Receiver.send_message(u'bible_showprogress') Receiver.send_message(u'process_events') search_results = self.get_chapter(self.name, book, reference[1]) diff --git a/openlp/plugins/bibles/resources/httpbooks.sqlite b/openlp/plugins/bibles/resources/httpbooks.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..ea0c405309e361c3366188aec8604b97db846861 GIT binary patch literal 45056 zcmeHw2Y6h?x%Qcvv%9m})k@lxw5#5Gv*g}w;f`&L3)p}GS8QByrGvE6?uw8E2<ZtS zmGoXnZ;;*~JvW7rLK-3c-ayL#e)D>fE8*t<Z|>#(mLJdiPC4gHJKucs&CJ;~=P%!R zXj}dEeFyezI#fT=^F5`!dG+<4=iPz-$Nz=lQO5=7<M>n3fLv&vkTfB}QzkzfnXdtV zs8WX-mM&F8Er+~K-ezyNx6M1~T?O3f9Rj}$zHRUyhP&6>@(*LpIo@h-p*P=K3%4Hb zd~eWO?)X#RwjH<M<n6%&x{p1w!%GjUP(wq5$}Aku+-7ed{_R4Vai-7w(8lAEH6lap zUIASGYeX5hdJ?+STj?^q7#Up+|0=jky%os(YHtJl=OSEizP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+aBsEK#H{Ib zfrhs>PAjs8PcW_$t$72J+)wyA;ZX;^Ce#vo3GV0A!eJ>le@Kl#9~Zt+qQl;+<o%zn z4|`AlcRHT>&DV#q1Mq2mjrV_TuRmL`e^dj~_k#ZO9e5une4F6Z{-7#xKIH^LP|c-p zJ;6zkpn5TVZrT%6Z>P`AVuI?&&Zn;>Fr{{HXHdK8Nl-uL;!Hb%w>Dep;}eXVkOU3$ zY1}ItG)_bW%~zT7mkxY4y9xT$^mP+v5tb61+8*?sPz(A8<%JA|oa;7Sgf=<uq(sQO zTdoOtpCEjP;N~156?Z=6ghfcrqmLq!zhV<oFJa(o2=5@cDO5=P#QF4fgqMi^A2rvX z@%;ZkYRa?mXKUbW4g7O8V8>`P9W2Mpk2cf6vMM`9o9SR_ksYJWbP!*k9;3~45QhoJ yXfqwe?<<VaW;%$IA7iwc4q{8>7;UD5_??L{+Dr!vk(M^oL7e;;qs??MlK4ME{iuWh literal 0 HcmV?d00001 From 92ef1f0d57f87238d738401051403bbf82a7008b Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 6 Feb 2010 15:05:45 +0200 Subject: [PATCH 18/20] Fixed multi-verse dual bible. --- openlp/plugins/bibles/lib/mediaitem.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 45c417130..bcd9adbb3 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -60,7 +60,7 @@ class BibleMediaItem(MediaManagerItem): self.IconPath = u'songs/song' self.ListViewWithDnD_class = BibleListView self.servicePath = None - self.lastReference = u'' + self.lastReference = [] MediaManagerItem.__init__(self, parent, icon, title) # place to store the search results self.search_results = {} @@ -400,9 +400,10 @@ class BibleMediaItem(MediaManagerItem): versetext = u'%s %s:%s-%s:%s' % (book, chapter_from, verse_from, \ chapter_to, verse_to) self.search_results = self.parent.manager.get_verses(bible, versetext) - self.lastReference = versetext if self.ClearAdvancedSearchComboBox.currentIndex() == 0: self.ListView.clear() + self.lastReference = [] + self.lastReference.append(versetext) self.displayResults(bible) def onAdvancedFromChapter(self): @@ -421,8 +422,9 @@ class BibleMediaItem(MediaManagerItem): text = unicode(self.QuickSearchEdit.displayText()) if self.ClearQuickSearchComboBox.currentIndex() == 0: self.ListView.clear() + self.lastReference = [] + self.lastReference.append(versetext) self.search_results = self.parent.manager.get_verses(bible, text) - self.lastReference = text if self.search_results: self.displayResults(bible) @@ -442,8 +444,9 @@ class BibleMediaItem(MediaManagerItem): else: bible2 = unicode(self.AdvancedSecondBibleComboBox.currentText()) if bible2: - self.searchByReference(bible2, self.lastReference) - bible2_verses = self.search_results + bible2_verses = [] + for scripture in self.lastReference: + bible2_verses.extend(self.parent.manager.get_verses(bible2, scripture)) bible2_version = self.parent.manager.get_meta_data(bible2, u'Version') bible2_copyright = self.parent.manager.get_meta_data(bible2, u'Copyright') bible2_permission = self.parent.manager.get_meta_data(bible2, u'Permission') @@ -477,7 +480,7 @@ class BibleMediaItem(MediaManagerItem): #If not found throws and error so add.s if footer not in raw_footer: raw_footer.append(footer) - bible_text = u'%s %s \n\n %s %s)' % \ + bible_text = u'%s %s \n\n %s %s' % \ (verse_text, text, verse_text, bible2_verses[item.row()].text) raw_slides.append(bible_text) bible_text = u'' From f81968e62b2c615b88dada7417c6e9b1264f42cc Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 6 Feb 2010 15:22:26 +0200 Subject: [PATCH 19/20] Mis-named variable in QuickSearch click. --- openlp/plugins/bibles/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index bcd9adbb3..648694f45 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -423,7 +423,7 @@ class BibleMediaItem(MediaManagerItem): if self.ClearQuickSearchComboBox.currentIndex() == 0: self.ListView.clear() self.lastReference = [] - self.lastReference.append(versetext) + self.lastReference.append(text) self.search_results = self.parent.manager.get_verses(bible, text) if self.search_results: self.displayResults(bible) From bd4d2daa74ed58b1e3f1a9e6b26089081e4934af Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Sat, 6 Feb 2010 15:23:38 +0200 Subject: [PATCH 20/20] Removed now unnecessary file. --- openlp/plugins/bibles/resources/httpbooks.csv | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 openlp/plugins/bibles/resources/httpbooks.csv diff --git a/openlp/plugins/bibles/resources/httpbooks.csv b/openlp/plugins/bibles/resources/httpbooks.csv deleted file mode 100644 index 2d8afa20e..000000000 --- a/openlp/plugins/bibles/resources/httpbooks.csv +++ /dev/null @@ -1,66 +0,0 @@ -Genesis,Gen,1,50 -Exodus,Exod,1,40 -Leviticus,Lev,1,27 -Numbers,Num,1,36 -Deuteronomy,Deut,1,34 -Joshua,Josh,1,24 -Judges,Judg,1,21 -Ruth,Ruth,1,4 -1 Samual,1Sam,1,31 -2 Samual,2Sam,1,24 -1 Kings,1Kgs,1,22 -2 Kings,2Kgs,1,25 -1 Chronicles,1Chr,1,29 -2 Chronicles,2Chr,1,36 -Ezra,Esra,1,10 -Nehemiah,Neh,1,13 -Esther,Esth,1,10 -Job,Job,1,42 -Psalms,Ps,1,150 -Proverbs,Prov,1,31 -Ecclesiastes,Eccl,1,12 -Song of Songs,Song,1,8 -Isaiah,Isa,1,66 -Jeremiah,Jer,1,5 -Lamentations,Lam,1,5 -Ezekiel,Ezek,1,48 -Daniel,Dan,1,12 -Hosea,Hos,1,14 -Joel,Joel,1,3 -Amos,Amos,1,9 -Obad,Obad,1,1 -Jonah,Jonah,1,4 -Micah,Mic,1,7 -Naham,Nah,1,3 -Habakkuk,Hab,1,3 -Zephaniah,Zeph,1,3 -Haggai,Hag,1,2 -Zechariah,Zech,1,3 -Malachi,Mal,1,4 -Matthew,Matt,2,28 -Mark,Mark,2,16 -Luke,Luke,2,24 -John,John,2,21 -Acts,Acts,2,28 -Romans,Rom,2,16 -1 Corinthans,1Cor,2,16 -2 Corinthans,2Cor,2,13 -Galatians,Gal,2,6 -Ephesians,Eph,2,6 -Philippians,Phil,2,4 -Colossians,Col,2,4 -1 Thessalonians,1Thess,2,5 -2 Thessalonians,2Thess,2,3 -1 Timothy,1Tim,2,6 -2 Timothy,2Tim,2,4 -Titus,Titus,2,3 -Philemon,Phlm,2,1 -Hebrews,Heb,2,13 -James,Jas,2,5 -1 Peter,1Pet,2,5 -2 Peter,2Pet,2,3 -1 John,1John,2,5 -2 John,2John,2,1 -3 John,3John,2,1 -Jude,Jude,2,1 -Revelation,Rev,2,22