Add download notifications for HTTP bibles

Fix bug running off the end of bible chapter
This commit is contained in:
Tim Bentley 2009-08-02 14:44:41 +01:00
parent 470f1d19df
commit fa606e19a9
3 changed files with 49 additions and 18 deletions

View File

@ -96,7 +96,7 @@ class CWExtract(BibleCommon):
chapter - chapter number
"""
log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter)
bookname = bookname.replace(u' ', '')
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)
#log.debug(u'Return data %s', xml_string)
@ -151,8 +151,8 @@ class CWExtract(BibleCommon):
verseText = xml_string[versePos: i]
versePos = i
#print verseText
#print self._clean_text(verseText)
bible[verse] = self._clean_text(verseText)
#bible[verse] = verseText
#log.debug( bible)
return SearchResults(book_title, book_chapter, bible)

View File

@ -28,9 +28,7 @@ from bibleOSISimpl import BibleOSISImpl
from bibleCSVimpl import BibleCSVImpl
from bibleDBimpl import BibleDBImpl
from bibleHTTPimpl import BibleHTTPImpl
#from openlp.plugins.bibles.lib.tables import *
#from openlp.plugins.bibles.lib.classes import *
from openlp.core.lib import Receiver
class BibleMode(object):
Full = 1
@ -68,6 +66,15 @@ class BibleManager(object):
self.dialogobject = None
self.reload_bibles()
def set_media_manager(self, media):
"""
Sets the reference to the media manager.
``media``
The reference to the media manager.
"""
self.media = media
def reload_bibles(self):
log.debug(u'Reload bibles')
files = self.config.get_files(self.bibleSuffix)
@ -228,8 +235,7 @@ class BibleManager(object):
Advanced Search, and when the mode is ``BibleMode.Partial``
this method returns all the bibles for the Quick Search.
``mode``
Defaults to ``BibleMode.Full``. The Bible mode.
c
"""
log.debug(u'get_bibles')
bible_list = []
@ -293,17 +299,24 @@ class BibleManager(object):
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 - Which bible to use.
``bible``
The name of the bible to be used
Rest can be guessed at !
"""
text = []
self.media.setQuickMsg1(u'')
self.media.setQuickMsg2(u'')
log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse)
if not self.bible_http_cache[bible] == None:
# check to see if book/chapter exists
# check to see if book/chapter exists fow HTTP bibles and load cache if necessary
if self.bible_http_cache[bible] is not None:
book= self.bible_db_cache[bible].get_bible_book(bookname)
if book == None:
self.media.setQuickMsg1(u'Downloading')
log.debug(u'get_verse_text : new book')
for chapter in range(schapter, echapter + 1):
self.media.setQuickMsg2(u'%s: %s'% (bookname, chapter))
search_results = self.bible_http_cache [bible].get_bible_chapter(bible, 0, bookname, chapter)
if search_results.has_verselist() :
## We have found a book of the bible lets check to see if it was there.
@ -325,6 +338,7 @@ class BibleManager(object):
## Book exists check chapter and texts only.
v = self.bible_db_cache[bible].get_bible_chapter(book.id, chapter)
if v == None:
self.media.setQuickMsg2(u'%s: %s'%(bookname, chapter))
self.bible_db_cache[bible].create_chapter(book.id, \
chapter, \
search_results.get_verselist())
@ -334,26 +348,29 @@ class BibleManager(object):
v = self.bible_db_cache[bible].get_bible_chapter(book.id, chapter)
if v == None:
try:
self.media.setQuickMsg1(u'Downloading')
self.media.setQuickMsg2(u'%s: %s'% (bookname, chapter))
search_results = self.bible_http_cache [bible].get_bible_chapter(bible, book.id, bookname, chapter)
if search_results.has_verselist():
self.bible_db_cache[bible].create_chapter(book.id, \
search_results.get_chapter(),\
search_results.get_verselist())
except :
log.error(u'Errow thrown %s', sys.exc_info()[1])
#Now get verses from database
if schapter == echapter:
text = self.bible_db_cache[bible].get_bible_text(bookname, schapter, sverse, everse)
else:
for i in range (schapter, echapter + 1):
if i == schapter:
start = sverse
end = self.get_book_verse_count(bible, bookname,i )[0]
end = self.get_book_verse_count(bible, bookname, i)
elif i == echapter:
start = 1
end = everse
else:
start = 1
end = self.get_book_verse_count(bible, bookname,i )[0]
end = self.get_book_verse_count(bible, bookname, i)
txt = self.bible_db_cache[bible].get_bible_text(bookname, i, start, end)
text.extend(txt)

View File

@ -135,6 +135,12 @@ class BibleMediaItem(MediaManagerItem):
self.ClearQuickSearchComboBox = QtGui.QComboBox(self.QuickTab)
self.ClearQuickSearchComboBox.setObjectName(u'ClearQuickSearchComboBox')
self.QuickLayout.addWidget(self.ClearQuickSearchComboBox, 3, 1, 1, 1)
self.QuickMsg1 = QtGui.QLabel(self.QuickTab)
self.QuickMsg1.setObjectName(u'QuickSearchLabel')
self.QuickLayout.addWidget(self.QuickMsg1, 4, 0, 1, 1)
self.QuickMsg2 = QtGui.QLabel(self.QuickTab)
self.QuickMsg2.setObjectName(u'QuickSearchLabel')
self.QuickLayout.addWidget(self.QuickMsg2, 4, 1, 1, 1)
self.SearchTabWidget.addTab(self.QuickTab, 'Quick')
QuickSpacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
QtGui.QSizePolicy.Expanding)
@ -254,6 +260,14 @@ class BibleMediaItem(MediaManagerItem):
def initialise(self):
log.debug(u'initialise')
self.loadBibles()
self.parent.biblemanager.set_media_manager(self)
def setQuickMsg1(self, text):
self.QuickMsg1.setText(translate(u'BibleMediaItem', unicode(text)))
def setQuickMsg2(self, text):
self.QuickMsg2.setText(translate(u'BibleMediaItem', unicode(text)))
Receiver().send_message(u'openlpprocessevents')
def loadBibles(self):
log.debug(u'Loading Bibles')