openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #01192
[Merge] lp:~raoul-snyman/openlp/biblefixes into lp:openlp
Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/biblefixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Fixes two bugs:
- Bible file names were being taken directly from the Bible name. They are now cleaned.
- A fix for displaying verses on Windows resulted in a bug on Linux. This has been fixed so that both scenarios are being taken care of.
--
https://code.launchpad.net/~raoul-snyman/openlp/biblefixes/+merge/21488
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/db.py'
--- openlp/plugins/bibles/lib/db.py 2010-02-27 09:18:26 +0000
+++ openlp/plugins/bibles/lib/db.py 2010-03-16 20:48:21 +0000
@@ -26,6 +26,7 @@
import os
import logging
import chardet
+import re
from sqlalchemy import or_
from PyQt4 import QtCore
@@ -63,16 +64,22 @@
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 @@
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 @@
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 @@
.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:
=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py 2010-03-13 21:48:04 +0000
+++ openlp/plugins/bibles/lib/manager.py 2010-03-16 20:48:21 +0000
@@ -123,20 +123,21 @@
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')
=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py 2010-03-13 21:48:04 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py 2010-03-16 20:48:21 +0000
@@ -65,6 +65,12 @@
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 @@
# 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:
Follow ups