Fix up bibles and sort out path issues in code

Load bible names into plugin
Handle no bible names if directory is empty

bzr-revno: 192
This commit is contained in:
Tim Bentley 2008-12-06 09:33:46 +00:00
parent 908418bb1a
commit 3450e1ac50
13 changed files with 155 additions and 94 deletions

View File

@ -67,6 +67,7 @@ class PluginManager(object):
__import__(modulename, globals(), locals(), [])
except ImportError, e:
print e.message
log.error("Failed to import module %s on path %s for reason %s", modulename, path, e.message)
self.plugin_classes = Plugin.__subclasses__()
self.plugins = []
plugin_objects = []

View File

@ -24,7 +24,7 @@ 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.plugins.bibles.lib.biblemanager import BibleManager
from openlp.utils import ConfigHelper
import logging

View File

@ -24,7 +24,7 @@ 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.plugins.bibles.lib.biblemanager import BibleManager
from openlp.utils import ConfigHelper
import logging

View File

@ -24,7 +24,7 @@ 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.plugins.bibles.lib.biblemanager import BibleManager
from openlp.utils import ConfigHelper
import logging

View File

@ -22,8 +22,8 @@ from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib import Plugin, MediaManagerItem
from lib.biblemanager import BibleManager
from forms.bibleimportform import BibleImportForm
from openlp.plugins.bibles.lib.biblemanager import BibleManager
from openlp.plugins.bibles.forms.bibleimportform import BibleImportForm
class BiblePlugin(Plugin):
def __init__(self):
@ -156,30 +156,13 @@ class BiblePlugin(Plugin):
# Add the search tab widget to the page layout
self.MediaManagerItem.PageLayout.addWidget(self.SearchTabWidget)
self.QuickVersionComboBox.addItem("NIV")
self.QuickVersionComboBox.addItem("KJC")
self.AdvancedVersionComboBox.addItem("NIV")
self.AdvancedVersionComboBox.addItem("KJC")
self.AdvancedBookComboBox.addItem("Genesis")
self.AdvancedBookComboBox.addItem("Matthew")
self.AdvancedBookComboBox.addItem("Revelation")
for i in range(1, 10):
self.AdvancedFromChapter.addItem(str(i))
for i in range(1, 20):
self.AdvancedToChapter.addItem(str(i))
for i in range(1, 30):
self.AdvancedFromVerse.addItem(str(i))
for i in range(1, 40):
self.AdvancedToVerse.addItem(str(i))
self.listView = QtGui.QListView()
self.listView.setGeometry(QtCore.QRect(10, 200, 256, 391))
self.listView.setObjectName("listView")
self.MediaManagerItem.PageLayout.addWidget(self.listView)
#self.textsearchmode()
self._initialiseform()
return self.MediaManagerItem
def onBibleNewClick(self):
@ -196,46 +179,22 @@ class BiblePlugin(Plugin):
def onBibleAddClick(self):
pass
def onBibleSearchClick(self):
#if self.textsearch == True:
# print "Text / Verse Search"
#else:
# print "Combo Search"
pass
def _initialiseform(self):
bibles = self.biblemanager.getBibles()
for b in bibles:
self.QuickVersionComboBox.addItem(b)
self.AdvancedVersionComboBox.addItem(b)
self.AdvancedBookComboBox.addItem("Genesis")
self.AdvancedBookComboBox.addItem("Matthew")
self.AdvancedBookComboBox.addItem("Revelation")
def onBibleSearchChangeClick(self):
#self.textsearchmode()
pass
def textsearchmode(self):
"""if self.textsearch == True:
self.textsearch = False
self.searchcomboBox.hide()
self.searchEdit.hide()
self.booklabel.show()
self.bookcomboBox.show()
self.fromcomboBox_c.show()
self.fromcomboBox_v.show()
self.tocomboBox_c.show()
self.tocomboBox_v.show()
self.chapterlabel.show()
self.verselabel.show()
self.fromlabel.show()
self.tolabel.show()
else:
self.textsearch = True
self.searchcomboBox.show()
self.searchEdit.show()
self.booklabel.hide()
self.bookcomboBox.hide()
self.fromcomboBox_c.hide()
self.fromcomboBox_v.hide()
self.tocomboBox_c.hide()
self.tocomboBox_v.hide()
self.chapterlabel.hide()
self.verselabel.hide()
self.fromlabel.hide()
self.tolabel.hide()"""
pass
for i in range(1, 10):
self.AdvancedFromChapter.addItem(str(i))
for i in range(1, 20):
self.AdvancedToChapter.addItem(str(i))
for i in range(1, 30):
self.AdvancedFromVerse.addItem(str(i))
for i in range(1, 40):
self.AdvancedToVerse.addItem(str(i))

View File

@ -18,7 +18,7 @@ from PyQt4.QtCore import pyqtSignature
from bibleimportdialog import Ui_BibleImportDialog
from bibleimportprogressform import BibleImportProgressForm
from openlp.plugins.biblemanager.bibleManager import BibleManager
from openlp.plugins.bibles.lib.biblemanager import BibleManager
class BibleImportForm(QDialog, Ui_BibleImportDialog):
"""
@ -30,7 +30,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog):
"""
QDialog.__init__(self, parent)
self.setupUi(self)
self.biblemanager = biblemanager
#self.biblemanager = biblemanager
# self.savebutton = self.BibleImportButtonBox.button(QtGui.QDialogButtonBox.Save)
# self.BibleImportButtonBox.removeButton(self.savebutton) # hide the save button tile screen is valid

View File

