More bible fix ups and added functionality

bzr-revno: 294
This commit is contained in:
Tim Bentley 2009-02-02 19:54:38 +00:00
parent e00e328ac1
commit fdf66b3bd5
8 changed files with 101 additions and 97 deletions

View File

@ -89,3 +89,6 @@ class MediaManagerItem(QtGui.QWidget):
def getInputFiles(self, dialogname, dialoglocation, dialogfilter): def getInputFiles(self, dialogname, dialoglocation, dialogfilter):
return QtGui.QFileDialog.getOpenFileNames(self, dialogname,dialoglocation, dialogfilter) return QtGui.QFileDialog.getOpenFileNames(self, dialogname,dialoglocation, dialogfilter)
def refresh(self):
self.update()

View File

@ -21,6 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import logging import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem
@ -235,7 +237,7 @@ class BiblePlugin(Plugin, PluginUtils):
pass pass
def onBibleNewClick(self): def onBibleNewClick(self):
self.bibleimportform = BibleImportForm(self.config, self.biblemanager) self.bibleimportform = BibleImportForm(self.config, self.biblemanager, self)
self.bibleimportform.setModal(True) self.bibleimportform.setModal(True)
self.bibleimportform.show() self.bibleimportform.show()
pass pass
@ -249,6 +251,13 @@ class BiblePlugin(Plugin, PluginUtils):
def onBibleAddClick(self): def onBibleAddClick(self):
pass pass
def refresh(self):
self.MediaManagerItem.refresh()
def reload_bibles(self):
self.biblemanager.reload_bibles()
self._initialise_form()
def _initialise_form(self): def _initialise_form(self):
log.debug("_initialise_form") log.debug("_initialise_form")
self.QuickSearchComboBox.clear() self.QuickSearchComboBox.clear()
@ -377,6 +386,10 @@ class BiblePlugin(Plugin, PluginUtils):
co = search.find(":") co = search.find(":")
if co == -1: # no : found if co == -1: # no : found
i = search.rfind(" ") i = search.rfind(" ")
if i == -1:
book = search
chapter = ""
else:
book = search[:i] book = search[:i]
chapter = search[i:len(search)] chapter = search[i:len(search)]
hi = chapter.find("-") hi = chapter.find("-")
@ -402,7 +415,6 @@ class BiblePlugin(Plugin, PluginUtils):
everse = search[co+1:] everse = search[co+1:]
else: else:
everse = search everse = search
print search
else: else:
everse = search everse = search
if echapter == "": if echapter == "":
@ -411,12 +423,16 @@ class BiblePlugin(Plugin, PluginUtils):
sverse = 1 sverse = 1
if everse == "": if everse == "":
everse = 99 everse = 99
# print "book = " + book print "book = " + book
# print "chapter s =" + str(schapter) print "chapter s =" + str(schapter)
# print "chapter e =" + str(echapter) print "chapter e =" + str(echapter)
# print "verse s =" + str(sverse) print "verse s =" + str(sverse)
# print "verse e =" + str(everse) print "verse e =" + str(everse)
if not schapter == "":
self.searchresults = self.biblemanager.get_verse_text(bible, book,int(schapter), int(echapter), int(sverse), int(everse)) self.searchresults = self.biblemanager.get_verse_text(bible, book,int(schapter), int(echapter), int(sverse), int(everse))
self._display_results(bible) self._display_results(bible)
else:
QMessageBox.information(self,"Information","A plain, informational message")

View File

