diff --git a/openlp/core/pluginmanager.py b/openlp/core/pluginmanager.py index 98caaa755..7e96ce764 100644 --- a/openlp/core/pluginmanager.py +++ b/openlp/core/pluginmanager.py @@ -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 = [] diff --git a/openlp/plugins/biblemanager/test/test_bibleManager.py b/openlp/plugins/biblemanager/test/test_bibleManager.py index 1732d6204..e530d8cac 100644 --- a/openlp/plugins/biblemanager/test/test_bibleManager.py +++ b/openlp/plugins/biblemanager/test/test_bibleManager.py @@ -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 diff --git a/openlp/plugins/biblemanager/test/test_bibleManagerCSV.py b/openlp/plugins/biblemanager/test/test_bibleManagerCSV.py index 320a8c7a4..03d8ea7b7 100644 --- a/openlp/plugins/biblemanager/test/test_bibleManagerCSV.py +++ b/openlp/plugins/biblemanager/test/test_bibleManagerCSV.py @@ -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 diff --git a/openlp/plugins/biblemanager/test/test_bibleManagerOSIS.py b/openlp/plugins/biblemanager/test/test_bibleManagerOSIS.py index 9eac85bb6..8689f9a76 100644 --- a/openlp/plugins/biblemanager/test/test_bibleManagerOSIS.py +++ b/openlp/plugins/biblemanager/test/test_bibleManagerOSIS.py @@ -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 diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 215db97d6..65bcc3991 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -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)) diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index c32e022d0..130f5d7aa 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -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 diff --git a/openlp/plugins/bibles/forms/bibleimportprogressform.py b/openlp/plugins/bibles/forms/bibleimportprogressform.py index ed44bab7b..c6e84f63a 100644 --- a/openlp/plugins/bibles/forms/bibleimportprogressform.py +++ b/openlp/plugins/bibles/forms/bibleimportprogressform.py @@ -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): """ diff --git a/openlp/plugins/bibles/lib/bibleCSVimpl.py b/openlp/plugins/bibles/lib/bibleCSVimpl.py index d69380793..d8e70e422 100644 --- a/openlp/plugins/bibles/lib/bibleCSVimpl.py +++ b/openlp/plugins/bibles/lib/bibleCSVimpl.py @@ -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, diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index d8fbda2e2..8d083e5bb 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -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': diff --git a/openlp/plugins/bibles/lib/bibleHTTPimpl.py b/openlp/plugins/bibles/lib/bibleHTTPimpl.py index c7468942d..0bf12eace 100644 --- a/openlp/plugins/bibles/lib/bibleHTTPimpl.py +++ b/openlp/plugins/bibles/lib/bibleHTTPimpl.py @@ -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, diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 76553882c..6969bb621 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -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, diff --git a/openlp/plugins/bibles/lib/biblecommon.py b/openlp/plugins/bibles/lib/biblecommon.py new file mode 100644 index 000000000..60cd43c85 --- /dev/null +++ b/openlp/plugins/bibles/lib/biblecommon.py @@ -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(" -1: + j=text.find("") + while x > -1: + y = text.find("") + text= text[:x] + text[y + 6:len(text)] + x = text.find("") + + # Static Clean ups + text= text.replace('\n', '') + text= text.replace('\r', '') + text= text.replace(' ', '') + text= text.replace('

', '') + text= text.replace('', '') + text= text.replace('', '') + text= text.replace('

', '') + text= text.replace('

', '') + text= text.replace('

', '') + text= text.replace('
', '') + text= text.replace('
', '') + text= text.replace(chr(189), '1/2') + text= text.replace(""", '"') + text= text.replace("'", "'") + + 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() + + diff --git a/openlp/plugins/bibles/lib/biblemanager.py b/openlp/plugins/bibles/lib/biblemanager.py index 70872bd32..33ad44387 100644 --- a/openlp/plugins/bibles/lib/biblemanager.py +++ b/openlp/plugins/bibles/lib/biblemanager.py @@ -50,23 +50,25 @@ 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. - 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. - nhttp.setProxy(proxy) # tell The Server where to get the verses from. + 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[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. # log.debug( "Bible Initialised")