Changes from Head

This commit is contained in:
Tim Bentley 2009-07-08 17:41:43 +01:00
commit b2f9f24120
5 changed files with 133 additions and 69 deletions

View File

@ -51,7 +51,7 @@ class PluginConfig(object):
return ConfigHelper.set_config(self.section, key, value) return ConfigHelper.set_config(self.section, key, value)
def get_data_path(self): def get_data_path(self):
app_data = ConfigHelper.get_data_path() #app_data = ConfigHelper.get_data_path()
app_data = ConfigHelper.get_data_path() app_data = ConfigHelper.get_data_path()
safe_name = self.section.replace(u' ',u'-') safe_name = self.section.replace(u' ',u'-')
plugin_data = self.get_config(u'data path', safe_name) plugin_data = self.get_config(u'data path', safe_name)

View File

@ -53,7 +53,7 @@ class PluginManager(object):
""" """
self.plugin_helpers = plugin_helpers self.plugin_helpers = plugin_helpers
startdepth = len(os.path.abspath(dir).split(os.sep)) startdepth = len(os.path.abspath(dir).split(os.sep))
log.debug(u'find plugins %s at depth %d' %( unicode(dir), startdepth)) log.debug(u'find plugins %s at depth %d', unicode(dir), startdepth)
for root, dirs, files in os.walk(dir): for root, dirs, files in os.walk(dir):
for name in files: for name in files:
@ -69,34 +69,46 @@ class PluginManager(object):
modulename = modulename[len(prefix) + 1:] modulename = modulename[len(prefix) + 1:]
modulename = modulename.replace(os.path.sep, '.') modulename = modulename.replace(os.path.sep, '.')
# import the modules # import the modules
log.debug(u'Importing %s from %s. Depth %d' % (modulename, path, thisdepth)) log.debug(u'Importing %s from %s. Depth %d', modulename, path, thisdepth)
try: try:
__import__(modulename, globals(), locals(), []) __import__(modulename, globals(), locals(), [])
except ImportError, e: except ImportError, e:
log.error(u'Failed to import module %s on path %s for reason %s', modulename, path, sys.exc_info()[1]) log.error(u'Failed to import module %s on path %s for reason %s', modulename, path, e.args[0])
self.plugin_classes = Plugin.__subclasses__() self.plugin_classes = Plugin.__subclasses__()
self.plugins = [] self.plugins = []
plugin_objects = [] plugin_objects = []
for p in self.plugin_classes: for p in self.plugin_classes:
try: try:
plugin = p(self.plugin_helpers) plugin = p(self.plugin_helpers)
log.debug(u'loaded plugin %s with helpers'%unicode(p)) log.debug(u'loaded plugin %s with helpers', unicode(p))
log.debug(u'Plugin: %s', unicode(p)) log.debug(u'Plugin: %s', unicode(p))
if plugin.check_pre_conditions(): if plugin.check_pre_conditions():
log.debug(u'Appending %s ', unicode(p)) log.debug(u'Appending %s ', unicode(p))
plugin_objects.append(plugin) plugin_objects.append(plugin)
eventmanager.register(plugin) eventmanager.register(plugin)
except TypeError: except TypeError:
log.error(u'loaded plugin %s has no helpers'%unicode(p)) log.error(u'loaded plugin %s has no helpers', unicode(p))
self.plugins = sorted(plugin_objects, self.order_by_weight) self.plugins = sorted(plugin_objects, self.order_by_weight)
def order_by_weight(self, x, y): def order_by_weight(self, x, y):
"""
Sort two plugins and order them by their weight.
``x``
The first plugin.
``y``
The second plugin.
"""
return cmp(x.weight, y.weight) return cmp(x.weight, y.weight)
def hook_media_manager(self, mediatoolbox): def hook_media_manager(self, mediatoolbox):
""" """
Loop through all the plugins. If a plugin has a valid media manager item, Loop through all the plugins. If a plugin has a valid media manager item,
add it to the media manager. add it to the media manager.
``mediatoolbox``
The Media Manager itself.
""" """
for plugin in self.plugins: for plugin in self.plugins:
media_manager_item = plugin.get_media_manager_item() media_manager_item = plugin.get_media_manager_item()
@ -140,3 +152,4 @@ class PluginManager(object):
""" """
for plugin in self.plugins: for plugin in self.plugins:
plugin.initialise() plugin.initialise()