@ -25,7 +25,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
""" """
Class documentation goes here. Class documentation goes here.
""" """
def __init__(self, config, biblemanager , parent = None): def __init__(self, config, biblemanager , bibleplugin, parent = None):
""" """
Constructor Constructor
""" """
@ -33,6 +33,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.setupUi(self) self.setupUi(self)
self.biblemanager = biblemanager self.biblemanager = biblemanager
self.config = config self.config = config
self.bibleplugin = bibleplugin
self.bibletype = None self.bibletype = None
self.barmax = 0 self.barmax = 0
@ -79,7 +80,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0: if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0:
self.setCSV() self.setCSV()
else: else:
if self.bibletype == "CVS": # Was CSV and is not any more stops lostFocus running mad if self.bibletype == "CSV": # Was CSV and is not any more stops lostFocus running mad
self.bibletype = None self.bibletype = None
self.freeAll() self.freeAll()
@ -103,30 +104,31 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.freeAll() self.freeAll()
def on_CopyrightEdit_lostFocus(self): def on_CopyrightEdit_lostFocus(self):
A =1 pass
def on_VersionNameEdit_lostFocus(self): def on_VersionNameEdit_lostFocus(self):
A =1 pass
def on_PermisionEdit_lostFocus(self): def on_PermisionEdit_lostFocus(self):
A =1 pass
def on_BibleNameEdit_lostFocus(self): def on_BibleNameEdit_lostFocus(self):
A =1 pass
def on_BibleImportButtonBox_clicked(self,button): def on_BibleImportButtonBox_clicked(self,button):
log.debug("BibleImportButtonBox %s , %s", button.text() , self.bibletype) log.debug("BibleImportButtonBox %s , %s", button.text() , self.bibletype)
if button.text() == "Save": if button.text() == "Save":
if self.biblemanager != None: if self.biblemanager != None:
if not self.bibletype == None: if not self.bibletype == None or len(self.BibleNameEdit.displayText()) > 0:
self.MessageLabel.setText("Import Started") self.MessageLabel.setText("Import Started")
self.ProgressBar.setValue(1) self.ProgressBar.setValue(0)
self.progress = 0 self.progress = 0
self.biblemanager.process_dialog(self) self.biblemanager.process_dialog(self)
self._import_bible() self._import_bible()
self.MessageLabel.setText("Import Complete") self.MessageLabel.setText("Import Complete")
self.ProgressBar.setValue(self.barmax) self.ProgressBar.setValue(self.barmax)
self.update() self.update()
self.bibleplugin.reload_bibles() # Update form as we have a new bible
elif button.text() == "Cancel": elif button.text() == "Cancel":
self.close() self.close()
@ -142,16 +144,17 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.progress +=1 self.progress +=1
self.ProgressBar.setValue(self.progress) self.ProgressBar.setValue(self.progress)
self.update() self.update()
self.bibleplugin.refresh()
def _import_bible(self): def _import_bible(self):
if self.bibletype == "OSIS": if self.bibletype == "OSIS":
self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText()) self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText())
elif self.bibletype == "CSV": elif self.bibletype == "CSV":
self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText()) self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.BooksLocationEdit.displayText(), self.VerseLocationEdit.displayText())
else: else:
self.setMax(1) # set a value as it will not be needed self.setMax(1) # set a value as it will not be needed
bname = self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()),str(self.LocationComboBox.currentText()) ) self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()),str(self.LocationComboBox.currentText()) )
self.BibleNameEdit.setText(bname) self.BibleNameEdit.setText(str(self.BibleComboBox.currentText()))
self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), str(self.VersionNameEdit.displayText()), str(self.CopyrightEdit.displayText()), str(self.PermisionEdit.displayText())) self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), str(self.VersionNameEdit.displayText()), str(self.CopyrightEdit.displayText()), str(self.PermisionEdit.displayText()))
self.bibletype = None self.bibletype = None
@ -165,7 +168,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.VersesFileButton.setEnabled(False) self.VersesFileButton.setEnabled(False)
def setCSV(self): def setCSV(self):
self.bibletype = "CVS" self.bibletype = "CSV"
self.BooksLocationEdit.setReadOnly(False) self.BooksLocationEdit.setReadOnly(False)
self.VerseLocationEdit.setReadOnly(False) self.VerseLocationEdit.setReadOnly(False)
self.BooksFileButton.setEnabled(True) self.BooksFileButton.setEnabled(True)

View File

