Added setup.py

Added PluginConfig
Updated ConfigHelper
Updated Bible plugin to use plugin config object

bzr-revno: 171
This commit is contained in:
Raoul Snyman 2008-12-03 10:57:34 +00:00
parent e8430a95f9
commit 3ad3a14ffb
7 changed files with 103 additions and 42 deletions

View File

@ -18,10 +18,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from pluginconfig import PluginConfig
from plugin import Plugin from plugin import Plugin
from settingstab import SettingsTab from settingstab import SettingsTab
from mediamanageritem import MediaManagerItem from mediamanageritem import MediaManagerItem
from event import Event from event import Event
from xmlrootclass import XmlRootClass from xmlrootclass import XmlRootClass
__all__ = ['Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', 'XmlRootClass'] __all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event',
'XmlRootClass']

View File

@ -18,6 +18,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from lib import PluginConfig
class Plugin(object): class Plugin(object):
""" """
Base class for openlp plugins to inherit from. Base class for openlp plugins to inherit from.
@ -70,6 +72,7 @@ class Plugin(object):
self.Name = 'Plugin' self.Name = 'Plugin'
if version is not None: if version is not None:
self.Version = version self.Version = version
self.config = PluginConfig(self.Name)
#self.MediaManagerItem = None #self.MediaManagerItem = None
self.SettingsTab = None self.SettingsTab = None
self.ImportMenuItem = None self.ImportMenuItem = None

View File

@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os
from core.utils import ConfigHelper
class PluginConfig(object):
"""
This is a generic config helper for plugins.
"""
def __init__(self, plugin_name):
"""
Initialise the plugin config object, setting the section name to the
plugin name.
"""
self.section = plugin_name.lower()
def get_config(self, key, default=None):
"""
Get a configuration value from the configuration registry.
"""
return ConfigHelper.get_config(self.section, key, default)
def set_config(self, key, value):
"""
Set a configuration value in the configuration registry.
"""
return ConfigHelper.set_config(self.section, key, value)
def get_data_path(self):
app_data = ConfigHelper.get_data_path()
safe_name = self.section.replace(' ', '-')
plugin_data = self.get_config('data path', safe_name)
return os.path.join(app_data, plugin_data)
def set_data_path(self, path):
return self.set_config('data path', os.path.basename(path))

View File

@ -27,24 +27,22 @@ class ConfigHelper(object):
@staticmethod @staticmethod
def get_data_path(): def get_data_path():
reg = ConfigHelper.get_registry() reg = ConfigHelper.get_registry()
return reg.get_value('main', 'data_path') return reg.get_value('main', 'data path')
@staticmethod @staticmethod
def get_data_path(): def get_config(section, key, default=None):
reg = ConfigHelper.get_registry() reg = ConfigHelper.get_registry()
return reg.get_value('main', 'data_path') if reg.has_value(section, key):
return reg.get_value(section, key, default)
else:
return default
@staticmethod @staticmethod
def get_songs_file(): def set_config(section, key, value):
path = ConfigHelper.get_data_path() reg = ConfigHelper.get_registry()
songfile = os.path.join(path, "songs", "songs.olp") if not reg.has_section(section):
if os.path.exists(songfile): reg.create_section(section)
filename.set_filename(songfile) return reg.set_value(section, key, value)
print songfile
@staticmethod
def getBiblePath():
return os.path.join(ConfigHelper.getConfigPath(), "Data","Bibles")
@staticmethod @staticmethod
def get_registry(): def get_registry():

View File

@ -40,7 +40,7 @@ class BibleManager():
global log global log
log=logging.getLogger("BibleMgr") log=logging.getLogger("BibleMgr")
log.info("Bible manager loaded") log.info("Bible manager loaded")
def __init__(self): def __init__(self, path):
""" """
Finds all the bibles defined for the system Finds all the bibles defined for the system
Creates an Interface Object for each bible containing connection information Creates an Interface Object for each bible containing connection information
@ -51,7 +51,7 @@ class BibleManager():
log.debug( "Bible Initialising") log.debug( "Bible Initialising")
self.bibleDBCache = {} # dict of bible database classes self.bibleDBCache = {} # dict of bible database classes
self.bibleHTTPCache = {} # dict of bible http readers self.bibleHTTPCache = {} # dict of bible http readers
self.biblePath = ConfigHelper.getBiblePath() self.biblePath = path #ConfigHelper.getBiblePath()
self.dialogobject = None self.dialogobject = None
#log.debug( self.biblePath ) #log.debug( self.biblePath )
files = os.listdir(self.biblePath) files = os.listdir(self.biblePath)

View File

@ -31,7 +31,7 @@ class BiblePlugin(Plugin):
Plugin.__init__(self, 'Bible', '1.9.0') Plugin.__init__(self, 'Bible', '1.9.0')
self.Weight = -9 self.Weight = -9
#Register the bible Manager #Register the bible Manager
#self.biblemanager = BibleManager() #self.biblemanager = BibleManager(self.config.get_data_path())
self.textsearch = True self.textsearch = True
def getMediaManagerItem(self): def getMediaManagerItem(self):

4
setup.py Normal file
View File

@ -0,0 +1,4 @@
from setuptools import setup APP = ['openlp.pyw'] OPTIONS = {'argv_emulation': True, 'includes': ['sip', 'PyQt4']} setup(
name='openlp.org',
version='1.9.0',
url='http://www.openlp.org/', app=APP, options={'py2app': OPTIONS}, setup_requires=['py2app'], )