Tidy up search code some more.

bzr-revno: 345
This commit is contained in:
Tim Bentley 2009-02-24 20:24:01 +00:00
parent db2dd4cd87
commit b05e609a41
5 changed files with 39 additions and 16 deletions

View File

@ -559,7 +559,7 @@ class BiblePlugin(Plugin, PluginUtils):
message = "No chapter found for search"
#print "message = " + str(message)
#print "search = " + str(original)
#print "results = " + str(book) + " @ "+ str(start_chapter)+" @ "+ str(end_chapter)+" @ "+ str(start_verse)+ " @ "+ str(end_verse)
print "results = " + str(book) + " @ "+ str(start_chapter)+" @ "+ str(end_chapter)+" @ "+ str(start_verse)+ " @ "+ str(end_verse)
if message == None:
self.search_results = None

View File

@ -79,7 +79,7 @@ class BibleDBImpl(BibleCommon):
metadata.bind.echo = False
session = self.session()
#text list has book and chapter as first to elements of the array
for v , t in textlist[2].iteritems():
for v , t in textlist.iteritems():
verse = Verse()
verse.book_id = bookid
verse.chapter = chap

View File

@ -20,7 +20,7 @@ import os, os.path
import sys
import urllib2
from common import BibleCommon
from common import BibleCommon, SearchResults
import logging
@ -145,7 +145,7 @@ class CWExtract(BibleCommon):
#bible[verse] = verseText
#log.debug( bible)
return book_title , book_chapter , bible
return SearchResults(book_title, book_chapter, bible)
class BibleHTTPImpl():
global log

View File

@ -23,6 +23,23 @@ import urllib2
import logging
class SearchResults:
def __init__(self, book, chapter, verselist):
self.book = book
self.chapter = chapter
self.verselist = verselist
def get_verselist(self):
return self.verselist
def get_book(self):
return self.book
def get_chapter(self):
return self.chapter
def has_verselist(self):
if self.verselist == {}:
return False
else:
return True
class BibleCommon:
global log
log=logging.getLogger("BibleCommon")

View File

@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import os, os.path
import sys
from common import SearchResults
from bibleOSISimpl import BibleOSISImpl
from bibleCSVimpl import BibleCSVImpl
from bibleDBimpl import BibleDBImpl
@ -28,6 +29,7 @@ from bibleHTTPimpl import BibleHTTPImpl
from openlp.plugins.bibles.lib.tables import *
from openlp.plugins.bibles.lib.classes import *
import logging
class BibleManager():
@ -233,35 +235,39 @@ class BibleManager():
if book == None:
log.debug("get_verse_text : new book")
for chapter in range(schapter, echapter+1):
chaptlist = self.bible_http_cache [bible].get_bible_chapter(bible, 0, bookname, chapter)
## chaplist contains 3 elements
## 0 - Book name
## 1 - Chapter Name
## 2 - Chapter list
if chaptlist[2] != {}:
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.
## By reusing the returned book name we get a correct book.
## For example it is possible to request ac and get Acts back.
bookname = chaptlist[0]
bookname = search_results.get_book()
book= self.bible_db_cache[bible].get_bible_book(bookname) # check to see if book/chapter exists
if book == None:
## Then create book, chapter and text
book = self.bible_db_cache[bible].create_book(bookname, self.book_abbreviations[bookname], self.book_testaments[bookname])
book = self.bible_db_cache[bible].create_book(bookname, \
self.book_abbreviations[bookname], \
self.book_testaments[bookname])
log.debug("New http book %s , %s, %s", book, book.id, book.name)
self.bible_db_cache[bible].create_chapter(book.id, chaptlist[1], chaptlist)
self.bible_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(book.id, chapter)
if v == None:
self.bible_db_cache[bible].create_chapter(book.id, book_chapter, chaptlist)
self.bible_db_cache[bible].create_chapter(book.id, \
book_chapter, \
search_results.get_verselist())
else:
log.debug("get_verse_text : old book")
for chapter in range(schapter, echapter+1):
v = self.bible_db_cache[bible].get_bible_chapter(book.id, chapter)
if v == None:
try:
chaptlist = self.bible_http_cache [bible].get_bible_chapter(bible, book.id, bookname, chapter)
self.bible_db_cache[bible].create_chapter(book.id, chapter, chaptlist)
search_results = self.bible_http_cache [bible].get_bible_chapter(bible, book.id, bookname, chapter)
self.bible_db_cache[bible].create_chapter(book.id, \
search_results.get_chapter(),\
search_results.get_verselist())
except :
log.error("Errow thrown %s", sys.exc_info()[1])