From 8124f0e8fe1f12d2be5b5df82b1ba214696a1e99 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 11 Mar 2010 14:02:43 +0000 Subject: [PATCH 01/16] Import and weird character cleanups --- openlp.pyw | 1 - openlp/core/ui/mainwindow.py | 1 - openlp/core/utils/__init__.py | 2 +- .../hook-openlp.plugins.presentations.presentationplugin.py | 2 +- resources/pyinstaller/hook-openlp.py | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index c4a5fb428..1de9c8417 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -34,7 +34,6 @@ from PyQt4 import QtCore, QtGui log = logging.getLogger() -import openlp from openlp.core.lib import Receiver, str_to_bool from openlp.core.resources import qInitResources from openlp.core.ui import MainWindow, SplashScreen, ScreenList diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 41b6d245f..808c4ad4c 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -23,7 +23,6 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import os import logging import time diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 4083300a6..042b8d88e 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -100,4 +100,4 @@ def check_latest_version(config, current_version): from registry import Registry from confighelper import ConfigHelper -__all__ = [u'Registry', u'ConfigHelper', u'AppLocations', u'check_latest_version'] +__all__ = [u'Registry', u'ConfigHelper', u'AppLocation', u'check_latest_version'] diff --git a/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py b/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py index 8b7d6b8a2..0ede06f90 100644 --- a/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py +++ b/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py @@ -1,3 +1,3 @@ -hiddenimports = ['openlp.plugins.presentations.lib.impresscontroller', +hiddenimports = ['openlp.plugins.presentations.lib.impresscontroller', 'openlp.plugins.presentations.lib.powerpointcontroller', 'openlp.plugins.presentations.lib.pptviewcontroller'] \ No newline at end of file diff --git a/resources/pyinstaller/hook-openlp.py b/resources/pyinstaller/hook-openlp.py index bd97e4aec..b77ec8b62 100644 --- a/resources/pyinstaller/hook-openlp.py +++ b/resources/pyinstaller/hook-openlp.py @@ -1,4 +1,4 @@ -hiddenimports = ['plugins.songs.songsplugin', +hiddenimports = ['plugins.songs.songsplugin', 'plugins.bibles.bibleplugin', 'plugins.presentations.presentationplugin', 'plugins.media.mediaplugin', From 90d2282e08ca0adc0f44964ed4f57165ab8d5857 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 15 Mar 2010 20:47:07 +0200 Subject: [PATCH 02/16] First attempt at fixing the Bible file name issue. --- openlp/plugins/bibles/lib/db.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index be4112a54..c3f22883f 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -26,6 +26,7 @@ import os import logging import chardet +import re from sqlalchemy import or_ from PyQt4 import QtCore @@ -69,10 +70,11 @@ class BibleDB(QtCore.QObject): raise KeyError(u'Missing keyword argument "config".') self.stop_import_flag = False self.name = kwargs[u'name'] + self.filename = self.clean_filename(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) + u'%s.sqlite' % self.filename) + log.debug(u'Load bible %s on path %s', self.filename, self.db_file) db_type = self.config.get_config(u'db type', u'sqlite') db_url = u'' if db_type == u'sqlite': @@ -86,6 +88,12 @@ class BibleDB(QtCore.QObject): self.metadata, self.session = init_models(db_url) self.metadata.create_all(checkfirst=True) + def clean_filename(self, old_filename): + for char in [u'\\', u'/', u':', u'*', u'?', u'"', u'<', u'>', u'|', u' ']: + old_filename = old_filename.replace(char, u'_') + old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_') + return old_filename + def register(self, wizard): """ This method basically just initialialises the database. It is called From 9044ed3a4a18d436f44bfa472459a311f5e2b9f9 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Mar 2010 21:46:19 +0200 Subject: [PATCH 03/16] Fixed a bug where Bible names were being used for file names, and causing issues on various operating systems. --- openlp/plugins/bibles/lib/db.py | 35 +++++++++++++++++++++------- openlp/plugins/bibles/lib/manager.py | 16 ++++++++----- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index a09223a20..08c6cbe38 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -66,15 +66,20 @@ class BibleDB(QtCore.QObject): raise KeyError(u'Missing keyword argument "path".') if u'config' not in kwargs: raise KeyError(u'Missing keyword argument "config".') - if u'name' not in kwargs: - raise KeyError(u'Missing keyword argument "name".') + 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.config = kwargs[u'config'] - self.name = kwargs[u'name'] - #self.filename = self.clean_filename(kwargs[u'name']) - self.db_file = os.path.join(kwargs[u'path'], - u'%s.sqlite' % self.name) - log.debug(u'Load bible %s on path %s', self.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': @@ -87,18 +92,30 @@ 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') for char in [u'\\', u'/', u':', u'*', u'?', u'"', u'<', u'>', u'|', u' ']: old_filename = old_filename.replace(char, u'_') old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_') - return old_filename + 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 diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 5fc871abc..12b4eeec8 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -123,17 +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) + #self.db_cache[name] = BibleDB(self.parent, path=self.path, + # 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. 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] From dc6c6bec31938fe9f65c90a3419eb0d7ac5916ac Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Mar 2010 22:43:41 +0200 Subject: [PATCH 04/16] - Removed commented code (just for you, TRB143!) - Removed any non-alphanumeric character for Bible names, just to be safe, since we don't actually use the filenames anymore. --- openlp/plugins/bibles/lib/db.py | 9 +-------- openlp/plugins/bibles/lib/manager.py | 3 --- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 08c6cbe38..8f55fb5fc 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -106,9 +106,7 @@ class BibleDB(QtCore.QObject): def clean_filename(self, old_filename): if not isinstance(old_filename, unicode): old_filename = unicode(old_filename, u'utf-8') - for char in [u'\\', u'/', u':', u'*', u'?', u'"', u'<', u'>', u'|', u' ']: - old_filename = old_filename.replace(char, u'_') - old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_') + old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_') return old_filename + u'.sqlite' def register(self, wizard): @@ -266,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: @@ -279,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: diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 12b4eeec8..90401a3e1 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -125,8 +125,6 @@ class BibleManager(object): for filename in files: bible = BibleDB(self.parent, path=self.path, file=filename, config=self.config) - #self.db_cache[name] = BibleDB(self.parent, path=self.path, - # name=name, config=self.config) name = bible.get_name() log.debug(u'Bible Name: "%s"', name) self.db_cache[name] = bible @@ -140,7 +138,6 @@ class BibleManager(object): 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') From a81c39ca659e8692b1e25e3f04beed23c16690ad Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 16 Mar 2010 21:13:23 +0000 Subject: [PATCH 05/16] Import fix --- openlp/plugins/bibles/lib/manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 90401a3e1..10ee7b9f9 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -24,7 +24,6 @@ ############################################################################### import logging -import os from common import parse_reference from opensong import OpenSongBible From fea160c5c4a0b89ab6f10f5556a5e14d3965ca7b Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 18 Mar 2010 15:43:27 +0000 Subject: [PATCH 06/16] AppLocation.PluginsDir changes --- openlp/core/utils/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 5d97dd8f2..61c38af87 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -43,7 +43,7 @@ class AppLocation(object): @staticmethod def get_directory(dir_type): if dir_type == AppLocation.AppDir: - return os.path.abspath(os.path.split(sys.argv[0])[0]) + return os.path.abspath(os.path.split(sys.argv[0])[0]) elif dir_type == AppLocation.ConfigDir: if sys.platform == u'win32': path = os.path.join(os.getenv(u'APPDATA'), u'openlp') @@ -71,11 +71,18 @@ class AppLocation(object): path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data') return path elif dir_type == AppLocation.PluginsDir: + plugin_path = None app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - if hasattr(sys, u'frozen') and sys.frozen == 1: - return os.path.join(app_path, u'plugins') + if sys.platform == u'win32': + if hasattr(sys, u'frozen') and sys.frozen == 1: + plugin_path = os.path.join(app_path, u'plugins') + else: + plugin_path = os.path.join(app_path, u'openlp', u'plugins') + elif sys.platform == u'darwin': + plugin_path = os.path.join(app_path, u'plugins') else: - return os.path.join(app_path, u'openlp', u'plugins') + plugin_path = os.path.join(openlp.__file__, u'plugins') + return plugin_path def check_latest_version(config, current_version): From 5d2fe81d712cfe34c2d043b5f66d2bf6f7ffe36e Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 18 Mar 2010 15:52:37 +0000 Subject: [PATCH 07/16] Fix for AppLocation changes --- openlp/core/utils/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 61c38af87..9cd539169 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -81,7 +81,8 @@ class AppLocation(object): elif sys.platform == u'darwin': plugin_path = os.path.join(app_path, u'plugins') else: - plugin_path = os.path.join(openlp.__file__, u'plugins') + plugin_path = os.path.join( + os.path.split(openlp.__file__)[0], u'plugins') return plugin_path From de767459bd4f4594498bbcf18218e46020db723b Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 18 Mar 2010 16:25:25 +0000 Subject: [PATCH 08/16] Fix 2 for AppLocation changes --- openlp/core/utils/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9cd539169..3ffb9ee8d 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -23,6 +23,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import openlp import os import sys import logging From 6414330b2c810a827a882bf64e0f4f771b4653d6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 18 Mar 2010 23:36:30 +0200 Subject: [PATCH 09/16] Reworked the BibleGateway Bibles. Changed some code to be standards compliant. --- openlp/core/utils/__init__.py | 3 +- openlp/plugins/bibles/lib/http.py | 130 +++++++++++++++++++++--------- 2 files changed, 93 insertions(+), 40 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 3ffb9ee8d..d29ff17b4 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -23,13 +23,14 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import openlp import os import sys import logging import urllib2 from datetime import datetime +import openlp + log = logging.getLogger(__name__) class AppLocation(object): diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 5a170d84c..ca75fb16b 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -28,7 +28,7 @@ import urllib2 import os import sqlite3 -from BeautifulSoup import BeautifulSoup +from BeautifulSoup import BeautifulSoup, Tag, NavigableString from openlp.core.lib import Receiver from openlp.core.utils import AppLocation @@ -146,44 +146,96 @@ class BGExtract(BibleCommon): urlstring = u'http://www.biblegateway.com/passage/?search=%s+%s' \ u'&version=%s' % (bookname, chapter, version) log.debug(u'BibleGateway url = %s' % urlstring) - xml_string = self._get_web_text(urlstring, self.proxyurl) - verseSearch = u' -1: - # clear out string - verseText = u'' - versePos = xml_string.find(u'', versePos) + 6 - i = xml_string.find(verseSearch, versePos + 1) - # Not sure if this is needed now - if i == -1: - i = xml_string.find(u' 0 and j < i: - i = j - verseText = xml_string[versePos + 7 : i ] - # store the verse - bible[verse] = self._clean_text(verseText) - versePos = -1 - else: - verseText = xml_string[versePos: i] - start_tag = verseText.find(verseFootnote) - while start_tag > -1: - end_tag = verseText.find(u'') - verseText = verseText[:start_tag] + verseText[end_tag + 6:len(verseText)] - start_tag = verseText.find(verseFootnote) - # Chop off verse and start again - xml_string = xml_string[i:] - #look for the next verse - versePos = xml_string.find(verseSearch) - # store the verse - bible[verse] = self._clean_text(verseText) - verse += 1 - return SearchResults(bookname, chapter, bible) + + page = urllib2.urlopen(urlstring) + soup = BeautifulSoup(page) + verses = soup.find(u'div', u'result-text-style-normal') + + verse_number = 0 + verse_list = {0: u''} + + for verse in verses: + if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes': + break + if isinstance(verse, Tag) and verse.name == u'sup' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] != u'versenum': + continue + if isinstance(verse, Tag) and verse.name == u'p' and not verse.contents: + continue + if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents: + for item in verse.contents: + if isinstance(item, Tag) and (item.name == u'h4' or item.name == u'h5'): + continue + if isinstance(item, Tag) and item.name == u'sup' and filter(lambda a: a[0] == u'class', item.attrs)[0][1] != u'versenum': + continue + if isinstance(item, Tag) and item.name == u'p' and not item.contents: + continue + if isinstance(item, Tag) and item.name == u'sup': + verse_number = int(str(item.contents[0])) + verse_list[verse_number] = u'' + continue + if isinstance(item, Tag) and item.name == u'font': + for subitem in item.contents: + if isinstance(subitem, Tag) and subitem.name == u'sup' and filter(lambda a: a[0] == u'class', subitem.attrs)[0][1] != u'versenum': + continue + if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents: + continue + if isinstance(subitem, Tag) and subitem.name == u'sup': + verse_number = int(str(subitem.contents[0])) + verse_list[verse_number] = u'' + continue + if isinstance(subitem, NavigableString): + verse_list[verse_number] = verse_list[verse_number] + subitem.replace(u' ', u' ') + continue + if isinstance(item, NavigableString): + verse_list[verse_number] = verse_list[verse_number] + item.replace(u' ', u' ') + continue + if isinstance(verse, Tag) and verse.name == u'sup': + verse_number = int(str(verse.contents[0])) + verse_list[verse_number] = u'' + continue + if isinstance(verse, NavigableString): + verse_list[verse_number] = verse_list[verse_number] + verse.replace(u' ', u' ') + + del verse_list[0] + +# xml_string = self._get_web_text(urlstring, self.proxyurl) +# verseSearch = u' -1: +# # clear out string +# verseText = u'' +# versePos = xml_string.find(u'', versePos) + 6 +# i = xml_string.find(verseSearch, versePos + 1) +# # Not sure if this is needed now +# if i == -1: +# i = xml_string.find(u' 0 and j < i: +# i = j +# verseText = xml_string[versePos + 7 : i ] +# # store the verse +# bible[verse] = self._clean_text(verseText) +# versePos = -1 +# else: +# verseText = xml_string[versePos: i] +# start_tag = verseText.find(verseFootnote) +# while start_tag > -1: +# end_tag = verseText.find(u'') +# verseText = verseText[:start_tag] + verseText[end_tag + 6:len(verseText)] +# start_tag = verseText.find(verseFootnote) +# # Chop off verse and start again +# xml_string = xml_string[i:] +# #look for the next verse +# versePos = xml_string.find(verseSearch) +# # store the verse +# bible[verse] = self._clean_text(verseText) +# verse += 1 + return SearchResults(bookname, chapter, verse_list) class CWExtract(BibleCommon): log.info(u'%s CWExtract loaded', __name__) From 2a903d6a5b1840764bbb5963d0641996f3b5def6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 19 Mar 2010 09:00:41 +0200 Subject: [PATCH 10/16] Added some documentation and removed the commented code. --- openlp/plugins/bibles/lib/http.py | 50 +++++-------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index ca75fb16b..55350c093 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -146,14 +146,16 @@ class BGExtract(BibleCommon): urlstring = u'http://www.biblegateway.com/passage/?search=%s+%s' \ u'&version=%s' % (bookname, chapter, version) log.debug(u'BibleGateway url = %s' % urlstring) - + # Let's get the page, and then open it in BeautifulSoup, so as to + # attempt to make "easy" work of bad HTML. page = urllib2.urlopen(urlstring) soup = BeautifulSoup(page) verses = soup.find(u'div', u'result-text-style-normal') - verse_number = 0 verse_list = {0: u''} - + # http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html + # This is a PERFECT example of opening the Cthulu tag! + # O Bible Gateway, why doth ye such horrific HTML produce? for verse in verses: if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes': break @@ -195,46 +197,10 @@ class BGExtract(BibleCommon): continue if isinstance(verse, NavigableString): verse_list[verse_number] = verse_list[verse_number] + verse.replace(u' ', u' ') - + # Delete the "0" element, since we don't need it, it's just there for + # some stupid initial whitespace, courtesy of Bible Gateway. del verse_list[0] - -# xml_string = self._get_web_text(urlstring, self.proxyurl) -# verseSearch = u' -1: -# # clear out string -# verseText = u'' -# versePos = xml_string.find(u'', versePos) + 6 -# i = xml_string.find(verseSearch, versePos + 1) -# # Not sure if this is needed now -# if i == -1: -# i = xml_string.find(u' 0 and j < i: -# i = j -# verseText = xml_string[versePos + 7 : i ] -# # store the verse -# bible[verse] = self._clean_text(verseText) -# versePos = -1 -# else: -# verseText = xml_string[versePos: i] -# start_tag = verseText.find(verseFootnote) -# while start_tag > -1: -# end_tag = verseText.find(u'') -# verseText = verseText[:start_tag] + verseText[end_tag + 6:len(verseText)] -# start_tag = verseText.find(verseFootnote) -# # Chop off verse and start again -# xml_string = xml_string[i:] -# #look for the next verse -# versePos = xml_string.find(verseSearch) -# # store the verse -# bible[verse] = self._clean_text(verseText) -# verse += 1 + # Finally, return the list of verses in a "SearchResults" object. return SearchResults(bookname, chapter, verse_list) class CWExtract(BibleCommon): From eddd11281133756b1cf0cea0f5bfb4440c413fad Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 20 Mar 2010 00:08:06 +0200 Subject: [PATCH 11/16] Failed Bibles are deleted. --- openlp/plugins/bibles/forms/importwizardform.py | 12 +++++++----- openlp/plugins/bibles/lib/db.py | 8 +++++++- openlp/plugins/bibles/lib/manager.py | 2 +- openlp/plugins/bibles/lib/osis.py | 4 ++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 422e869eb..7e8cde45b 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -315,23 +315,23 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): def performImport(self): bible_type = self.field(u'source_format').toInt()[0] - success = False + importer = None if bible_type == BibleFormat.OSIS: # Import an OSIS bible - success = self.manager.import_bible(BibleFormat.OSIS, + importer = self.manager.import_bible(BibleFormat.OSIS, name=unicode(self.field(u'license_version').toString()), filename=unicode(self.field(u'osis_location').toString()) ) elif bible_type == BibleFormat.CSV: # Import a CSV bible - success = self.manager.import_bible(BibleFormat.CSV, + importer = self.manager.import_bible(BibleFormat.CSV, name=unicode(self.field(u'license_version').toString()), booksfile=self.field(u'csv_booksfile').toString(), versefile=self.field(u'csv_versefile').toString() ) elif bible_type == BibleFormat.OpenSong: # Import an OpenSong bible - success = self.manager.import_bible(BibleFormat.OpenSong, + importer = self.manager.import_bible(BibleFormat.OpenSong, name=unicode(self.field(u'license_version').toString()), filename=self.field(u'opensong_file').toString() ) @@ -345,7 +345,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): elif download_location == DownloadLocation.BibleGateway: bible = self.web_bible_list[DownloadLocation.BibleGateway][ unicode(self.BibleComboBox.currentText())] - success = self.manager.import_bible(BibleFormat.WebDownload, + importer = self.manager.import_bible(BibleFormat.WebDownload, name=unicode(self.field(u'license_version').toString()), download_source=unicode(DownloadLocation.get_name(download_location)), download_name=unicode(bible), @@ -353,6 +353,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): proxy_username=unicode(self.field(u'proxy_username').toString()), proxy_password=unicode(self.field(u'proxy_password').toString()) ) + success = importer.do_import() if success: self.manager.save_meta_data( unicode(self.field(u'license_version').toString()), @@ -365,6 +366,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): else: self.ImportProgressLabel.setText( self.trUtf8('Your Bible import failed.')) + importer.delete() def postImport(self): self.ImportProgressBar.setValue(self.ImportProgressBar.maximum()) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 8f55fb5fc..d6a6d10ca 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -77,7 +77,6 @@ class BibleDB(QtCore.QObject): 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') @@ -109,6 +108,13 @@ class BibleDB(QtCore.QObject): old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_') return old_filename + u'.sqlite' + def delete(self): + try: + os.remove(self.db_file) + return True + except: + return False + def register(self, wizard): """ This method basically just initialialises the database. It is called diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 10ee7b9f9..e3647e129 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -165,7 +165,7 @@ class BibleManager(object): importer = class_(self.parent, **kwargs) name = importer.register(self.import_wizard) self.db_cache[name] = importer - return importer.do_import() + return importer def get_bibles(self): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index e4cb79e73..894feb8d8 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -114,12 +114,14 @@ class OSISBible(BibleDB): osis = codecs.open(self.filename, u'r', details['encoding']) last_chapter = 0 testament = 1 + match_count = 0 db_book = None for file_record in osis: if self.stop_import_flag: break match = self.verse_regex.search(file_record) if match: + match_count += 1 book = match.group(1) chapter = int(match.group(2)) verse = int(match.group(3)) @@ -166,6 +168,8 @@ class OSISBible(BibleDB): Receiver.send_message(u'process_events') self.commit() self.wizard.incrementProgressBar(u'Finishing import...') + if match_count == 0: + success = False except: log.exception(u'Loading bible from OSIS file failed') success = False From 916987052026022eeed37fb6ce74fca17b300302 Mon Sep 17 00:00:00 2001 From: rimach Date: Sat, 20 Mar 2010 00:02:23 +0100 Subject: [PATCH 12/16] make Blank button workable --- openlp/core/ui/maindisplay.py | 11 ++++++++++- openlp/core/ui/slidecontroller.py | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index e59ce2060..f77d0a841 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -226,6 +226,7 @@ class MainDisplay(DisplayWidget): ``frame`` Image frame to be rendered """ + log.debug(u'frameView %d' % (self.displayBlank)) if not self.displayBlank: if transition: if self.frame is not None: @@ -248,14 +249,22 @@ class MainDisplay(DisplayWidget): if not self.isVisible(): self.setVisible(True) self.showFullScreen() + else: + self.waitingFrame = frame + self.waitingFrameTrans = transition def blankDisplay(self, blanked=True): + log.debug(u'Blank main Display %d' % blanked) if blanked: self.displayBlank = True self.display_text.setPixmap(QtGui.QPixmap.fromImage(self.blankFrame)) + self.waitingFrame = None + self.waitingFrameTrans = False else: self.displayBlank = False - if self.display_frame: + if self.waitingFrame: + self.frameView(self.waitingFrame, self.waitingFrameTrans) + elif self.display_frame: self.frameView(self.display_frame) def onMediaQueue(self, message): diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 0af64819a..08583cb54 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -524,6 +524,7 @@ class SlideController(QtGui.QWidget): """ Handle the blank screen button """ + log.debug(u'onBlankDisplay %d' % force) if force: self.blankButton.setChecked(True) self.blankScreen(self.blankButton.isChecked()) @@ -540,6 +541,8 @@ class SlideController(QtGui.QWidget): Receiver.send_message(u'%s_blank'% self.serviceItem.name.lower()) else: Receiver.send_message(u'%s_unblank'% self.serviceItem.name.lower()) + else: + self.parent.mainDisplay.blankDisplay(blanked) else: self.parent.mainDisplay.blankDisplay(blanked) From 848eb601af248a8b4e74546b73ebdb1a3a304abd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Mar 2010 14:24:41 +0000 Subject: [PATCH 13/16] Fix NONE appearing as song verses Delay the hidden window display Fix missing add status for custom slides --- openlp/core/lib/songxmlhandler.py | 4 ++++ openlp/core/ui/mainwindow.py | 7 ++++++- openlp/plugins/custom/forms/editcustomform.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/songxmlhandler.py b/openlp/core/lib/songxmlhandler.py index 7a532970d..076523545 100644 --- a/openlp/core/lib/songxmlhandler.py +++ b/openlp/core/lib/songxmlhandler.py @@ -147,9 +147,13 @@ class SongXMLParser(object): iter = self.song_xml.getiterator() verse_list = [] for element in iter: + print element.tag, element.text if element.tag == u'verse': + if element.text is None: + element.text = u'' verse_list.append([element.attrib, unicode(element.text).decode('unicode-escape')]) + print verse_list return verse_list def dump_xml(self): diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index ab2eaf7d8..30530669c 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -67,7 +67,8 @@ class VersionThread(QtCore.QThread): """ Run the thread. """ - time.sleep(2) + time.sleep(1) + Receiver.send_message(u'blank_check') version = check_latest_version(self.generalConfig, self.app_version) #new version has arrived if version != self.app_version: @@ -493,6 +494,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'update_global_theme'), self.defaultThemeChanged) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'version_check'), self.versionCheck) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'blank_check'), self.blankCheck) QtCore.QObject.connect(self.FileNewItem, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onNewService) @@ -582,6 +585,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.activateWindow() if str_to_bool(self.generalConfig.get_config(u'auto open', False)): self.ServiceManagerContents.onLoadService(True) + + def blankCheck(self): if str_to_bool(self.generalConfig.get_config(u'screen blank', False)) \ and str_to_bool(self.generalConfig.get_config(u'blank warning', False)): self.LiveController.onBlankDisplay(True) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index b4402ceb3..bb2607a74 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -87,6 +87,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): def initialise(self): self.editAll = False + self.AddButton.setEnabled(True) self.DeleteButton.setEnabled(False) self.EditButton.setEnabled(False) self.EditAllButton.setEnabled(True) From 8f692d13be2abe0e56f5342cfdbf768f3b0627e8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Mar 2010 14:30:18 +0000 Subject: [PATCH 14/16] Remove prints --- openlp/core/lib/songxmlhandler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openlp/core/lib/songxmlhandler.py b/openlp/core/lib/songxmlhandler.py index 076523545..12b0c2d47 100644 --- a/openlp/core/lib/songxmlhandler.py +++ b/openlp/core/lib/songxmlhandler.py @@ -147,13 +147,11 @@ class SongXMLParser(object): iter = self.song_xml.getiterator() verse_list = [] for element in iter: - print element.tag, element.text if element.tag == u'verse': if element.text is None: element.text = u'' verse_list.append([element.attrib, unicode(element.text).decode('unicode-escape')]) - print verse_list return verse_list def dump_xml(self): From 2d43cd2d8a19d9b1dd089b4af13a996f8342bf37 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Mar 2010 15:08:46 +0000 Subject: [PATCH 15/16] Stop double loading of service items --- openlp/core/ui/slidecontroller.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 08583cb54..b6392a4d7 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -419,6 +419,11 @@ class SlideController(QtGui.QWidget): Called by ServiceManager """ log.debug(u'addServiceManagerItem') + #If service item is the same as the current on only change slide + if item.__eq__(self.serviceItem): + self.PreviewListWidget.selectRow(slideno) + self.onSlideSelected() + return #If old item was a command tell it to stop if self.serviceItem and self.serviceItem.is_command(): self.onMediaStop() From 3e4683bd6dff627eb82ad492f4ea31c8fd545055 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Mar 2010 17:56:56 +0000 Subject: [PATCH 16/16] Fix up issues and confusion with service item edit --- openlp/core/ui/slidecontroller.py | 37 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index b6392a4d7..51ad5b6b9 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -403,14 +403,14 @@ class SlideController(QtGui.QWidget): if self.songEdit: slideno = self.selectedRow self.songEdit = False - self.addServiceManagerItem(item, slideno) + self._processItem(item, slideno) def replaceServiceManagerItem(self, item): """ Replacement item following a remote edit """ if item.__eq__(self.serviceItem): - self.addServiceManagerItem(item, self.PreviewListWidget.currentRow()) + self._processItem(item, self.PreviewListWidget.currentRow()) def addServiceManagerItem(self, item, slideno): """ @@ -424,27 +424,27 @@ class SlideController(QtGui.QWidget): self.PreviewListWidget.selectRow(slideno) self.onSlideSelected() return - #If old item was a command tell it to stop - if self.serviceItem and self.serviceItem.is_command(): - self.onMediaStop() - if item.is_media(): - self.onMediaStart(item) - elif item.is_command(): - if self.isLive: - blanked = self.blankButton.isChecked() - else: - blanked = False - Receiver.send_message(u'%s_start' % item.name.lower(), \ - [item.title, item.service_item_path, - item.get_frame_title(), slideno, self.isLive, blanked]) - self.displayServiceManagerItems(item, slideno) + self._processItem(item, slideno) - def displayServiceManagerItems(self, serviceItem, slideno): + def _processItem(self, serviceItem, slideno): """ Loads a ServiceItem into the system from ServiceManager Display the slide number passed """ - log.debug(u'displayServiceManagerItems Start') + log.debug(u'processsManagerItem') + #If old item was a command tell it to stop + if self.serviceItem and self.serviceItem.is_command(): + self.onMediaStop() + if serviceItem.is_media(): + self.onMediaStart(serviceItem) + elif serviceItem.is_command(): + if self.isLive: + blanked = self.blankButton.isChecked() + else: + blanked = False + Receiver.send_message(u'%s_start' % serviceItem.name.lower(), \ + [serviceItem.title, serviceItem.service_item_path, + serviceItem.get_frame_title(), slideno, self.isLive, blanked]) self.slideList = {} width = self.parent.ControlSplitter.sizes()[self.split] #Set pointing cursor when we have somthing to point at @@ -508,7 +508,6 @@ class SlideController(QtGui.QWidget): log.log(15, u'Display Rendering took %4s' % (time.time() - before)) if self.isLive: self.serviceItem.request_audit() - log.debug(u'displayServiceManagerItems End') #Screen event methods def onSlideSelectedFirst(self):