@ -15,15 +15,11 @@ 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os, os.path import logging
import sys
import urllib2
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
from openlp.plugins.bibles.lib.common import BibleCommon from openlp.plugins.bibles.lib.common import BibleCommon
import logging
class BibleCSVImpl(BibleCommon): class BibleCSVImpl(BibleCommon):
global log global log
@ -37,13 +33,7 @@ class BibleCSVImpl(BibleCommon):
""" """
self.bibledb = bibledb self.bibledb = bibledb
def load_data(self, booksfile, versesfile): def load_data(self, booksfile, versesfile, 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")
#session = self.Session()
#Populate the Tables #Populate the Tables
fbooks=open(booksfile, 'r') fbooks=open(booksfile, 'r')
fverse=open(versesfile, 'r') fverse=open(versesfile, 'r')
@ -51,22 +41,19 @@ class BibleCSVImpl(BibleCommon):
for line in fbooks: for line in fbooks:
#log.debug( line) #log.debug( line)
p = line.split(",") p = line.split(",")
p1 = p[1].replace('"', '')
p2 = p[2].replace('"', '') p2 = p[2].replace('"', '')
p3 = p[3].replace('"', '') p3 = p[3].replace('"', '')
self.bibledb.create_book(int(p[1]), p2, p3) self.bibledb.create_book(p2, p3, int(p1))
book_ptr = None
book_ptr = ""
id = 0
for line in fverse: for line in fverse:
#log.debug( line) #log.debug( line)
p = line.split(",", 3) # split into 3 units and leave the rest as a single field p = line.split(",", 3) # split into 3 units and leave the rest as a single field
p0 = p[0].replace('"', '') p0 = p[0].replace('"', '')
p3 = p[3].replace('"', '') p3 = p[3].replace('"', '')
if book_ptr is not p0: if book_ptr is not p0:
cl = self.bibledb.get_bible_book(p0) book = self.bibledb.get_bible_book(p0)
id = self.bibledb.get_bible_book_Id(p0) book_ptr = book.name
book_ptr = cl dialogobject.incrementBar(book.name) # increament the progress bar
log.debug( id ) self.bibledb.add_verse(book.id, p[1], p[2], p3)
self.bibledb.add_verse(id[0], p[1], p[2], p3)

View File

@ -15,24 +15,18 @@ 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os, os.path import os
import sys import os.path
import time
import datetime
import logging import logging
import string
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.sql import select from sqlalchemy.sql import select
from sqlalchemy.orm import sessionmaker, mapper, scoped_session from sqlalchemy.orm import sessionmaker, mapper, scoped_session
from openlp.plugins.bibles.lib.tables import *
from openlp.plugins.bibles.lib.classes import *
from common import BibleCommon from common import BibleCommon
from openlp.core.utils import ConfigHelper from openlp.core.utils import ConfigHelper
from openlp.plugins.bibles.lib.tables import *
import logging from openlp.plugins.bibles.lib.classes import *
class BibleDBImpl(BibleCommon): class BibleDBImpl(BibleCommon):
global log global log
@ -65,11 +59,11 @@ class BibleDBImpl(BibleCommon):
log.debug( "createTables") log.debug( "createTables")
self.save_meta("dbversion", "2") self.save_meta("dbversion", "2")
self._load_testament("Old Testament") self._load_testament("Old Testament")
self._load_testament("Apocrypha")
self._load_testament("New Testament") self._load_testament("New Testament")
self._load_testament("Apocrypha")
def add_verse(self, bookid, chap, vse, text): def add_verse(self, bookid, chap, vse, text):
log.debug( "add_verse %s,%s,%s,%s", bookid, chap, vse, text) log.debug( "add_verse %s,%s,%s", bookid, chap, vse)
metadata.bind.echo = False metadata.bind.echo = False
session = self.session() session = self.session()
verse = Verse() verse = Verse()
@ -81,7 +75,7 @@ class BibleDBImpl(BibleCommon):
session.commit() session.commit()
def create_chapter(self, bookid, chap, textlist): def create_chapter(self, bookid, chap, textlist):
log.debug( "create_chapter %s,%s,%s", bookid, chap, textlist) log.debug( "create_chapter %s,%s", bookid, chap)
metadata.bind.echo = False metadata.bind.echo = False
session = self.session() session = self.session()
for v , t in textlist.iteritems(): for v , t in textlist.iteritems():
@ -93,12 +87,12 @@ class BibleDBImpl(BibleCommon):
session.add(verse) session.add(verse)
session.commit() session.commit()
def create_book(self, bookname, bookabbrev): def create_book(self, bookname, bookabbrev, testament = 1):
log.debug( "create_book %s,%s", bookname, bookabbrev) log.debug( "create_book %s,%s", bookname, bookabbrev)
metadata.bind.echo = False metadata.bind.echo = False
session = self.session() session = self.session()
book = Book() book = Book()
book.testament_id = 1 book.testament_id = testament
book.name = bookname book.name = bookname
book.abbreviation = bookabbrev book.abbreviation = bookabbrev
session.add(book) session.add(book)
@ -159,9 +153,7 @@ class BibleDBImpl(BibleCommon):
def get_bible_chapter(self, id, chapter): def get_bible_chapter(self, id, chapter):
log.debug( "get_bible_chapter %s,%s", id, chapter ) log.debug( "get_bible_chapter %s,%s", id, chapter )
metadata.bind.echo = False metadata.bind.echo = False
#s = text (""" select book.name FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and book.name == :b """)
return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first() return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first()
#return self.db.execute(s, c=chapter, b=bookname).fetchone()
def get_bible_text(self, bookname, chapter, sverse, everse): def get_bible_text(self, bookname, chapter, sverse, everse):
log.debug( "get_bible_text %s,%s,%s,%s ", bookname, chapter, sverse, everse) log.debug( "get_bible_text %s,%s,%s,%s ", bookname, chapter, sverse, everse)

View File

@ -157,14 +157,14 @@ class BibleHTTPImpl():
def set_bible_source(self,biblesource): def set_bible_source(self,biblesource):
""" """
Set the source of where the bible text is comming from Set the source of where the bible text is coming from
""" """
log.debug("set_bible_source %s", biblesource) log.debug("set_bible_source %s", biblesource)
self.biblesource = biblesource self.biblesource = biblesource
def get_bible_chapter(self, version, bookid, bookname, chapter): def get_bible_chapter(self, version, bookid, bookname, chapter):
""" """
Recieve the request and call the relevent handler methods Receive the request and call the relevant handler methods
""" """
log.debug( "get_bible_chapter %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) log.debug("biblesource = %s", self.biblesource)

View File

@ -15,13 +15,8 @@ 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os, os.path
import sys
import urllib2
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
import logging import logging
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
class BibleOSISImpl(): class BibleOSISImpl():
global log global log
@ -39,25 +34,19 @@ class BibleOSISImpl():
def load_data(self, osisfile, dialogobject=None): 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)
osis=open(osisfile, 'r') osis=open(osisfile, 'r')
book_ptr = "" book_ptr = None
id = 0 id = 0
verseText = "<verse osisID=" verseText = "<verse osisID="
testament = 1
for f in osis.readlines(): for f in osis.readlines():
#print f #print f
s = f.find(verseText) s = f.find(verseText)
if s > -1: # we have a verse if s > -1: # we have a verse
e= f.find(">", s) e= f.find(">", s)
ref = f[s+15:e-1] # Book Reference ref = f[s+15:e-1] # Book Reference
#lets find the bble text #lets find the bible text
s = e + 1 # find start of text s = e + 1 # find start of text
e = f.find("</verse>", s) # end of text e = f.find("</verse>", s) # end of text
t = f[s:e] t = f[s:e]
@ -81,12 +70,19 @@ class BibleOSISImpl():
#print "X", s, e, t #print "X", s, e, t
s = t.find("<RF>") s = t.find("<RF>")
p = ref.split(".", 3) # split u[ the reference p = ref.split(".", 3) # split up the reference
if book_ptr != p[0]: if book_ptr != p[0]:
if book_ptr == None: # first time through
if p[0] == "Gen": # set the max book size depending on the first book read
dialogobject.setMax(66)
else:
dialogobject.setMax(27)
if p[0] == "Gen":
testament += 1
book_ptr = p[0] book_ptr = p[0]
id = self.bibledb.create_book(int(p[1]), self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]]) book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament)
dialogobject.incrementBar() dialogobject.incrementBar(self.booksOfBible[p[0]] )
self.bibledb.add_verse(id, p[1], p[2], t) self.bibledb.add_verse(book.id, p[1], p[2], t)

