more PEP 8 clean ups

fix advance search across multiple books

bzr-revno: 231
This commit is contained in:
Tim Bentley 2008-12-16 19:13:31 +00:00
parent 70ef8ef2b7
commit 2457713b1d
5 changed files with 48 additions and 34 deletions

View File

@ -297,10 +297,11 @@ class BiblePlugin(Plugin):
chapto = int(self.AdvancedToChapter.currentText())
versefrom = int(self.AdvancedFromVerse.currentText())
verseto = int(self.AdvancedToVerse.currentText())
self.searchresults = self.biblemanager.get_verse_text(bible, book, chapfrom, versefrom, verseto)
self.searchresults = self.biblemanager.get_verse_text(bible, book, chapfrom, chapto, versefrom, verseto)
self._display_results()
def onQuickSearchButton(self):
self.log.debug("onQuickSearchButton")
bible = str(self.QuickVersionComboBox.currentText())
text = str(self.QuickSearchEdit.displayText())
@ -310,6 +311,7 @@ class BiblePlugin(Plugin):
self._verse_search()
def _search_text(self, bible, text):
self.log.debug("_search Text %s,%s", bible, text)
self.searchresults = self.biblemanager.get_verse_from_text(bible,text)
self._display_results()

View File

@ -59,7 +59,7 @@ class BibleCSVImpl(BibleCommon):
p = line.split(",")
p2 = p[2].replace('"', '')
p3 = p[3].replace('"', '')
self.bibledb.createBook(int(p[1]), p2, p3)
self.bibledb.create_book(int(p[1]), p2, p3)
book_ptr = ""
@ -70,7 +70,7 @@ class BibleCSVImpl(BibleCommon):
p0 = p[0].replace('"', '')
p3 = p[3].replace('"', '')
if book_ptr is not p0:
cl = self.bibledb.getBibleBook(p0)
cl = self.bibledb.get_bible_book(p0)
id = self.bibledb.getBibleBookId(p0)
book_ptr = cl
log.debug( id )

View File

@ -147,7 +147,7 @@ class BibleDBImpl(BibleCommon):
session.add(versemeta)
session.commit()
def createChapter(self, bookid, chap, textlist):
def create_chapter(self, bookid, chap, textlist):
log.debug( "createChapter %s,%s,%s", bookid, chap, textlist)
metadata.bind.echo = False
session = self.Session()
@ -160,7 +160,7 @@ class BibleDBImpl(BibleCommon):
session.add(versemeta)
session.commit()
def createBook(self, bookid, bookname, bookabbrev):
def create_book(self, bookid, bookname, bookabbrev):
log.debug( "createBook %s,%s,%s", bookid, bookname, bookabbrev)
metadata.bind.echo = False
session = self.Session()
@ -175,7 +175,7 @@ class BibleDBImpl(BibleCommon):
session.add(bmeta)
session.commit()
def getMeta(self, key):
def get_meta(self, key):
s = text (""" select value FROM metadata where key == :k """)
return self.db.execute(s, k=key).fetchone()
@ -197,55 +197,55 @@ class BibleDBImpl(BibleCommon):
session.commit()
def get_bible_books(self):
log.debug( "getBibleBook ")
log.debug( "get_bible_book ")
metadata.bind.echo = False
s = text (""" select name FROM book order by id """)
return self.db.execute(s).fetchall()
def get_max_bible_book_verses(self, bookname, chapter):
log.debug( "getMaxBibleBookVerses %s,%s ", bookname , chapter)
log.debug( "get_max_bible_book_verses %s,%s ", bookname , chapter)
metadata.bind.echo = False
s = text (""" select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b """)
return self.db.execute(s, c=chapter, b=bookname).fetchone()
def get_max_bible_book_chapter(self, bookname):
log.debug( "getMaxBibleBookChapters %s ", bookname )
log.debug( "get_max_bible_book_chapter %s ", bookname )
metadata.bind.echo = False
s = text (""" select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b """)
return self.db.execute(s, b=bookname).fetchone()
def getBibleBook(self, bookname):
log.debug( "getBibleBook %s", bookname)
def get_bible_book(self, bookname):
log.debug( "get_bible_book %s", bookname)
metadata.bind.echo = False
s = text (""" select name FROM book where book.name == :b """)
return self.db.execute(s, b=bookname).fetchone()
def getBibleBookId(self, bookname):
log.debug( "getBibleBook %s", bookname)
def get_bible_book_Id(self, bookname):
log.debug( "get_bible_book_id %s", bookname)
metadata.bind.echo = False
s = text (""" select id FROM book where book.name == :b """)
return self.db.execute(s, b=bookname).fetchone()
def getBibleChapter(self, bookname, chapter):
log.debug( "getBibleChapter %s,%s", bookname, chapter )
def get_bible_chapter(self, bookname, chapter):
log.debug( "get_bible_chapter %s,%s", bookname, chapter )
metadata.bind.echo = False
s = text (""" select book.name FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and book.name == :b """)
return self.db.execute(s, c=chapter, b=bookname).fetchone()
def getBibleText(self, bookname, chapter, sverse, everse):
log.debug( "getBibleText %s,%s,%s,%s ", bookname, chapter, sverse, everse)
def get_bible_text(self, bookname, chapter, sverse, everse):
log.debug( "get_bible_text %s,%s,%s,%s ", bookname, chapter, sverse, everse)
metadata.bind.echo = False
s = text (""" select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and book.name == :b """)
return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall()
def get_verses_from_text(self,versetext):
log.debug( "getBibleText %s",versetext)
log.debug( "get_verses_from_text %s",versetext)
metadata.bind.echo = False
versetext = "%"+versetext+"%"
s = text (""" select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t """)
return self.db.execute(s, t=versetext).fetchall()
def dumpBible(self):
def dump_bible(self):
log.debug( ".........Dumping Bible Database")
log.debug( "...............................Books ")
s = text (""" select * FROM book """)

