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 #
###############################################################################
import os
import logging
import time

View File

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

View File

@ -29,6 +29,8 @@ import logging
import urllib2
from datetime import datetime
import openlp
log = logging.getLogger(__name__)
class AppLocation(object):
@ -43,7 +45,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 +73,19 @@ 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(
os.path.split(openlp.__file__)[0], u'plugins')
return plugin_path
def check_latest_version(config, current_version):

View File

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

View File

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

View File

@ -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,62 @@ 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'<sup class=\"versenum'
verseFootnote = u'<sup class=\'footnote'
verse = 1
i = xml_string.find(u'result-text-style-normal') + 26
xml_string = xml_string[i:len(xml_string)]
versePos = xml_string.find(verseSearch)
bible = {}
while versePos > -1:
# clear out string
verseText = u''
versePos = xml_string.find(u'</sup>', versePos) + 6
i = xml_string.find(verseSearch, versePos + 1)
# Not sure if this is needed now
if i == -1:
i = xml_string.find(u'</div', versePos + 1)
j = xml_string.find(u'<strong', versePos + 1)
if j > 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'</sup>')
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)
# 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
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'&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):
log.info(u'%s CWExtract loaded', __name__)

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=OpenLP 2.0
AllowNoIcons=true
LicenseFile=LICENSE.txt
OutputBaseFilename=OpenLP-1.9.0-bzr737-setup
OutputBaseFilename=OpenLP-1.9.0-bzr739-setup
Compression=lzma
SolidCompression=true
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.pptviewcontroller']

View File

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

View File

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