From b05e609a41f7f8c5107b06ca2ad22ee2024b867c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 24 Feb 2009 20:24:01 +0000 Subject: [PATCH] Tidy up search code some more. bzr-revno: 345 --- openlp/plugins/bibles/bibleplugin.py | 2 +- openlp/plugins/bibles/lib/bibleDBimpl.py | 2 +- openlp/plugins/bibles/lib/bibleHTTPimpl.py | 4 +-- openlp/plugins/bibles/lib/common.py | 17 ++++++++++++ openlp/plugins/bibles/lib/manager.py | 30 +++++++++++++--------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 022789182..68f6c764c 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -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 diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index 13d7d1f8d..a58b92fc9 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -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 diff --git a/openlp/plugins/bibles/lib/bibleHTTPimpl.py b/openlp/plugins/bibles/lib/bibleHTTPimpl.py index 381ad0c7c..c8eeb7817 100644 --- a/openlp/plugins/bibles/lib/bibleHTTPimpl.py +++ b/openlp/plugins/bibles/lib/bibleHTTPimpl.py @@ -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 diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index 0d0637388..58ad7f934 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -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") diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 8594575e8..c04da6e06 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -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])