Add ability to load OSIS xml bibles exported from Sword bible reader

bzr-revno: 99
This commit is contained in:
Tim Bentley 2008-11-19 18:13:22 +00:00
parent ca5eed490d
commit a067f0b34a
5 changed files with 173 additions and 8 deletions

View File

@ -25,6 +25,7 @@ from openlp.utils import ConfigHelper
from openlp.plugins.biblemanager.BibleDBImpl import BibleDBImpl
from openlp.plugins.biblemanager.BibleHTTPImpl import BibleHTTPImpl
from openlp.plugins.biblemanager.BibleCSVImpl import BibleCSVImpl
from openlp.plugins.biblemanager.BibleOSISImpl import BibleOSISImpl
from openlp.plugins.plugin import Plugin
import logging
@ -115,7 +116,7 @@ class BibleManager(Plugin):
nbible.saveMeta("proxypass", proxypass) # store the proxy password
def registerFileBible(self, biblename, booksfile, versefile, filetype):
def registerCVSFileBible(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
@ -126,8 +127,20 @@ class BibleManager(Plugin):
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
if filetype == "csv":
bcsv.loadData(booksfile, versefile)
bcsv.loadData(booksfile, versefile)
def registerOSISFileBible(self, biblename, osisfile):
"""
Method to load a bible from a osis xml file extracted from Sword bible viewer.
If the database exists it is deleted and the database is reloaded
from scratch.
"""
if self._isNewBible(biblename):
nbible = BibleDBImpl(biblename) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later
bcsv = BibleOSISImpl(nbible) # create the loader and pass in the database
bcsv.loadData(osisfile)
def loadBible(self,biblename):

View File

@ -0,0 +1,92 @@
"""
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
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..', '..')))
from openlp.plugins.biblemanager.BibleDBImpl import BibleDBImpl
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='plugins.log',
filemode='w')
class BibleOSISImpl():
global log
log=logging.getLogger("BibleOSISImpl")
log.info("BibleOSISImpl loaded")
def __init__(self, bibledb):
self.bibledb = bibledb
def loadData(self, osisfile):
self.bibledb.saveMeta("version", "Bible Version")
self.bibledb.saveMeta("Copyright", "(c) Some Bible company")
self.bibledb.saveMeta("Permission", "You Have Some")
osis=open(osisfile, 'r')
book_ptr = ""
id = 0
verseText = "<verse osisID="
for f in osis.readlines():
#print f
s = f.find(verseText)
if s > -1: # we have a verse
e= f.find(">", s)
ref = f[s+15:e-1] # Book Reference
#lets find the bble text
s = e + 1 # find start of text
e = f.find("</verse>", s) # end of text
t = f[s:e]
#print s, e, f[s:e] # Found Basic Text
#remove tags of extra information
s = t.find("<FI>")
while s > -1:
e = t.find("<Fi>", s)
if e == -1: # TODO
#print "Y", s, e
s = -1
else:
t = t[:s] + t[e + 4: ]
s = t.find("<FI>")
s = t.find("<RF>")
while s > -1:
e = t.find("<Rf>", s)
t = t[:s] + t[e + 4: ]
#print "X", s, e, t
s = t.find("<RF>")
p = ref.split(".", 3) # split u[ the reference
if book_ptr != p[0]:
book_ptr = p[0]
print p
self.bibledb.createBook(int(p[1]), p[0], p[0])
id = self.bibledb.getBibleBookId(p[0])
self.bibledb.addVerse(id[0], p[1], p[2], t)

View File

@ -60,7 +60,7 @@ class TestBibleManager:
def testGetBibleBooks(self):
log.debug( "\n.......testGetBibleBooks")
c = self.bm.getBibleBooks("NIV")
c = self.bm.getBibleBooks("asv")
for c1 in c:
log.debug( c1)
assert(c1 in c)
@ -84,8 +84,8 @@ class TestBibleManager:
#log.debug( c )
c = self.bm.getVerseText('asv','Genesis',10,1,20)
log.debug( c )
c = self.bm.getVerseText('nasb','Genesis',10,1,20)
c = self.bm.getVerseText('asv','Genesis',10,1,20)
log.debug( c )
c = self.bm.getVerseText('nkj','Revelation',10,1,20)
c = self.bm.getVerseText('asv','Revelation',10,1,20)
log.debug( c )

View File

@ -53,8 +53,8 @@ class TestBibleManager:
def testRegisterCSVBibleFiles(self):
# Register a bible from files
log.debug("\n.......testRegisterBibleFiles")
self.bm.registerFileBible("TheMessage",'biblebooks_msg_short.csv','bibleverses_msg_short.csv', "csv")
self.bm.registerFileBible("NIV",'biblebooks_niv_short.csv','bibleverses_niv_short.csv', "csv")
self.bm.registerCSVFileBible("TheMessage",'biblebooks_msg_short.csv','bibleverses_msg_short.csv')
self.bm.registerCSVFileBible("NIV",'biblebooks_niv_short.csv','bibleverses_niv_short.csv')
b = self.bm.getBibles()
for b1 in b:
log.debug( b1)

View File

@ -0,0 +1,60 @@
"""
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
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='plugins.log',
filemode='w')
console=logging.StreamHandler()
# set a format which is simpler for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
log=logging.getLogger('')
logging.info("\nLogging started")
class TestBibleManager:
log=logging.getLogger("testBibleMgr")
def setup_class(self):
log.debug("\n.......Register BM")
self.bm = BibleManager()
def testRegisterOSISBibleFiles(self):
# Register a bible from files
log.debug("\n.......testRegisterOSISBibleFiles")
self.bm.registerOSISFileBible("asv",'asv.osis')
b = self.bm.getBibles()
for b1 in b:
log.debug( b1)
assert(b1 in b)