This commit is contained in:
Tim Bentley 2010-03-19 08:07:12 +00:00
commit b011104deb
15 changed files with 795 additions and 735 deletions

View File

@ -1 +1 @@
1.9.0-bzr722 1.9.0-bzr743

View File

@ -23,7 +23,6 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import os
import logging import logging
import time import time

View File

@ -28,7 +28,6 @@ import logging
from PyQt4 import QtGui from PyQt4 import QtGui
from openlp.core.ui import GeneralTab, ThemesTab from openlp.core.ui import GeneralTab, ThemesTab
from openlp.core.lib import Receiver
from settingsdialog import Ui_SettingsDialog from settingsdialog import Ui_SettingsDialog
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -45,7 +44,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
self.ThemesTab = ThemesTab(mainWindow) self.ThemesTab = ThemesTab(mainWindow)
self.addTab(u'Themes', self.ThemesTab) self.addTab(u'Themes', self.ThemesTab)
def addTab(self, name, tab): def addTab(self, name, tab):
log.info(u'Adding %s tab' % tab.tabTitle) log.info(u'Adding %s tab' % tab.tabTitle)
self.SettingsTabWidget.addTab(tab, tab.tabTitleVisible) self.SettingsTabWidget.addTab(tab, tab.tabTitleVisible)

View File

@ -29,6 +29,8 @@ import logging
import urllib2 import urllib2
from datetime import datetime from datetime import datetime
import openlp
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class AppLocation(object): class AppLocation(object):
@ -43,7 +45,7 @@ class AppLocation(object):
@staticmethod @staticmethod
def get_directory(dir_type): def get_directory(dir_type):
if dir_type == AppLocation.AppDir: 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: elif dir_type == AppLocation.ConfigDir:
if sys.platform == u'win32': if sys.platform == u'win32':
path = os.path.join(os.getenv(u'APPDATA'), u'openlp') path = os.path.join(os.getenv(u'APPDATA'), u'openlp')
@ -71,11 +73,19 @@ class AppLocation(object):
path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data') path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data')
return path return path
elif dir_type == AppLocation.PluginsDir: elif dir_type == AppLocation.PluginsDir:
plugin_path = None
app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
if hasattr(sys, u'frozen') and sys.frozen == 1: if sys.platform == u'win32':
return os.path.join(app_path, u'plugins') 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: else:
return os.path.join(app_path, u'openlp', u'plugins') plugin_path = os.path.join(
os.path.split(openlp.__file__)[0], u'plugins')
return plugin_path
def check_latest_version(config, current_version): def check_latest_version(config, current_version):

View File

@ -93,7 +93,6 @@ class BiblePlugin(Plugin):
'displayed on the screen during the service.') 'displayed on the screen during the service.')
return about_text return about_text
def can_delete_theme(self, theme): def can_delete_theme(self, theme):
if self.settings_tab.bible_theme == theme: if self.settings_tab.bible_theme == theme:
return False return False

View File

@ -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:

View File