View File

@ -19,93 +19,140 @@ import os
import os.path import os.path
import sys import sys
import urllib2 import urllib2
import chardet
import logging import logging
class SearchResults: class SearchResults:
"""
Encapsulate a set of search results. This is Bible-type independant.
"""
def __init__(self, book, chapter, verselist): def __init__(self, book, chapter, verselist):
"""
Create the search result object.
``book``
The book of the Bible.
``chapter``
The chapter of the book.
``verselist``
The list of verses for this reading
"""
self.book = book self.book = book
self.chapter = chapter self.chapter = chapter
self.verselist = verselist self.verselist = verselist
def get_verselist(self):
return self.verselist
def get_book(self):
return self.book
def get_chapter(self):
return self.chapter
def has_verselist(self):
if self.verselist == {}:
return False
else:
return True
class BibleCommon: def get_verselist(self):
"""
Returns the list of verses.
"""
return self.verselist
def get_book(self):
"""
Returns the book of the Bible.
"""
return self.book
def get_chapter(self):
"""
Returns the chapter of the book.
"""
return self.chapter
def has_verselist(self):
"""
Returns whether or not the verse list contains verses.
"""
return len(self.verselist) > 0
class BibleCommon(object):
"""
A common ancestor for bible download sites.
"""
global log global log
log = logging.getLogger(u'BibleCommon') log = logging.getLogger(u'BibleCommon')
log.info(u'BibleCommon') log.info(u'BibleCommon')
def __init__(self): def __init__(self):
""" """
An empty constructor... not sure why I'm here.
""" """
pass
def _get_web_text(self, urlstring, proxyurl): def _get_web_text(self, urlstring, proxyurl):
"""
Get the HTML from the web page.
``urlstring``
The URL of the page to open.
``proxyurl``
The URL of a proxy server used to access the Internet.
"""
log.debug(u'get_web_text %s %s', proxyurl, urlstring) log.debug(u'get_web_text %s %s', proxyurl, urlstring)
if not proxyurl == None: if proxyurl is not None:
proxy_support = urllib2.ProxyHandler({'http': self.proxyurl}) proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
http_support = urllib2.HTTPHandler() http_support = urllib2.HTTPHandler()
opener= urllib2.build_opener(proxy_support, http_support) opener = urllib2.build_opener(proxy_support, http_support)
urllib2.install_opener(opener) urllib2.install_opener(opener)
xml_string = u'' xml_string = u''
req = urllib2.Request(urlstring) req = urllib2.Request(urlstring)
req.add_header(u'User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)') req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
try: try:
handle = urllib2.urlopen(req) handle = urllib2.urlopen(req)
xml_string = unicode(handle.read()) html = handle.read()
details = chardet.detect(html)
xml_string = unicode(html, details['encoding'])
except IOError, e: except IOError, e:
if hasattr(e, u'reason'): if hasattr(e, u'reason'):
log.error(u'Reason : ') log.error(u'Reason : %s', e.reason)
log.error( e.reason)
return xml_string return xml_string
def _clean_text(self, text): def _clean_text(self, text):
""" """
Clean up text and remove extra characters Clean up text and remove extra characters after been downloaded from
after been downloaded from web the Internet.
``text``
The text from the web page that needs to be cleaned up.
""" """
#return text.rstrip() #return text.rstrip()
# Remove Headings from the Text # Remove Headings from the Text
i = text.find(u'<h') start_tag = text.find(u'<h')
while i > -1: while start_tag > -1:
j=text.find(u'</h', i) end_tag = text.find(u'</h', start_tag)
text = text[ : (i - 1)]+text[(j+4)] text = text[:(start_tag - 1)] + text[(end_tag + 4)]
i = text.find(u'<h') start_tag = text.find(u'<h')
# Remove Support References from the Text # Remove Support References from the Text
x = text.find(u'<sup>') start_tag = text.find(u'<sup>')
while x > -1: while start_tag > -1:
y = text.find(u'</sup>') end_tag = text.find(u'</sup>')
text= text[:x] + text[y + 6:len(text)] text = text[:start_tag] + text[end_tag + 6:len(text)]
x = text.find(u'<sup>') start_tag = text.find(u'<sup>')
# Static Clean ups # Static Clean ups
text= text.replace(u'\n', u'') text = text.replace(u'\n', u'')
text= text.replace(u'\r', u'') text = text.replace(u'\r', u'')
text= text.replace(u'&nbsp;', u'') text = text.replace(u'&nbsp;', u'')
text= text.replace(u'<P>', u'') text = text.replace(u'<P>', u'')
text= text.replace(u'<I>', u'') text = text.replace(u'<I>', u'')
text= text.replace(u'</I>', u'') text = text.replace(u'</I>', u'')
text= text.replace(u'<P />', u'') text = text.replace(u'<P />', u'')
text= text.replace(u'<p />', u'') text = text.replace(u'<p />', u'')
text= text.replace(u'</P>', u'') text = text.replace(u'</P>', u'')
text= text.replace(u'<BR>', u'') text = text.replace(u'<BR>', u'')
text= text.replace(u'<BR />', u'') text = text.replace(u'<BR />', u'')
#text= text.replace(chr(189), u'1/2');print "l" #text = text.replace(chr(189), u'1/2');print "l"
text= text.replace(u'&quot;', "'") text = text.replace(u'&quot;', u'\"')
text= text.replace(u'&apos;', "'") text = text.replace(u'&apos;', u'\'')
# Remove some other tags
i = text.find(u'<') start_tag = text.find(u'<')
while i > -1 : while start_tag > -1 :
j = text.find(u'>', i) end_tag = text.find(u'>', start_tag)
text= text[:i] + text[j+1:] text = text[:start_tag] + text[end_tag + 1:]
i = text.find(u'<') start_tag = text.find(u'<')
text = text.replace(u'>', u'')
text= text.replace(u'>', u'')
return text.rstrip() return text.rstrip()

