finish PEP 8 changes

bzr-revno: 230
This commit is contained in:
Tim Bentley 2008-12-16 17:29:39 +00:00
parent e53e7e7db4
commit 70ef8ef2b7
7 changed files with 86 additions and 86 deletions

View File

@ -243,7 +243,7 @@ class BiblePlugin(Plugin):
cf = self.biblemanager.get_book_chapter_count(bible, currentBook)[0]
log.debug("Book change bible %s book %s ChapterCount %s", bible, currentBook, cf)
if cf == None: # Only change the search details if the book is missing from the new bible
books = self.biblemanager.get_bible_books_full(str(self.AdvancedVersionComboBox.currentText()))
books = self.biblemanager.get_bible_books(str(self.AdvancedVersionComboBox.currentText()))
self.AdvancedBookComboBox.clear()
first = True
for b in books:

View File

@ -43,10 +43,10 @@ class BibleCSVImpl(BibleCommon):
"""
self.bibledb = bibledb
def loadData(self, booksfile, versesfile):
self.bibledb.saveMeta("version", "Bible Version")
self.bibledb.saveMeta("Copyright", "(c) Some Bible company")
self.bibledb.saveMeta("Permission", "You Have Some")
def load_data(self, booksfile, versesfile):
self.bibledb.save_meta("version", "Bible Version")
self.bibledb.save_meta("Copyright", "(c) Some Bible company")
self.bibledb.save_meta("Permission", "You Have Some")
#session = self.Session()

View File

@ -136,7 +136,7 @@ class BibleDBImpl(BibleCommon):
testament_table.create()
book_table.create()
verse_table.create()
self.saveMeta("dbversion", "2")
self.save_meta("dbversion", "2")
self._loadTestaments()
def addVerse(self, bookid, chap, verse, text):
@ -168,7 +168,7 @@ class BibleDBImpl(BibleCommon):
session.add(bookmeta)
session.commit()
def saveMeta(self, key, value):
def save_meta(self, key, value):
metadata.bind.echo = False
session = self.Session()
bmeta= BibleMeta(key, value)
@ -196,19 +196,19 @@ class BibleDBImpl(BibleCommon):
session.add(testmeta)
session.commit()
def getBibleBooks(self):
def get_bible_books(self):
log.debug( "getBibleBook ")
metadata.bind.echo = False
s = text (""" select name FROM book order by id """)
return self.db.execute(s).fetchall()
def getMaxBibleBookVerses(self, bookname, chapter):
def get_max_bible_book_verses(self, bookname, chapter):
log.debug( "getMaxBibleBookVerses %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 getMaxBibleBookChapters(self, bookname):
def get_max_bible_book_chapter(self, bookname):
log.debug( "getMaxBibleBookChapters %s ", bookname )
metadata.bind.echo = False
s = text (""" select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b """)
@ -238,7 +238,7 @@ class BibleDBImpl(BibleCommon):
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 getVersesFromText(self,versetext):
def get_verses_from_text(self,versetext):
log.debug( "getBibleText %s",versetext)
metadata.bind.echo = False
versetext = "%"+versetext+"%"

View File

@ -33,12 +33,12 @@ logging.basicConfig(level=logging.DEBUG,
class BGExtract(BibleCommon):
global log
log=logging.getLogger("BibleHTTPMgr(BGExtract)")
log.info("BGExtract loaded")
log=logging.getLogger("BibleHTTPMgr(BG_extract)")
log.info("BG_extract loaded")
def __init__(self, proxyurl= None):
log.debug("init %s", proxyurl)
self.proxyurl = proxyurl
def getBibleChapter(self, version, bookid, bookname, chapter) :
def get_bible_chapter(self, version, bookid, bookname, chapter) :
"""
Access and decode bibles via the BibleGateway website
Version - the version of the bible like 31 for New International version
@ -48,9 +48,9 @@ class BGExtract(BibleCommon):
"""
version = 49
log.debug( "getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
urlstring = "http://www.biblegateway.com/passage/?book_id="+str(bookid)+"&chapter"+str(chapter)+"&version="+str(version)
xml_string = self._getWebText(urlstring, self.proxyurl)
xml_string = self._get_web_text(urlstring, self.proxyurl)
VerseSearch = "class="+'"'+"sup"+'"'+">"
verse = 1
@ -73,14 +73,14 @@ class BGExtract(BibleCommon):
verseText = xml_string[versePos + 7 : i ]
#print xml_string
#print "VerseText = " + str(verse) +" "+ verseText
bible[verse] = self._cleanText(verseText) # store the verse
bible[verse] = self._clean_text(verseText) # store the verse
versePos = -1
else:
i = xml_string[:i].rfind("<span")+1
verseText = xml_string[versePos + 7 : i - 1 ] # Loose the </span>
xml_string = xml_string[i - 1 :len(xml_string)] # chop off verse 1
versePos = xml_string.find(VerseSearch) #look for the next verse
bible[verse] = self._cleanText(verseText) # store the verse
bible[verse] = self._clean_text(verseText) # store the verse
verse += 1
return bible
@ -91,7 +91,7 @@ class CWExtract(BibleCommon):
def __init__(self, proxyurl=None):
log.debug("init %s", proxyurl)
self.proxyurl = proxyurl
def getBibleChapter(self, version, bookid, bookname, chapter) :
def get_bible_chapter(self, version, bookid, bookname, chapter) :
log.debug( "getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
"""
Access and decode bibles via the Crosswalk website
@ -100,9 +100,9 @@ class CWExtract(BibleCommon):
bookname - text name of in english eg 'gen' for Genesis
chapter - chapter number
"""
log.debug( "getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
urlstring = "http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word="+bookname+"+"+str(chapter)+"&version="+version
xml_string = self._getWebText(urlstring, self.proxyurl)
xml_string = self._get_web_text(urlstring, self.proxyurl)
i= xml_string.find("NavCurrentChapter")
xml_string = xml_string[i:len(xml_string)]
@ -133,7 +133,7 @@ class CWExtract(BibleCommon):
#log.debug( i, versePos)
verseText = xml_string[versePos: i]
versePos = i
bible[verse] = self._cleanText(verseText)
bible[verse] = self._clean_text(verseText)
#bible[verse] = verseText
#log.debug( bible)
@ -155,33 +155,33 @@ class BibleHTTPImpl():
biblesource = ""
proxyurl = None
def setProxy(self,proxyurl):
def set_proxy(self,proxyurl):
"""
Set the Proxy Url
"""
log.debug("setProxy %s", proxyurl)
log.debug("set_proxy %s", proxyurl)
self.proxyurl = proxyurl
def setBibleSource(self,biblesource):
def set_bible_source(self,biblesource):
"""
Set the source of where the bible text is comming from
"""
log.debug("setBibleSource %s", biblesource)
log.debug("set_bible_source %s", biblesource)
self.biblesource = biblesource
def getBibleChapter(self, version, bookid, bookname, chapter):
def get_bible_chapter(self, version, bookid, bookname, chapter):
"""
Recieve the request and call the relevent handler methods
"""
log.debug( "getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug("biblesource = %s", self.biblesource)
try:
if self.biblesource == 'Crosswalk':
ev = CWExtract(self.proxyurl)
else:
ev = CWExtract(self.proxyurl)
ev = BGExtract(self.proxyurl)
return ev.getBibleChapter(version, bookid, bookname, chapter)
return ev.get_bible_chapter(version, bookid, bookname, chapter)
except:
log.error("Error thrown = %s", sys.exc_info()[1])

View File

@ -45,10 +45,10 @@ class BibleOSISImpl():
self.abbrevOfBible[p[0]] = p[2].replace('\n', '')
def loadData(self, osisfile, dialogobject=None):
self.bibledb.saveMeta("Version", "Bible Version")
self.bibledb.saveMeta("Copyright", "(c) Some Bible company")
self.bibledb.saveMeta("Permission", "You Have Some")
def load_data(self, osisfile, dialogobject=None):
self.bibledb.save_meta("Version", "Bible Version")
self.bibledb.save_meta("Copyright", "(c) Some Bible company")
self.bibledb.save_meta("Permission", "You Have Some")
#TODO: need to see if new / old or both testaments
dialogobject.setMax(65)

View File

@ -35,8 +35,8 @@ class BibleCommon:
def __init__(self):
"""
"""
def _getWebText(self, urlstring, proxyurl):
log.debug( "getWebText %s %s", proxyurl, urlstring)
def _get_web_text(self, urlstring, proxyurl):
log.debug( "get_web_text %s %s", proxyurl, urlstring)
if proxyurl != "" or len(proxyurl) > 0 :
print "ProxyUrl " , proxyurl + " " + str(len(proxyurl))
@ -57,7 +57,7 @@ class BibleCommon:
log.error( e.reason)
return xml_string
def _cleanText(self, text):
def _clean_text(self, text):
"""
Clean up text and remove extra characters
after been downloaded from web