@ -28,7 +28,7 @@ import urllib2
import os import os
import sqlite3 import sqlite3
from BeautifulSoup import BeautifulSoup from BeautifulSoup import BeautifulSoup, Tag, NavigableString
from openlp.core.lib import Receiver from openlp.core.lib import Receiver
from openlp.core.utils import AppLocation from openlp.core.utils import AppLocation
@ -146,44 +146,62 @@ class BGExtract(BibleCommon):
urlstring = u'http://www.biblegateway.com/passage/?search=%s+%s' \ urlstring = u'http://www.biblegateway.com/passage/?search=%s+%s' \
u'&version=%s' % (bookname, chapter, version) u'&version=%s' % (bookname, chapter, version)
log.debug(u'BibleGateway url = %s' % urlstring) log.debug(u'BibleGateway url = %s' % urlstring)
xml_string = self._get_web_text(urlstring, self.proxyurl) # Let's get the page, and then open it in BeautifulSoup, so as to
verseSearch = u'<sup class=\"versenum' # attempt to make "easy" work of bad HTML.
verseFootnote = u'<sup class=\'footnote' page = urllib2.urlopen(urlstring)
verse = 1 soup = BeautifulSoup(page)
i = xml_string.find(u'result-text-style-normal') + 26 verses = soup.find(u'div', u'result-text-style-normal')
xml_string = xml_string[i:len(xml_string)] verse_number = 0
versePos = xml_string.find(verseSearch) verse_list = {0: u''}
bible = {} # http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
while versePos > -1: # This is a PERFECT example of opening the Cthulu tag!
# clear out string # O Bible Gateway, why doth ye such horrific HTML produce?
verseText = u'' for verse in verses:
versePos = xml_string.find(u'</sup>', versePos) + 6 if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes':
i = xml_string.find(verseSearch, versePos + 1) break
# Not sure if this is needed now if isinstance(verse, Tag) and verse.name == u'sup' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] != u'versenum':
if i == -1: continue
i = xml_string.find(u'</div', versePos + 1) if isinstance(verse, Tag) and verse.name == u'p' and not verse.contents:
j = xml_string.find(u'<strong', versePos + 1) continue
if j > 0 and j < i: if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents:
i = j for item in verse.contents:
verseText = xml_string[versePos + 7 : i ] if isinstance(item, Tag) and (item.name == u'h4' or item.name == u'h5'):
# store the verse continue
bible[verse] = self._clean_text(verseText) if isinstance(item, Tag) and item.name == u'sup' and filter(lambda a: a[0] == u'class', item.attrs)[0][1] != u'versenum':
versePos = -1 continue
else: if isinstance(item, Tag) and item.name == u'p' and not item.contents:
verseText = xml_string[versePos: i] continue
start_tag = verseText.find(verseFootnote) if isinstance(item, Tag) and item.name == u'sup':
while start_tag > -1: verse_number = int(str(item.contents[0]))
end_tag = verseText.find(u'</sup>') verse_list[verse_number] = u''
verseText = verseText[:start_tag] + verseText[end_tag + 6:len(verseText)] continue
start_tag = verseText.find(verseFootnote) if isinstance(item, Tag) and item.name == u'font':
# Chop off verse and start again for subitem in item.contents:
xml_string = xml_string[i:] if isinstance(subitem, Tag) and subitem.name == u'sup' and filter(lambda a: a[0] == u'class', subitem.attrs)[0][1] != u'versenum':
#look for the next verse continue
versePos = xml_string.find(verseSearch) if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents:
# store the verse continue
bible[verse] = self._clean_text(verseText) if isinstance(subitem, Tag) and subitem.name == u'sup':
verse += 1 verse_number = int(str(subitem.contents[0]))
return SearchResults(bookname, chapter, bible) verse_list[verse_number] = u''
continue
if isinstance(subitem, NavigableString):
verse_list[verse_number] = verse_list[verse_number] + subitem.replace(u'&nbsp;', u' ')
continue
if isinstance(item, NavigableString):
verse_list[verse_number] = verse_list[verse_number] + item.replace(u'&nbsp;', 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'&nbsp;', 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]
# Finally, return the list of verses in a "SearchResults" object.
return SearchResults(bookname, chapter, verse_list)
class CWExtract(BibleCommon): class CWExtract(BibleCommon):
log.info(u'%s CWExtract loaded', __name__) log.info(u'%s CWExtract loaded', __name__)

View File

@ -24,7 +24,6 @@
############################################################################### ###############################################################################
import logging import logging
import os
from common import parse_reference from common import parse_reference
from opensong import OpenSongBible from opensong import OpenSongBible
@ -123,19 +122,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, name=name, config=self.config) 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')

View File

