Move and update bible manager and associated classes

bzr-revno: 60
This commit is contained in:
Tim Bentley 2008-10-30 20:44:54 +00:00
parent fd05e8c6fe
commit d0fb086b77
11 changed files with 638 additions and 0 deletions

View File

@ -0,0 +1,217 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os, os.path
import sys
import time
import datetime
import logging
import string
from sqlalchemy import *
from sqlalchemy.sql import select
from sqlalchemy.orm import sessionmaker, mapper
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..', '..')))
from openlp.utils import ConfigHelper
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
metadata = MetaData()
#Define the tables and indexes
meta_table = Table('meta', metadata,
Column('key', String(255), primary_key=True),
Column('value', String(255)),
)
testament_table = Table('testament', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(30)),
)
book_table = Table('book', metadata,
Column('id', Integer, primary_key=True),
Column('testament_id', None , ForeignKey('testament.id')),
Column('name', String(30)),
Column('abbrev', String(30)),
)
Index('idx_name', book_table.c.name, book_table.c.id)
Index('idx_abbrev', book_table.c.abbrev, book_table.c.id)
verse_table = Table('verse', metadata,
Column('id', Integer, primary_key=True),
Column('book_id', None, ForeignKey('book.id')),
Column('chapter', Integer),
Column('verse', Integer),
Column('text', Text),
)
Index('idx_chapter_verse_book', verse_table.c.chapter, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id)
class BibleMeta(object):
def __init__(self, key, value):
self.key = key
self.value =value
def __repr__(self):
return "<biblemeta('%s','%s')>" %(self.key, self.value)
class ONTestament(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return "<testament('%s')>" %(self.name)
class Book(object):
def __init__(self, testament_id, name, abbrev):
self.testament_id = testament_id
self.name = name
self.abbrev = abbrev
def __repr__(self):
return "<book('%s','%s','%s','%s')>" %(self.id, self.testament_id, self.name, self.abbrev)
class Verse(object):
def __init__(self, book_id, chapter, verse, text):
self.book_id = book_id
self.chapter = chapter
self.verse = verse
self.text = text
def __repr__(self):
return "<verse('%s','%s','%s','%s')>" %(self.book_id, self.chapter, self.verse, self.text)
mapper(BibleMeta, meta_table)
mapper(ONTestament, testament_table)
mapper(Book, book_table)
mapper(Verse, verse_table)
class BibleDBImpl:
def __init__(self, biblename):
# Connect to database
path = ConfigHelper.getBiblePath()
#print path
#print biblename
self.biblefile = os.path.join(path, biblename+".bible")
#print self.biblefile
self.db = create_engine("sqlite:///"+self.biblefile)
self.db.echo = False
#self.metadata = metaData()
metadata.bind = self.db
metadata.bind.echo = False
self.Session = sessionmaker()
self.Session.configure(bind=self.db)
self.book_ptr = ""
def createTables(self):
if os.path.exists(self.biblefile): # delete bible file and set it up again
os.remove(self.biblefile)
meta_table.create()
testament_table.create()
book_table.create()
verse_table.create()
self.loadMeta("dbversion", "0.1")
def loadVerse(self, book, chapter, verse, text):
metadata.bind.echo = True
session = self.Session()
if self.book_ptr is not book:
query = session.query(Book).filter(Book.name==book)
#print query.first().id
self.book_ptr = book
#print text
versemeta = Verse(book_id=query.first().id, chapter=int(chapter), verse=int(verse), text=(text))
session.add(versemeta)
session.commit()
def loadMeta(self, key, value):
session = self.Session()
bmeta= BibleMeta(key, value)
session.add(bmeta)
session.commit()
def loadData(self, booksfile, versesfile):
self.loadMeta("version", "Bible Version")
self.loadMeta("Copyright", "(c) Some Bible company")
self.loadMeta("Permission", "You Have Some")
session = self.Session()
#Populate the Tables
testmeta = ONTestament(name="Old Testament")
session.add(testmeta)
testmeta = ONTestament(name="New Testament")
session.add(testmeta)
session.commit()
fbooks=open(booksfile, 'r')
fverse=open(versesfile, 'r')
for line in fbooks:
#print line
p = line.split(",")
p[2] = self._cleanText(p[2])
p[3] = self._cleanText(p[3])
bookmeta = Book(int(p[1]), p[2], p[3])
session.add(bookmeta)
session.commit()
for line in fverse:
#print line
p = line.split(",", 3) # split into 3 units and leave the rest as a single field
p[0] = self._cleanText(p[0])
p[3] = self._cleanText(p[3])
self.loadVerse(p[0], p[1], p[2], p[3])
session.commit()
def getBibleChapter(self, bookname, chapter):
s = text (""" select text 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):
metadata.bind.echo = True
s = text (""" select 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 _cleanText(self, text):
text = text.replace('\n', '')
text = text.replace('\r', '')
text = text.replace('"', '')
return text
def Run_Tests(self):
metadata.bind.echo = True
print "test print"
session = self.Session()
print session.query(Book).filter(Book.name=='John').all()
q = session.query(Verse).filter(Verse.book_id==8)
print q.first()
q = session.query(Verse, Book).filter(Verse.chapter==1).filter(Verse.verse==1).filter(Book.name=='Genesis')
print "--"
#print q.first()[0].text
#print q.first()[1].name
#print "----"
ch =1
vs = 1
bk = 'Genesis'
s = text (""" select text FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and verse.verse == :v and book.name == :b """)
print self.db.execute(s, c=ch, v=vs , b=bk).fetchall()

View File

@ -0,0 +1,88 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os, os.path
import sys
import urllib2
class BibleHTTPImpl:
def __init__(self):
"""
Finds all the bibles defined for the system
Creates an Interface Object for each bible containing connection information
Throws Exception if no Bibles are found.
Init confirms the bible exists and stores the database path.
"""
bible = {}
def getBibleChapter(self, version, book, chapter):
urlstring = "http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word="+book+"+"+str(chapter)+"&version="+version
print urlstring
xml_string = ""
req = urllib2.Request(urlstring)
req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
try:
handle = urllib2.urlopen(req)
xml_string = handle.read()
except IOError, e:
if hasattr(e, 'reason'):
print 'Reason : '
print e.reason
i= xml_string.find("NavCurrentChapter")
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<TABLE")
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<B>")
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
i= xml_string.find("<B>") # Remove the heading for the book
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
versePos = xml_string.find("<BLOCKQUOTE>")
#print versePos
bible = {}
cleanbible = {}
while versePos > 0:
versePos = xml_string.find("<B><I>", versePos) + 6
i = xml_string.find("</I></B>", versePos)
#print versePos, i
verse= xml_string[versePos:i] # Got the Chapter
#verse = int(temp)
#print "Chapter = " + str(temp)
versePos = i + 8 # move the starting position to negining of the text
i = xml_string.find("<B><I>", versePos) # fine the start of the next verse
if i == -1:
i = xml_string.find("</BLOCKQUOTE>",versePos)
verseText = xml_string[versePos: i]
versePos = 0
else:
#print i, versePos
verseText = xml_string[versePos: i]
versePos = i
bible[verse] = self._cleanVerse(verseText)
#print bible
return bible
def _cleanVerse(self, text):
text = text.replace('\n', '')
text = text.replace('\r', '')
text = text.replace('&nbsp;', '')
text = text.replace('<P>', '')
text = text.replace('"', '')
return text.rstrip()

View File

@ -0,0 +1,126 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os, os.path
import sys
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..', '..')))
from openlp.utils import ConfigHelper
from openlp.plugins.biblemanager.BibleDBImpl import *
from openlp.plugins.biblemanager.BibleHTTPImpl import *
class BibleManager:
def __init__(self):
"""
Finds all the bibles defined for the system
Creates an Interface Object for each bible containing connection information
Throws Exception if no Bibles are found.
Init confirms the bible exists and stores the database path.
"""
self.bibleDBCache = {}
self.bibleHTTPCache = {}
self.biblePath = ConfigHelper.getBiblePath()
#print self.biblePath
files = os.listdir(self.biblePath)
for f in files:
b = f.split('.')[0]
self.bibleDBCache[b] = BibleDBImpl(b)
print self.bibleDBCache
print self.bibleHTTPCache
def registerHTTPBible(self, name, biblesource, proxy, proxyport, proxyid, proxypass):
"""
Return a list of bibles from a given URL.
The selected Bible can then be registered and LazyLoaded into a database
"""
if self._isNewBible(name):
nbible = BibleDBImpl(name) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[name] = nbible
nhttp = BibleHTTPImpl()
self.bibleHTTPCache[name] = nhttp
nbible.loadMeta("WEB", biblesource)
def registerBible(self, name, 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(name):
nbible = BibleDBImpl(name) # Create new Bible
nbible.createTables() # Create Database
nbible.loadData(booksfile, versefile)
self.bibleDBCache[name] = nbible
def getBibles(self):
"""
Returns a list of Books of the bible
"""
r=[]
for b , o in self.bibleDBCache.iteritems():
r.append(b)
return r
def getBibleBooks(self,bible):
"""
Returns a list of the books of the bible
"""
return ["Gen","Exd","Matt","Mark"]
def getBookVerseCount(self, bible, book, chapter):
"""
Returns all the number of verses for a given
book and chapter
"""
return 28
def getVerseText(self, bible, book, chapter, 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)
then only one verse is returned
"""
print self.bibleDBCache
print self.bibleHTTPCache
c = self.bibleDBCache[bible].getBibleChapter(book, chapter) # check to see if book/chapter exists
if not c:
self._loadChapter(bible, book, chapter)
if everse < sverse:
everse = sverse
text = self.bibleDBCache[bible].getBibleText(book, chapter, sverse, everse)
print text
return text
def _loadChapter(self, bible, book, chapter):
cl = self.bibleHTTPCache[bible].getBibleChapter(bible, book, chapter)
for v , t in cl.iteritems():
#self.bibleDBCache[bible].loadVerse(book, chapter, v, t)
print v , t
def _isNewBible(self, name):
"""
Check cache to see if new bible
"""
for b , o in self.bibleDBCache.iteritems():
print b
if b == name :
return False
return True

View File

@ -0,0 +1,18 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""

View File

@ -0,0 +1,18 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""

View File

@ -0,0 +1,8 @@
1,1,"Genesis","GEN"
2,1,"Exodus","EXOD"
3,1,"Leviticus","LEV"
4,1,"Numbers","NUM"
47,2,"Matthew","MATT"
48,2,"Mark","MARK"
49,2,"Luke","LUKE"
50,2,"John","JOHN"
1 1 1 Genesis GEN
2 2 1 Exodus EXOD
3 3 1 Leviticus LEV
4 4 1 Numbers NUM
5 47 2 Matthew MATT
6 48 2 Mark MARK
7 49 2 Luke LUKE
8 50 2 John JOHN

View File

@ -0,0 +1,9 @@
1,1,"Genesis","GEN"
2,1,"Exodus","EXOD"
3,1,"Leviticus","LEV"
4,1,"Numbers","NUM"
46,1,"Malachi","MAL"
47,2,"Matthew","MATT"
48,2,"Mark","MARK"
49,2,"Luke","LUKE"
50,2,"John","JOHN"
1 1 1 Genesis GEN
2 2 1 Exodus EXOD
3 3 1 Leviticus LEV
4 4 1 Numbers NUM
5 46 1 Malachi MAL
6 47 2 Matthew MATT
7 48 2 Mark MARK
8 49 2 Luke LUKE
9 50 2 John JOHN

View File

@ -0,0 +1,35 @@
"Genesis",1,1,"First this: God created the Heavens and Earth - all you see, all you don't see."
"Genesis",1,2,"Earth was a soup of nothingness, a bottomless emptiness, an inky blackness. God's Spirit brooded like a bird above the watery abyss."
"Exodus",1,1,"These are the names of the Israelites who went to Egypt with Jacob, each bringing his family members:"
"Exodus",1,2,"Reuben, Simeon, Levi, and Judah,"
"Exodus",2,1,"A man from the family of Levi married a Levite woman."
"Exodus",2,2,"The woman became pregnant and had a son. She saw there was something special about him and hid him. She hid him for three months."
"Leviticus",1,1,"God called Moses and spoke to him from the Tent of Meeting:"
"Leviticus",1,2,"""Speak to the People of Israel. Tell them, When anyone presents an offering to God, present an animal from either the herd or the flock."
"Leviticus",1,3,"""If the offering is a Whole-Burnt-Offering from the herd, present a male without a defect at the entrance to the Tent of Meeting that it may be accepted by God."
"Numbers",1,1,"God spoke to Moses in the Wilderness of Sinai at the Tent of Meeting on the first day of the second month in the second year after they had left Egypt. He said,"
"Numbers",1,2,"""Number the congregation of the People of Israel by clans and families, writing down the names of every male."
"Matthew",1,1,"The family tree of Jesus Christ, David's son, Abraham's son:"
"Matthew",1,2,"Abraham had Isaac, Isaac had Jacob, Jacob had Judah and his brothers,"
"Matthew",1,3,"Judah had Perez and Zerah (the mother was Tamar), Perez had Hezron, Hezron had Aram,"
"Matthew",1,4,"Aram had Amminadab, Amminadab had Nahshon, Nahshon had Salmon,"
"Matthew",1,5,"Salmon had Boaz (his mother was Rahab), Boaz had Obed (Ruth was the mother), Obed had Jesse,"
"Matthew",1,6,"Jesse had David, and David became king. David had Solomon (Uriah's wife was the mother),"
"Matthew",1,7,"Solomon had Rehoboam, Rehoboam had Abijah, Abijah had Asa,"
"Matthew",1,8,"Asa had Jehoshaphat, Jehoshaphat had Joram, Joram had Uzziah,"
"Matthew",2,1,"After Jesus was born in Bethlehem village, Judah territory - this was during Herod's kingship - a band of scholars arrived in Jerusalem from the East."
"Matthew",2,2,"They asked around, ""Where can we find and pay homage to the newborn King of the Jews? We observed a star in the eastern sky that "Matthew",3,1,"While Jesus was living in the Galilean hills, John, called ""the Baptizer,"" was preaching in the desert country of Judea."
"Matthew",3,2,"His message was simple and austere, like his desert surroundings: ""Change your life. God's kingdom is here."""
"Matthew",3,3,"John and his message were authorized by Isaiah's prophecy: Thunder in the desert! Prepare for God's arrival! Make the road smooth and straight!"
"Mark",1,1,"The good news of Jesus Christ - the Message! - begins here,"
"Mark",1,2,"following to the letter the scroll of the prophet Isaiah. Watch closely: I'm sending my preacher ahead of you; He'll make the road smooth for you."
"Mark",1,3,"Thunder in the desert! Prepare for God's arrival! Make the road smooth and straight!"
"Luke",1,1,"So many others have tried their hand at putting together a story of the wonderful harvest of Scripture and history that took place among us,"
"Luke",1,2,"using reports handed down by the original eyewitnesses who served this Word with their very lives."
"Luke",1,3,"Since I have investigated all the reports in close detail, starting from the story's beginning, I decided to write it all out for you, most honorable Theophilus,"
"John",1,1,"The Word was first, the Word present to God, God present to the Word. The Word was God,"
"John",1,2,"in readiness for God from day one."
"John",1,3,"Everything was created through him; nothing - not one thing! - came into being without him."
"John",2,1,"Three days later there was a wedding in the village of Cana in Galilee. Jesus' mother was there."
"John",2,2,"Jesus and his disciples were guests also."
"John",2,3,"When they started running low on wine at the wedding banquet, Jesus' mother told him, ""They're just about out of wine."""
Can't render this file because it contains an unexpected character in line 21 and column 146.

View File

@ -0,0 +1,35 @@
"Genesis",1,1,"In the beginning God created the heavens and the earth."
"Genesis",1,2,"Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters."
"Exodus",1,1,"These are the names of the sons of Israel who went to Egypt with Jacob, each with his family:"
"Exodus",1,2,"Reuben, Simeon, Levi and Judah;"
"Exodus",2,1,"Now a man of the house of Levi married a Levite woman,"
"Exodus",2,2,"and she became pregnant and gave birth to a son. When she saw that he was a fine child, she hid him for three months."
"Leviticus",1,1,"The Lord called to Moses and spoke to him from the Tent of Meeting. He said,"
"Leviticus",1,2,"""Speak to the Israelites and say to them: 'When any of you brings an offering to the Lord, bring as your offering an animal from either the herd or the flock."
"Leviticus",1,3,"""'If the offering is a burnt offering from the herd, he is to offer a male without defect. He must present it at the entrance to the Tent of Meeting so that it will be acceptable to the Lord."
"Numbers",1,1,"The Lord spoke to Moses in the Tent of Meeting in the Desert of Sinai on the first day of the second month of the second year after the Israelites came out of Egypt. He said:"
"Numbers",1,2,"""Take a census of the whole Israelite community by their clans and families, listing every man by name, one by one."
"Matthew",1,1,"A record of the genealogy of Jesus Christ the son of David, the son of Abraham:"
"Matthew",1,2,"Abraham was the father of Isaac,"
"Matthew",1,3,"Judah the father of Perez and Zerah, whose mother was Tamar,"
"Matthew",1,4,"Ram the father of Amminadab,"
"Matthew",1,5,"Salmon the father of Boaz, whose mother was Rahab,"
"Matthew",1,6,"and Jesse the father of King David."
"Matthew",1,7,"Solomon the father of Rehoboam,"
"Matthew",1,8,"Asa the father of Jehoshaphat,"
"Matthew",2,1,"After Jesus was born in Bethlehem in Judea, during the time of King Herod, Magi from the east came to Jerusalem"
"Matthew",2,2,"and asked, ""Where is the one who has been born king of the Jews? We saw his star in the east and have come to worship "Matthew",3,1,"In those days John the Baptist came, preaching in the Desert of Judea"
"Matthew",3,2,"and saying, ""Repent, for the kingdom of heaven is near."""
"Matthew",3,3,"This is he who was spoken of through the prophet Isaiah: ""A voice of one calling in the desert, 'Prepare the way for the Lord, make straight paths for him.'"""
"Mark",1,1,"The beginning of the gospel about Jesus Christ, the Son of God."
"Mark",1,2,"It is written in Isaiah the prophet: ""I will send my messenger ahead of you, who will prepare your way""--"
"Mark",1,3,"""a voice of one calling in the desert, 'Prepare the way for the Lord, make straight paths for him.'"""
"Luke",1,1,"Many have undertaken to draw up an account of the things that have been fulfilled among us,"
"Luke",1,2,"just as they were handed down to us by those who from the first were eyewitnesses and servants of the word."
"Luke",1,3,"Therefore, since I myself have carefully investigated everything from the beginning, it seemed good also to me to write an orderly account for you, most excellent Theophilus,"
"John",1,1,"In the beginning was the Word, and the Word was with God, and the Word was God."
"John",1,2,"He was with God in the beginning."
"John",1,3,"Through him all things were made; without him nothing was made that has been made."
"John",2,1,"On the third day a wedding took place at Cana in Galilee. Jesus' mother was there,"
"John",2,2,"and Jesus and his disciples had also been invited to the wedding."
"John",2,3,"When the wine was gone, Jesus' mother said to him, ""They have no more wine."""
Can't render this file because it contains an unexpected character in line 21 and column 135.

View File

@ -0,0 +1 @@
py.test --nocapture test_bibleManager.py

View File

@ -0,0 +1,83 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import random
import unittest
import os, os.path
import sys
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..','..','..')))
from openlp.plugins.biblemanager.BibleManager import BibleManager
from openlp.utils import ConfigHelper
class TestBibleManager:
def setup_class(self):
print "\nRegister BM"
self.bm = BibleManager()
def testRegisterBibleFiles(self):
# Register a bible from files
print "testRegisterBibleFiles"
self.bm.registerBible("TheMessage",'biblebooks_msg_short.csv','bibleverses_msg_short.csv')
self.bm.registerBible("NIV",'biblebooks_niv_short.csv','bibleverses_niv_short.csv')
b = self.bm.getBibles()
for b1 in b:
print b1
assert(b1 in b)
def testRegisterBibleHTTP(self):
# Register a bible from files
print "testRegisterBibleHTTP"
self.bm.registerHTTPBible("asv","Crosswalk", "", "", "", "")
#self.bm.registerBible("NIV", "ge", 1)
b = self.bm.getBibles()
for b1 in b:
print b1
assert(b1 in b)
def testGetBibles(self):
print "testGetBibles"
# make sure the shuffled sequence does not lose any elements
b = self.bm.getBibles()
for b1 in b:
print b1
assert(b1 in b)
def testGetBooks(self):
print "testGetBooks"
c = self.bm.getBibleBooks("NIV")
for c1 in c:
print c1
assert(c1 in c)
def testGetVerseCount(self):
print "testGetVerseCount"
assert(self.bm.getBookVerseCount("NIV", "GEN", 1) == 28, "Wrong Book Count")
def testGetVerseText(self):
print "testGetVerseText"
c = self.bm.getVerseText("TheMessage",'Genesis',1,2, 1)
print c
c = self.bm.getVerseText('NIV','Genesis',1,1,2)
print c
c = self.bm.getVerseText('asv','re',1,1,2)
print c