View File

@ -71,13 +71,13 @@ class BibleManager():
def process_dialog(self, dialogobject):
self.dialogobject = dialogobject
def registerHTTPBible(self, biblename, biblesource, mode="lazy", proxyurl=None, proxyid=None, proxypass=None):
def register_HTTP_bible(self, biblename, biblesource, mode="lazy", proxyurl=None, proxyid=None, proxypass=None):
"""
Return a list of bibles from a given URL.
The selected Bible can then be registered and LazyLoaded into a database
"""
log.debug( "registerHTTPBible %s,%s,%s,%s,%s", biblename, biblesource, proxyurl, proxyid, proxypass, mode)
if self._isNewBible(biblename):
log.debug( "register_HTTP_bible %s,%s,%s,%s,%s", biblename, biblesource, proxyurl, proxyid, proxypass, mode)
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible
@ -85,28 +85,28 @@ class BibleManager():
nhttp = BibleHTTPImpl()
nhttp.setBibleSource(biblesource)
self.bibleHTTPCache[biblename] = nhttp
nbible.saveMeta("WEB", biblesource) # register a lazy loading interest
nbible.save_meta("WEB", biblesource) # register a lazy loading interest
if proxyurl != None:
nbible.saveMeta("proxy", proxyurl) # store the proxy URL
nbible.save_meta("proxy", proxyurl) # store the proxy URL
nhttp.setProxy(proxyurl)
if proxyid != None:
nbible.saveMeta("proxyid", proxyid) # store the proxy userid
nbible.save_meta("proxyid", proxyid) # store the proxy userid
if proxypass != None:
nbible.saveMeta("proxypass", proxypass) # store the proxy password
nbible.save_meta("proxypass", proxypass) # store the proxy password
def registerCVSFileBible(self, biblename, booksfile, versefile):
def register_CVS_file_bible(self, biblename, booksfile, versefile):
"""
Method to load a bible from a set of files into a database.
If the database exists it is deleted and the database is reloaded
from scratch.
"""
if self._isNewBible(biblename):
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later
bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database
bcsv.loadData(booksfile, versefile)
bcsv.load_data(booksfile, versefile)
def register_OSIS_file_bible(self, biblename, osisfile):
"""
@ -114,8 +114,8 @@ class BibleManager():
If the database exists it is deleted and the database is reloaded
from scratch.
"""
log.debug( "registerOSISFileBible %s , %s", biblename, osisfile)
if self._isNewBible(biblename):
log.debug( "register_OSIS_file_bible %s , %s", biblename, osisfile)
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later
@ -123,24 +123,24 @@ class BibleManager():
bcsv.loadData(osisfile, self.dialogobject)
def loadBible(self,biblename):
"""
Downloads all the books of the bible
and loads it into the database
"""
log.debug( "loadBible %s", biblename)
bookabbrev = ""
for bookname in self.listOfBooks:
cptrs = self.booksChapters[ self.booksOfBible[bookname]]
log.debug( "book and chapter %s %s", bookname , self.booksChapters[ self.booksOfBible[bookname]] )
for chptr in range(1 , int(cptrs)): # loop through all the chapters in book
c = self.bibleDBCache[biblename].getBibleChapter(bookname, chptr) # check to see if book/chapter exists
log.debug( "got chapter %s", c)
if not c:
bookid = self.booksOfBible[bookname] # convert to id ie Genesis --> 1 Revelation --> 73
log.debug( "missing %s,%s", bookname, chptr)
self._loadBook(biblename,bookid, bookname, bookabbrev)
self._loadChapter(biblename,bookid, bookname, chptr)
# def loadBible(self,biblename):
# """
# Downloads all the books of the bible
# and loads it into the database
# """
# log.debug( "loadBible %s", biblename)
# bookabbrev = ""
# for bookname in self.listOfBooks:
# cptrs = self.booksChapters[ self.booksOfBible[bookname]]
# log.debug( "book and chapter %s %s", bookname , self.booksChapters[ self.booksOfBible[bookname]] )
# for chptr in range(1 , int(cptrs)): # loop through all the chapters in book
# c = self.bibleDBCache[biblename].getBibleChapter(bookname, chptr) # check to see if book/chapter exists
# log.debug( "got chapter %s", c)
# if not c:
# bookid = self.booksOfBible[bookname] # convert to id ie Genesis --> 1 Revelation --> 73
# log.debug( "missing %s,%s", bookname, chptr)
# self._loadBook(biblename,bookid, bookname, bookabbrev)
# self._loadChapter(biblename,bookid, bookname, chptr)
def get_bibles(self, mode="full"):
"""
@ -151,50 +151,50 @@ class BibleManager():
r.append(b)
return r
def get_bible_books_full(self,bible):
def get_bible_books(self,bible):
"""
Returns a list of the books of the bible from the database
"""
log.debug("getbibleBooks %s", bible)
return self.bibleDBCache[bible].getBibleBooks()
log.debug("get_bible_books %s", bible)
return self.bibleDBCache[bible].get_bible_books()
def get_book_chapter_count(self, bible, book):
"""
Returns the number of Chapters for a given book
"""
log.debug( "getBookChapterCount %s,%s", bible, book)
return self.bibleDBCache[bible].getMaxBibleBookChapters(book)
log.debug( "get_book_chapter_count %s,%s", bible, book)
return self.bibleDBCache[bible].get_max_bible_book_chapter(book)
def get_book_verse_count(self, bible, book, chapter):
"""
Returns all the number of verses for a given
book and chapterMaxBibleBookVerses
"""
log.debug( "getBookVerseCount %s,%s,%s", bible, book, chapter)
return self.bibleDBCache[bible].getMaxBibleBookVerses(book, chapter)
log.debug( "get_book_verse_count %s,%s,%s", bible, book, chapter)
return self.bibleDBCache[bible].get_max_bible_book_verses(book, chapter)
def get_verse_from_text(self, bible, versetext):
"""
Returns all the number of verses for a given
book and chapterMaxBibleBookVerses
"""
log.debug( "getVersesFromText %s,%s", bible, versetext)
return self.bibleDBCache[bible].getVersesFromText(versetext)
log.debug( "get_verses_from_text %s,%s", bible, versetext)
return self.bibleDBCache[bible].get_verses_from_text(versetext)
def save_meta_data(self, bible, version, copyright, permissions):
"""
Saves the bibles meta data
"""
log.debug( "saveMetaData %s,%s, %s,%s", bible, version, copyright, permissions)
self.bibleDBCache[bible].saveMeta("Version", version)
self.bibleDBCache[bible].saveMeta("Copyright", copyright)
self.bibleDBCache[bible].saveMeta("Permissins", permissions)
log.debug( "save_meta %s,%s, %s,%s", bible, version, copyright, permissions)
self.bibleDBCache[bible].save_meta("Version", version)
self.bibleDBCache[bible].save_meta("Copyright", copyright)
self.bibleDBCache[bible].save_meta("Permissins", permissions)
def getMetaData(self, bible, key):
def get_meta_data(self, bible, key):
"""
Returns the meta data for a given key
"""
log.debug( "getMetaData %s,%s", bible, key)
log.debug( "get_meta %s,%s", bible, key)
self.bibleDBCache[bible].getMeta(key)
def get_verse_text(self, bible, bookname, chapter, sverse, everse = 0 ):
@ -224,22 +224,22 @@ class BibleManager():
#self.bibleDBCache[bible].dumpBible()
return text
def _loadBook(self, bible, bookid, bookname, bookabbrev):
log.debug( "loadbook %s,%s,%s,%s", bible, bookid, bookname, bookabbrev)
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)
log.debug( "get bible book %s" , cl)
if not cl :
self.bibleDBCache[bible].createBook(bookid, bookname, bookabbrev)
def _loadChapter(self, bible, bookid, bookname, chapter):
log.debug( "loadChapter %s,%s,%s,%s", 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)
except :
log.error("Errow thrown %s", sys.exc_info()[1])
def _isNewBible(self, name):
def _is_new_bible(self, name):
"""
Check cache to see if new bible
"""