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