forked from openlp/openlp
Head r744
This commit is contained in:
commit
ed370650f8
@ -26,6 +26,7 @@
|
||||
import os
|
||||
import logging
|
||||
import chardet
|
||||
import re
|
||||
|
||||
from sqlalchemy import or_
|
||||
from PyQt4 import QtCore
|
||||
@ -63,16 +64,22 @@ class BibleDB(QtCore.QObject):
|
||||
QtCore.QObject.__init__(self)
|
||||
if u'path' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "path".')
|
||||
if u'name' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "name".')
|
||||
if u'config' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "config".')
|
||||
if u'name' not in kwargs and u'file' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "name" or "file".')
|
||||
self.stop_import_flag = False
|
||||
self.name = kwargs[u'name']
|
||||
self.config = kwargs[u'config']
|
||||
self.db_file = os.path.join(kwargs[u'path'],
|
||||
u'%s.sqlite' % kwargs[u'name'])
|
||||
log.debug(u'Load bible %s on path %s', kwargs[u'name'], self.db_file)
|
||||
if u'name' in kwargs:
|
||||
self.name = kwargs[u'name']
|
||||
if not isinstance(self.name, unicode):
|
||||
self.name = unicode(self.name, u'utf-8')
|
||||
self.file = self.clean_filename(self.name)
|
||||
if u'file' in kwargs:
|
||||
self.file = kwargs[u'file']
|
||||
|
||||
self.db_file = os.path.join(kwargs[u'path'], self.file)
|
||||
log.debug(u'Load bible %s on path %s', self.file, self.db_file)
|
||||
db_type = self.config.get_config(u'db type', u'sqlite')
|
||||
db_url = u''
|
||||
if db_type == u'sqlite':
|
||||
@ -85,12 +92,28 @@ class BibleDB(QtCore.QObject):
|
||||
self.config.get_config(u'db database'))
|
||||
self.metadata, self.session = init_models(db_url)
|
||||
self.metadata.create_all(checkfirst=True)
|
||||
if u'file' in kwargs:
|
||||
self.get_name()
|
||||
|
||||
def get_name(self):
|
||||
version_name = self.get_meta(u'Version')
|
||||
if version_name:
|
||||
self.name = version_name.value
|
||||
else:
|
||||
self.name = None
|
||||
return self.name
|
||||
|
||||
def clean_filename(self, old_filename):
|
||||
if not isinstance(old_filename, unicode):
|
||||
old_filename = unicode(old_filename, u'utf-8')
|
||||
old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_')
|
||||
return old_filename + u'.sqlite'
|
||||
|
||||
def register(self, wizard):
|
||||
"""
|
||||
This method basically just initialialises the database. It is called
|
||||
from the Bible Manager when a Bible is imported. Descendant classes
|
||||
may want to override this method to supply their own custom
|
||||
may want to override this method to suVersionpply their own custom
|
||||
initialisation as well.
|
||||
"""
|
||||
self.wizard = wizard
|
||||
@ -241,8 +264,6 @@ class BibleDB(QtCore.QObject):
|
||||
count = self.session.query(Verse.chapter).join(Book)\
|
||||
.filter(Book.name==book)\
|
||||
.distinct().count()
|
||||
#verse = self.session.query(Verse).join(Book).filter(
|
||||
# Book.name == bookname).order_by(Verse.chapter.desc()).first()
|
||||
if not count:
|
||||
return 0
|
||||
else:
|
||||
@ -254,9 +275,6 @@ class BibleDB(QtCore.QObject):
|
||||
.filter(Book.name==book)\
|
||||
.filter(Verse.chapter==chapter)\
|
||||
.count()
|
||||
#verse = self.session.query(Verse).join(Book).filter(
|
||||
# Book.name == bookname).filter(
|
||||
# Verse.chapter == chapter).order_by(Verse.verse.desc()).first()
|
||||
if not count:
|
||||
return 0
|
||||
else:
|
||||
|
@ -123,20 +123,21 @@ class BibleManager(object):
|
||||
log.debug(u'Bible Files %s', files)
|
||||
self.db_cache = {}
|
||||
for filename in files:
|
||||
name, extension = os.path.splitext(filename)
|
||||
self.db_cache[name] = BibleDB(self.parent, path=self.path,
|
||||
name=name, config=self.config)
|
||||
bible = BibleDB(self.parent, path=self.path, file=filename,
|
||||
config=self.config)
|
||||
name = bible.get_name()
|
||||
log.debug(u'Bible Name: "%s"', name)
|
||||
self.db_cache[name] = bible
|
||||
# look to see if lazy load bible exists and get create getter.
|
||||
source = self.db_cache[name].get_meta(u'download source')
|
||||
if source:
|
||||
download_name = self.db_cache[name].get_meta(u'download name').value
|
||||
meta_proxy = self.db_cache[name].get_meta(u'proxy url')
|
||||
web_bible = HTTPBible(self.parent, path=self.path, name=name,
|
||||
config=self.config, download_source=source.value,
|
||||
download_name=download_name)
|
||||
web_bible = HTTPBible(self.parent, path=self.path,
|
||||
file=filename, config=self.config,
|
||||
download_source=source.value, download_name=download_name)
|
||||
if meta_proxy:
|
||||
web_bible.set_proxy_server(meta_proxy.value)
|
||||
#del self.db_cache[name]
|
||||
self.db_cache[name] = web_bible
|
||||
log.debug(u'Bibles reloaded')
|
||||
|
||||
|
@ -65,6 +65,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'openlpreloadbibles'), self.reloadBibles)
|
||||
|
||||
def _decodeQtObject(self, listobj, key):
|
||||
obj = listobj[QtCore.QString(key)]
|
||||
if isinstance(obj, QtCore.QVariant):
|
||||
obj = obj.toPyObject()
|
||||
return unicode(obj)
|
||||
|
||||
def initPluginNameVisible(self):
|
||||
self.PluginNameVisible = self.trUtf8('Bible')
|
||||
|
||||
@ -452,15 +458,17 @@ class BibleMediaItem(MediaManagerItem):
|
||||
# Let's loop through the main lot, and assemble our verses
|
||||
for item in items:
|
||||
bitem = self.ListView.item(item.row())
|
||||
reference = bitem.data(QtCore.Qt.UserRole).toPyObject()
|
||||
bible = unicode(reference[QtCore.QString('bible')].toPyObject())
|
||||
book = unicode(reference[QtCore.QString('book')].toPyObject())
|
||||
chapter = unicode(reference[QtCore.QString('chapter')].toPyObject())
|
||||
verse = unicode(reference[QtCore.QString('verse')].toPyObject())
|
||||
text = unicode(reference[QtCore.QString('text')].toPyObject())
|
||||
version = unicode(reference[QtCore.QString('version')].toPyObject())
|
||||
copyright = unicode(reference[QtCore.QString('copyright')].toPyObject())
|
||||
permission = unicode(reference[QtCore.QString('permission')].toPyObject())
|
||||
reference = bitem.data(QtCore.Qt.UserRole)
|
||||
if isinstance(reference, QtCore.QVariant):
|
||||
reference = reference.toPyObject()
|
||||
bible = self._decodeQtObject(reference, 'bible')
|
||||
book = self._decodeQtObject(reference, 'book')
|
||||
chapter = self._decodeQtObject(reference, 'chapter')
|
||||
verse = self._decodeQtObject(reference, 'verse')
|
||||
text = self._decodeQtObject(reference, 'text')
|
||||
version = self._decodeQtObject(reference, 'version')
|
||||
copyright = self._decodeQtObject(reference, 'copyright')
|
||||
permission = self._decodeQtObject(reference, 'permission')
|
||||
if self.parent.settings_tab.display_style == 1:
|
||||
verse_text = self.formatVerse(old_chapter, chapter, verse, u'(u', u')')
|
||||
elif self.parent.settings_tab.display_style == 2:
|
||||
|
Loading…
Reference in New Issue
Block a user