View File

@ -42,8 +42,8 @@ class PresentationPlugin(Plugin):
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
def get_settings_tab(self): def get_settings_tab(self):
self.presentation_tab = PresentationTab() #self.presentation_tab = PresentationTab()
return self.presentation_tab return None #self.presentation_tab
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object
@ -54,3 +54,4 @@ class PresentationPlugin(Plugin):
log.debug('check_pre_conditions') log.debug('check_pre_conditions')
self.openoffice = Openoffice() self.openoffice = Openoffice()
return self.openoffice.checkOoPid() return self.openoffice.checkOoPid()

View File

@ -47,8 +47,7 @@ class SongManager():
self.db_url = u'' self.db_url = u''
db_type = self.config.get_config(u'db type', u'sqlite') db_type = self.config.get_config(u'db type', u'sqlite')
if db_type == u'sqlite': if db_type == u'sqlite':
self.db_url = u'sqlite:///' + self.config.get_data_path() + \ self.db_url = u'sqlite:///%s/songs.sqlite' % self.config.get_data_path()
u'/songs.sqlite'
else: else:
self.db_url = db_type + 'u://' + \ self.db_url = db_type + 'u://' + \
self.config.get_config(u'db username') + u':' + \ self.config.get_config(u'db username') + u':' + \
@ -73,13 +72,17 @@ class SongManager():
""" """
Searches the song title for keywords. Searches the song title for keywords.
""" """
return self.session.query(Song).filter(Song.search_title.like(u'%' + keywords + u'%')).order_by(Song.search_title.asc()).all() return self.session.query(Song).filter(
Song.search_title.like(u'%' + keywords + u'%')).order_by(
Song.search_title.asc()).all()
def search_song_lyrics(self, keywords): def search_song_lyrics(self, keywords):
""" """
Searches the song lyrics for keywords. Searches the song lyrics for keywords.
""" """
return self.session.query(Song).filter(Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(Song.search_lyrics.asc()).all() return self.session.query(Song).filter(
Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(
Song.search_lyrics.asc()).all()
def get_song_from_author(self, keywords): def get_song_from_author(self, keywords):
""" """