Finishing touches on the Import wizard and the OpenSong bible importer.

This commit is contained in:
Raoul Snyman 2009-12-21 22:58:00 +02:00
parent e29a88e9a3
commit dc0f7e7f5a
6 changed files with 55 additions and 25 deletions

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -53,6 +53,7 @@ class BibleOSISImpl():
A reference to a Bible database object.
"""
log.info(u'BibleOSISImpl Initialising')
self.verse_regex = re.compile(r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*)</verse>')
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'<Rf>', pos)
text = text[:pos] + text[epos + 4: ]
pos = text.find(u'<RF>')
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:

View File

@ -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')

View File

@ -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):
"""