@ -45,6 +45,7 @@ class BibleListView(BaseListWithDnD):
def resizeEvent(self, event): def resizeEvent(self, event):
self.parent.onListViewResize(event.size().width(), event.size().width()) self.parent.onListViewResize(event.size().width(), event.size().width())
class BibleMediaItem(MediaManagerItem): class BibleMediaItem(MediaManagerItem):
""" """
This is the custom media manager item for Bibles. This is the custom media manager item for Bibles.
@ -65,6 +66,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 +459,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')]) if isinstance(reference, QtCore.QVariant):
book = unicode(reference[QtCore.QString('book')]) reference = reference.toPyObject()
chapter = unicode(reference[QtCore.QString('chapter')]) bible = self._decodeQtObject(reference, 'bible')
verse = unicode(reference[QtCore.QString('verse')]) book = self._decodeQtObject(reference, 'book')
text = unicode(reference[QtCore.QString('text')]) chapter = self._decodeQtObject(reference, 'chapter')
version = unicode(reference[QtCore.QString('version')]) verse = self._decodeQtObject(reference, 'verse')
copyright = unicode(reference[QtCore.QString('copyright')]) text = self._decodeQtObject(reference, 'text')
permission = unicode(reference[QtCore.QString('permission')]) 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:
@ -567,7 +576,7 @@ class BibleMediaItem(MediaManagerItem):
permission = u'' permission = u''
else: else:
permission = permission.value permission = permission.value
for count, verse in enumerate(self.search_results): for count, verse in enumerate(self.search_results):
bible_text = u' %s %d:%d (%s)' % \ bible_text = u' %s %d:%d (%s)' % \
(verse.book.name, verse.chapter, verse.verse, bible) (verse.book.name, verse.chapter, verse.verse, bible)
bible_verse = QtGui.QListWidgetItem(bible_text) bible_verse = QtGui.QListWidgetItem(bible_text)

View File

@ -102,7 +102,7 @@ class OpenSongBible(BibleDB):
finally: finally:
if file: if file:
file.close() file.close()
if self.stop_import: if self.stop_import_flag:
self.wizard.incrementProgressBar(u'Import canceled!') self.wizard.incrementProgressBar(u'Import canceled!')
return False return False
else: else:

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=OpenLP 2.0 DefaultGroupName=OpenLP 2.0
AllowNoIcons=true AllowNoIcons=true
LicenseFile=LICENSE.txt LicenseFile=LICENSE.txt
OutputBaseFilename=OpenLP-1.9.0-bzr737-setup OutputBaseFilename=OpenLP-1.9.0-bzr739-setup
Compression=lzma Compression=lzma
SolidCompression=true SolidCompression=true
SetupIconFile=C:\Program Files\Inno Setup 5\Examples\Setup.ico SetupIconFile=C:\Program Files\Inno Setup 5\Examples\Setup.ico

View File

@ -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.powerpointcontroller',
'openlp.plugins.presentations.lib.pptviewcontroller'] 'openlp.plugins.presentations.lib.pptviewcontroller']

View File

@ -1,4 +1,4 @@
hiddenimports = ['plugins.songs.songsplugin', hiddenimports = ['plugins.songs.songsplugin',
'plugins.bibles.bibleplugin', 'plugins.bibles.bibleplugin',
'plugins.presentations.presentationplugin', 'plugins.presentations.presentationplugin',
'plugins.media.mediaplugin', 'plugins.media.mediaplugin',

View File

@ -99,6 +99,8 @@ def main():
start_dir = os.path.abspath(u'..') start_dir = os.path.abspath(u'..')
for root, dirs, files in os.walk(start_dir): for root, dirs, files in os.walk(start_dir):
for file in files: for file in files:
if file.startswith(u'hook-') or file.startswith(u'test_'):
continue
if file.endswith(u'.py'): if file.endswith(u'.py'):
print u'Parsing "%s"' % file print u'Parsing "%s"' % file
parse_file(start_dir, os.path.join(root, file), strings) parse_file(start_dir, os.path.join(root, file), strings)