From dc0f7e7f5a68990745e382eafd30310c9c4ef630 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 21 Dec 2009 22:58:00 +0200 Subject: [PATCH] Finishing touches on the Import wizard and the OpenSong bible importer. --- .../plugins/bibles/forms/importwizardform.py | 11 ++----- openlp/plugins/bibles/lib/bibleCSVimpl.py | 5 +-- openlp/plugins/bibles/lib/bibleDBimpl.py | 4 +-- openlp/plugins/bibles/lib/bibleOSISimpl.py | 26 +++++++++------- .../plugins/bibles/lib/bibleOpenSongimpl.py | 3 +- openlp/plugins/bibles/lib/manager.py | 31 +++++++++++++++++++ 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index ec23637db..c3a91c736 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -32,14 +32,7 @@ from PyQt4 import QtCore, QtGui from bibleimportwizard import Ui_BibleImportWizard from openlp.core.lib import Receiver - -class BibleFormat(object): - Unknown = -1 - OSIS = 0 - CSV = 1 - OpenSong = 2 - WebDownload = 3 - +from openlp.plugins.bibles.lib.manager import BibleFormat class DownloadLocation(object): Unknown = -1 @@ -276,7 +269,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.finishButton.setEnabled(False) self.cancelButton.setVisible(False) self.ImportProgressBar.setMinimum(0) - self.ImportProgressBar.setMaximum(65) + self.ImportProgressBar.setMaximum(1188) self.ImportProgressBar.setValue(0) self.ImportProgressLabel.setText(self.trUtf8('Starting import...')) Receiver.send_message(u'process_events') diff --git a/openlp/plugins/bibles/lib/bibleCSVimpl.py b/openlp/plugins/bibles/lib/bibleCSVimpl.py index 0d419072c..72a0f30d2 100644 --- a/openlp/plugins/bibles/lib/bibleCSVimpl.py +++ b/openlp/plugins/bibles/lib/bibleCSVimpl.py @@ -88,12 +88,13 @@ class BibleCSVImpl(BibleCommon): # 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'') + p3 = p[3].replace(u'"', u'') if book_ptr is not p0: book = self.bibledb.get_bible_book(p0) book_ptr = book.name # increament the progress bar - dialogobject.incrementProgressBar(book.name) + 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 diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index f6e5d5480..2875c96b8 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -53,14 +53,14 @@ class BibleDBImpl(BibleCommon): self.metadata.create_all(checkfirst=True) def create_tables(self): - log.debug( u'createTables') + 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') def add_verse(self, bookid, chap, vse, text): - #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse) + log.debug(u'add_verse %s,%s,%s', bookid, chap, vse) verse = Verse() verse.book_id = bookid verse.chapter = chap diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 5c60e4617..fdfa6cc07 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -53,6 +53,7 @@ class BibleOSISImpl(): A reference to a Bible database object. """ log.info(u'BibleOSISImpl Initialising') + self.verse_regex = re.compile(r'(.*)') self.bibledb = bibledb # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} @@ -98,7 +99,7 @@ class BibleOSISImpl(): detect_file = None try: detect_file = open(osisfile_record, u'r') - details = chardet.detect(detect_file.read(2048)) + details = chardet.detect(detect_file.read(3000)) except: log.exception(u'Failed to detect OSIS file encoding') return @@ -153,6 +154,8 @@ class BibleOSISImpl(): epos = text.find(u'', pos) text = text[:pos] + text[epos + 4: ] pos = text.find(u'') + print ref + continue # split up the reference p = ref.split(u'.', 3) if book_ptr != p[0]: @@ -161,28 +164,29 @@ class BibleOSISImpl(): # set the max book size depending # on the first book read if p[0] == u'Gen': - dialogobject.setMax(65) + dialogobject.ImportProgressBar.setMaximum(1188) else: - dialogobject.setMax(27) + dialogobject.ImportProgressBar.setMaximum(260) # First book of NT if p[0] == u'Matt': testament += 1 + dialogobject.incrementProgressBar(u'Importing %s %s...' % \ + (self.booksOfBible[p[0]], p[1])) + Receiver.send_message(u'process_events') + self.bibledb.save_verses() book_ptr = p[0] book = self.bibledb.create_book( unicode(self.booksOfBible[p[0]]), unicode(self.abbrevOfBible[p[0]]), testament) - dialogobject.incrementProgressBar( - self.booksOfBible[p[0]]) count = 0 - self.bibledb.save_verses() self.bibledb.add_verse(book.id, p[1], p[2], text) - count += 1 + #count += 1 #Every 3 verses repaint the screen - if count % 3 == 0: - Receiver.send_message(u'process_events') - count = 0 - self.bibledb.save_verses() + #if count % 3 == 0: + # Receiver.send_message(u'process_events') + # count = 0 + #self.bibledb.save_verses() except: log.exception(u'Loading bible from OSIS file failed') finally: diff --git a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py index cc7e02f7a..eebbfe5b4 100644 --- a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py +++ b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py @@ -101,7 +101,8 @@ class BibleOpenSongImpl(): self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'], verse.attrib[u'n'], verse.text) Receiver.send_message(u'process_events') - dialogobject.incrementProgressBar(dbbook.name + str(chapter.attrib[u'n'])) + dialogobject.incrementProgressBar(u'Importing %s %s' % \ + (dbbook.name, str(chapter.attrib[u'n']))) self.bibledb.save_verses() except: log.exception(u'Loading bible from OpenSong file failed') diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 20e4ee75d..5a60c13aa 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -36,6 +36,28 @@ class BibleMode(object): Full = 1 Partial = 2 + +class BibleFormat(object): + Unknown = -1 + OSIS = 0 + CSV = 1 + OpenSong = 2 + WebDownload = 3 + + @classmethod + def get_handler(class_, id): + if id == class_.OSIS: + return BibleOSISImpl + elif id == class_.CSV: + return BibleCSVImpl + elif id == class_.OpenSong: + return BibleOpenSongImpl + elif id == class_.WebDownload: + return BibleHTTPImpl + else: + return None + + class BibleManager(object): """ The Bible manager which holds and manages all the Bibles. @@ -142,6 +164,15 @@ class BibleManager(object): """ self.dialogobject = dialogobject + def import_bible(self, type, **kwargs): + """ + Register a bible in the bible cache, and then import the verses. + + ``type`` + What type of Bible, + """ + pass + def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None): """