From 8063d211a91292d3901498d45d7a14037993c185 Mon Sep 17 00:00:00 2001 From: helmutm Date: Tue, 4 Aug 2009 19:26:52 +0000 Subject: [PATCH] rearrange configuration stuff git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3494 fd906abe-77d9-0310-91a1-e0d9ade77398 --- wiki/README.txt | 2 +- wiki/base/config.py | 41 ++++++++++++++++++++++++++++------------- wiki/interfaces.py | 33 +++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/wiki/README.txt b/wiki/README.txt index d673f7a..eb0bf0d 100644 --- a/wiki/README.txt +++ b/wiki/README.txt @@ -20,7 +20,7 @@ to make sure the btree-based tracking link manager will be used. >>> manager = WikiManager() >>> linkManagerName = 'tracking' - >>> manager.linkManager = linkManagerName + >>> manager.setConfig('linkManager', linkManagerName) >>> wiki = manager.addWiki(Wiki('demo_wiki')) >>> startPage = wiki.createPage('start_page') diff --git a/wiki/base/config.py b/wiki/base/config.py index 138a5e3..dc3b8fd 100644 --- a/wiki/base/config.py +++ b/wiki/base/config.py @@ -24,7 +24,18 @@ $Id$ from zope.interface import implements -from cybertools.wiki.interfaces import IWikiConfiguration +from cybertools.wiki.interfaces import IWikiConfigInfo, IWikiConfiguration + + +class WikiConfigInfo(dict): + + implements(IWikiConfigInfo) + + def set(self, functionality, value): + self[functionality] = value + + def __getattr__(self, attr): + return self.get(attr, None) class BaseConfiguration(object): @@ -33,31 +44,35 @@ class BaseConfiguration(object): implements(IWikiConfiguration) - parent = None - - writer = parser = None + _configInfo = None def getConfig(self, functionality): - c = self.get(functionality) + c = None + ci = self._configInfo + if ci is not None: + c = ci.get(functionality) if c is None: parent = self.getConfigParent() if parent is not None: return parent.getConfig(functionality) return c - def get(self, key, default=None): - return getattr(self, key, None) + def setConfig(self, functionality, value): + if self._configInfo is None: + self._configInfo = WikiConfigInfo() + self._configInfo.set(functionality, value) def getConfigParent(self): - return self.parent + return None class WikiConfiguration(BaseConfiguration): """ A global utility providing the default settings. """ - parser = 'docutils.rstx' - writer = 'docutils.html' - linkManager = 'basic' - - nodeProcessors = dict(reference=['default']) + _configInfo = WikiConfigInfo( + parser='docutils.rstx', + writer='docutils.html', + linkManager='basic', + nodeProcessors=dict(reference=['default']), + ) diff --git a/wiki/interfaces.py b/wiki/interfaces.py index 66002cc..64a1ed7 100644 --- a/wiki/interfaces.py +++ b/wiki/interfaces.py @@ -25,9 +25,8 @@ $Id$ from zope.interface import Interface, Attribute -class IWikiConfiguration(Interface): - """ Provides information about the implementations to be used for - the various kinds of wiki plug-ins. +class IWikiConfigInfo(Interface): + """ A collection of configuration settings. """ writer = Attribute('Plug-in component converting from internal tree ' @@ -35,16 +34,34 @@ class IWikiConfiguration(Interface): parser = Attribute('Plug-in component converting from text input ' 'format to internal tree format.') + def get(functionality): + """ Return the setting for the functionality given or None if not set. + """ + + def set(functionality, value): + """ Register the value given for the functionality given. + """ + + +class IWikiConfiguration(Interface): + """ Provides information about the implementations to be used for + the various kinds of wiki plug-ins. + """ + + def getConfig(functionality): + """ Return the name of the component that should used for the + functionality given. + """ + + def setConfig(functionality, value): + """ Register the value given for the functionality given. + """ + def getConfigParent(): """ Return the parent object in case this configuration does not provide configuration information for a certain functionality. """ - def getConfig(functionality): - """ Return the name of the plugin that should used for the - functionality given. - """ - class IWikiManager(Interface): """ Manages wikis and wiki-related objects, like plugins.