View File

@ -44,16 +44,23 @@ class BibleManager():
""" """
self.config = config self.config = config
log.debug( "Bible Initialising") log.debug( "Bible Initialising")
self.bibleDBCache = {} # dict of bible database classes self.bibleDBCache = None # dict of bible database classes
self.bibleHTTPCache = {} # dict of bible http readers self.bibleHTTPCache = None # dict of bible http readers
self.biblePath = self.config.get_data_path() self.biblePath = self.config.get_data_path()
self.proxyname = self.config.get_config("proxy name") #get proxy name for screen self.proxyname = self.config.get_config("proxy name") #get proxy name for screen
self.bibleSuffix = "sqlite" self.bibleSuffix = "sqlite"
self.dialogobject = None self.dialogobject = None
self.reload_bibles()
def reload_bibles(self):
log.debug("Reload bibles")
files = self.config.get_files(self.bibleSuffix) files = self.config.get_files(self.bibleSuffix)
log.debug("Bible Files %s", files ) log.debug("Bible Files %s", files )
self.bibleDBCache = {}
self.bibleHTTPCache = {}
for f in files: for f in files:
nme = f.split('.') nme = f.split('.')
bname = nme[0] bname = nme[0]
@ -96,21 +103,21 @@ class BibleManager():
nbible.save_meta("proxyid", proxyid) # store the proxy userid nbible.save_meta("proxyid", proxyid) # store the proxy userid
if proxypass != None: if proxypass != None:
nbible.save_meta("proxypass", proxypass) # store the proxy password nbible.save_meta("proxypass", proxypass) # store the proxy password
return biblename
def register_cvs_file_bible(self, biblename, booksfile, versefile): def register_csv_file_bible(self, biblename, booksfile, versefile):
""" """
Method to load a bible from a set of files into a database. 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 If the database exists it is deleted and the database is reloaded
from scratch. from scratch.
""" """
log.debug( "register_CSV_file_bible %s,%s,%s", biblename, booksfile, versefile)
if self._is_new_bible(biblename): if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible
nbible.create_tables() # Create Database nbible.create_tables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later self.bibleDBCache[biblename] = nbible # cache the database for use later
bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database
bcsv.load_data(booksfile, versefile) bcsv.load_data(booksfile, versefile, self.dialogobject)
def register_osis_file_bible(self, biblename, osisfile): def register_osis_file_bible(self, biblename, osisfile):
""" """
@ -176,10 +183,10 @@ class BibleManager():
""" """
Saves the bibles meta data Saves the bibles meta data
""" """
log.debug( "save_meta %s,%s, %s,%s", bible, version, copyright, permissions) log.debug( "save_meta data %s,%s, %s,%s", bible, version, copyright, permissions)
self.bibleDBCache[bible].save_meta("Version", version) self.bibleDBCache[bible].save_meta("Version", version)
self.bibleDBCache[bible].save_meta("Copyright", copyright) self.bibleDBCache[bible].save_meta("Copyright", copyright)
self.bibleDBCache[bible].save_meta("Permissins", permissions) self.bibleDBCache[bible].save_meta("Permissions", permissions)
def get_meta_data(self, bible, key): def get_meta_data(self, bible, key):
""" """