@ -16,7 +16,7 @@ from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature
from bibleimportprogressdialog import Ui_BibleImportProgressDialog
from openlp.plugins.biblemanager.bibleManager import BibleManager
from openlp.plugins.bibles.lib.biblemanager import BibleManager
class BibleImportProgressForm(QDialog, Ui_BibleImportProgressDialog):
"""

View File

@ -21,8 +21,8 @@ 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
from openlp.plugins.biblemanager.bibleCommon import BibleCommon
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
from openlp.plugins.bibles.lib.biblecommon import BibleCommon
import logging
logging.basicConfig(level=logging.DEBUG,

View File

@ -28,7 +28,7 @@ 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.plugins.biblemanager.bibleCommon import BibleCommon
from openlp.plugins.bibles.lib.biblecommon import BibleCommon
from openlp.core.utils import ConfigHelper
import logging
@ -42,7 +42,6 @@ class BibleDBException(Exception):
class BibleInvalidDatabaseError(Exception):
pass
metadata = MetaData()
#Define the tables and indexes
meta_table = Table('metadata', metadata,
@ -118,14 +117,10 @@ class BibleDBImpl(BibleCommon):
global log
log=logging.getLogger("BibleDBMgr")
log.info("BibleDB manager loaded")
def __init__(self, biblename, btype = 'sqlite'):
def __init__(self, biblepath , biblename, suffix, btype = 'sqlite'):
# Connect to database
path = "/home/timali/.openlp.org/Data/Bibles"
#log.debug( path
#log.debug( biblename
self.biblefile = os.path.join(path, biblename+".bible3")
#log.debug( self.biblefile
#log.debug( btype
self.biblefile = os.path.join(biblepath, biblename+"."+suffix)
log.debug( "Load bible %s on path %s", biblename, self.biblefile)
if btype == 'sqlite':
self.db = create_engine("sqlite:///"+self.biblefile)
elif btype == 'mysql':

View File

@ -22,7 +22,7 @@ import urllib2
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..', '..')))
from openlp.plugins.biblemanager.bibleCommon import BibleCommon
from openlp.plugins.bibles.lib.biblecommon import BibleCommon
import logging
logging.basicConfig(level=logging.DEBUG,

View File

@ -21,7 +21,7 @@ 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
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
import logging
logging.basicConfig(level=logging.DEBUG,

View File

@ -0,0 +1,104 @@
"""
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
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 BibleCommon:
global log
log=logging.getLogger("BibleCommon")
log.info("BibleCommon")
def __init__(self):
"""
"""
def _getWebText(self, urlstring, proxyurl):
log.debug( "getWebText %s %s", proxyurl, urlstring)
if proxyurl != "" or len(proxyurl) > 0 :
print "ProxyUrl " , proxyurl + " " + str(len(proxyurl))
proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
http_support = urllib2.HTTPHandler()
opener= urllib2.build_opener(proxy_support, http_support)
urllib2.install_opener(opener)
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'):
log.error( 'Reason : ')
log.error( e.reason)
return xml_string
def _cleanText(self, text):
"""
Clean up text and remove extra characters
after been downloaded from web
"""
#return text.rstrip()
# Remove Headings from the Text
i = text.find("<h")
while i > -1:
j=text.find("</h", i)
text = text[ : (i - 1)]+text[(j+4)]
i = text.find("<h")
# Remove Support References from the Text
x = text.find("<sup>")
while x > -1:
y = text.find("</sup>")
text= text[:x] + text[y + 6:len(text)]
x = text.find("<sup>")
# Static Clean ups
text= text.replace('\n', '')
text= text.replace('\r', '')
text= text.replace('&nbsp;', '')
text= text.replace('<P>', '')
text= text.replace('<I>', '')
text= text.replace('</I>', '')
text= text.replace('<P />', '')
text= text.replace('<p />', '')
text= text.replace('</P>', '')
text= text.replace('<BR>', '')
text= text.replace('<BR />', '')
text= text.replace(chr(189), '1/2')
text= text.replace("&quot;", '"')
text= text.replace("&apos;", "'")
i = text.find("<")
while i > -1 :
j = text.find(">", i)
text= text[:i] + text[j+1:]
i = text.find("<")
text= text.replace('>', '')
return text.rstrip()

View File

@ -50,22 +50,24 @@ class BibleManager():
log.debug( "Bible Initialising")
self.bibleDBCache = {} # dict of bible database classes
self.bibleHTTPCache = {} # dict of bible http readers
self.biblePath = path #+"/Data/Bibles" #ConfigHelper.getBiblePath()
print self.biblePath
self.biblePath = path
self.bibleSuffix = "bible3a"
self.dialogobject = None
#log.debug( self.biblePath )
log.debug("Bible Path %s", self.biblePath )
files = os.listdir(self.biblePath)
for f in files:
b = f.split('.')[0]
self.bibleDBCache[b] = BibleDBImpl(b)
biblesource = self.bibleDBCache[b].getMeta("WEB") # look to see if lazy load bible exists and get create getter.
nme = f.split('.')
bname = nme[0]
sfx = nme[1]
if sfx == self.bibleSuffix: # only load files with the correct suffix
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.
if biblesource:
nhttp = BibleHTTPImpl()
nhttp.setBibleSource(biblesource) # tell The Server where to get the verses from.
self.bibleHTTPCache[b] = nhttp
proxy = self.bibleDBCache[b].getMeta("proxy") # look to see if lazy load bible exists and get create getter.
self.bibleHTTPCache[bname] = nhttp
proxy = self.bibleDBCache[bname].getMeta("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.
#