View File

@ -91,7 +91,7 @@ class BibleOSISImpl():
p = ref.split(".", 3) # split u[ the reference
if book_ptr != p[0]:
book_ptr = p[0]
self.bibledb.createBook(int(p[1]), self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]])
self.bibledb.create_book(int(p[1]), self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]])
id = self.bibledb.getBibleBookId(self.booksOfBible[p[0]])
dialogobject.incrementBar()
self.bibledb.addVerse(id[0], p[1], p[2], t)

View File

@ -56,13 +56,13 @@ class BibleManager():
nme = f.split('.')
bname = nme[0]
self.bibleDBCache[bname] = BibleDBImpl(self.biblePath, bname, self.bibleSuffix)
biblesource = self.bibleDBCache[bname].getMeta("WEB") # look to see if lazy load bible exists and get create getter.
biblesource = self.bibleDBCache[bname].get_meta("WEB") # look to see if lazy load bible exists and get create getter.
if biblesource:
print biblesource
nhttp = BibleHTTPImpl()
nhttp.setBibleSource(biblesource) # tell The Server where to get the verses from.
self.bibleHTTPCache[bname] = nhttp
proxy = self.bibleDBCache[bname].getMeta("proxy") # look to see if lazy load bible exists and get create getter.
proxy = self.bibleDBCache[bname].get_meta("proxy") # look to see if lazy load bible exists and get create getter.
nhttp.setProxy(proxy) # tell The Server where to get the verses from.
#
@ -195,9 +195,9 @@ class BibleManager():
Returns the meta data for a given key
"""
log.debug( "get_meta %s,%s", bible, key)
self.bibleDBCache[bible].getMeta(key)
self.bibleDBCache[bible].get_meta(key)
def get_verse_text(self, bible, bookname, chapter, sverse, everse = 0 ):
def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse = 0 ):
"""
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)
@ -205,9 +205,10 @@ class BibleManager():
bible - Which bible to use.
Rest can be guessed at !
"""
text = []
#log.debug( self.bibleDBCache)
#log.debug( self.bibleHTTPCache)
log.debug( "getVerseText %s,%s,%s,%s,%s", bible,bookname, chapter, sverse, everse)
log.debug( "get_verse_text %s,%s,%s,%s,%s,%s", bible,bookname, schapter,echapter, sverse, everse)
# bookid = self.booksOfBible[bookname] # convert to id ie Genesis --> 1 Revelation --> 73
# # SORT OUT BOOKNAME BOOK ID.
# # NAME COMES IN TO ID AND BACK TO NAME ?
@ -217,25 +218,36 @@ class BibleManager():
# if not c:
# self._loadBook(bible,bookid, bookname, bookabbrev)
# self._loadChapter(bible, bookid,bookname, chapter)
if everse < sverse:
everse = sverse
text = self.bibleDBCache[bible].getBibleText(bookname, chapter, sverse, everse)
#log.debug( text)
#self.bibleDBCache[bible].dumpBible()
if schapter == echapter:
text = self.bibleDBCache[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]
elif i == echapter:
start = 1
end = everse
else:
start = 1
end = self.get_book_verse_count(bible, bookname,i )[0]
txt = self.bibleDBCache[bible].get_bible_text(bookname, i, start, end)
text.extend(txt)
return text
def _load_book(self, bible, bookid, bookname, bookabbrev):
log.debug( "load_book %s,%s,%s,%s", bible, bookid, bookname, bookabbrev)
cl = self.bibleDBCache[bible].getBibleBook(bookname)
cl = self.bibleDBCache[bible].get_bible_book(bookname)
log.debug( "get bible book %s" , cl)
if not cl :
self.bibleDBCache[bible].createBook(bookid, bookname, bookabbrev)
self.bibleDBCache[bible].create_book(bookid, bookname, bookabbrev)
def _loadChapter(self, bible, bookid, bookname, chapter):
log.debug( "load_chapter %s,%s,%s,%s", bible, bookid,bookname, chapter)
try :
chaptlist = self.bibleHTTPCache[bible].getBibleChapter(bible, bookid,bookname, chapter)
self.bibleDBCache[bible].createChapter(bookname, chapter, chaptlist)
chaptlist = self.bibleHTTPCache[bible].get_bible_chapter(bible, bookid,bookname, chapter)
self.bibleDBCache[bible].create_chapter(bookname, chapter, chaptlist)
except :
log.error("Errow thrown %s", sys.exc_info()[1])