options/config management basically working
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2521 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
87ec9a2860
commit
e7b83a83ad
8 changed files with 80 additions and 15 deletions
|
@ -34,9 +34,6 @@ Options Adapters
|
||||||
Global and site options
|
Global and site options
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
>>> from loops.config.base import LoopsOptions
|
|
||||||
>>> component.provideAdapter(LoopsOptions)
|
|
||||||
|
|
||||||
>>> from cybertools.meta.interfaces import IOptions
|
>>> from cybertools.meta.interfaces import IOptions
|
||||||
>>> opt = IOptions(loopsRoot)
|
>>> opt = IOptions(loopsRoot)
|
||||||
>>> opt
|
>>> opt
|
||||||
|
@ -49,15 +46,16 @@ some options.
|
||||||
|
|
||||||
>>> loopsRoot.options = ['useVersioning', 'organize.tracking:changes, access']
|
>>> loopsRoot.options = ['useVersioning', 'organize.tracking:changes, access']
|
||||||
>>> opt = IOptions(loopsRoot)
|
>>> opt = IOptions(loopsRoot)
|
||||||
>>> print opt
|
|
||||||
organize(tracking=['changes', 'access'])
|
|
||||||
useVersioning=True
|
|
||||||
|
|
||||||
>>> opt.organize.tracking
|
>>> opt.organize.tracking
|
||||||
['changes', 'access']
|
['changes', 'access']
|
||||||
>>> opt.useVersioning
|
>>> opt.useVersioning
|
||||||
True
|
True
|
||||||
|
|
||||||
|
>>> print opt
|
||||||
|
organize(tracking=['changes', 'access'])
|
||||||
|
useVersioning=True
|
||||||
|
|
||||||
If we query an option that is not defined on the site level we get a
|
If we query an option that is not defined on the site level we get a
|
||||||
dummy element that corresponds to False.
|
dummy element that corresponds to False.
|
||||||
|
|
||||||
|
@ -66,6 +64,26 @@ dummy element that corresponds to False.
|
||||||
>>> bool(opt.i18n.languages)
|
>>> bool(opt.i18n.languages)
|
||||||
False
|
False
|
||||||
|
|
||||||
|
We can use a utility for providing global settings.
|
||||||
|
|
||||||
|
>>> from cybertools.meta.interfaces import IOptions
|
||||||
|
>>> globalOpt = component.getUtility(IOptions)
|
||||||
|
>>> globalOpt.i18n.languages = ['en', 'de']
|
||||||
|
>>> globalOpt.i18n.languages
|
||||||
|
['en', 'de']
|
||||||
|
|
||||||
|
If we call the site options with the key we want to query the global
|
||||||
|
options will be used as a fallback.
|
||||||
|
|
||||||
|
>>> opt('i18n.languages')
|
||||||
|
['en', 'de']
|
||||||
|
|
||||||
|
User options (preferences)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Type- and object-based settings
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
|
||||||
Fin de partie
|
Fin de partie
|
||||||
=============
|
=============
|
||||||
|
|
|
@ -22,15 +22,26 @@ Adapters and others classes for analyzing resources.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope import component
|
from zope import component
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.traversing.api import getName, getParent
|
from zope.traversing.api import getName, getParent
|
||||||
|
|
||||||
from cybertools.meta.config import Options
|
from cybertools.meta.config import Options
|
||||||
|
from cybertools.meta.config import GlobalOptions as BaseGlobalOptions
|
||||||
|
from cybertools.meta.interfaces import IOptions
|
||||||
from cybertools.meta.namespace import Executor, ExecutionError
|
from cybertools.meta.namespace import Executor, ExecutionError
|
||||||
from cybertools.typology.interfaces import IType
|
from cybertools.typology.interfaces import IType
|
||||||
from loops.interfaces import ILoops
|
from loops.interfaces import ILoops
|
||||||
|
from loops import util
|
||||||
|
|
||||||
|
|
||||||
|
class GlobalOptions(BaseGlobalOptions):
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def _filename(self):
|
||||||
|
return os.path.join(util.getEtcDirectory(), 'loops.cfg')
|
||||||
|
|
||||||
|
|
||||||
class LoopsOptions(Options):
|
class LoopsOptions(Options):
|
||||||
|
@ -39,11 +50,24 @@ class LoopsOptions(Options):
|
||||||
|
|
||||||
builtins = Options.builtins + ('True', 'False')
|
builtins = Options.builtins + ('True', 'False')
|
||||||
True, False = True, False
|
True, False = True, False
|
||||||
|
_initialized = False
|
||||||
|
|
||||||
def __init__(self, context, *args, **kw):
|
def __init__(self, context, *args, **kw):
|
||||||
self.context = context
|
self.context = context
|
||||||
super(LoopsOptions, self).__init__(*args, **kw)
|
super(LoopsOptions, self).__init__(*args, **kw)
|
||||||
self.loadContextOptions()
|
#self.loadContextOptions()
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
if not self._initialized:
|
||||||
|
self._initialized = True
|
||||||
|
self.loadContextOptions()
|
||||||
|
return super(LoopsOptions, self).__getitem__(key)
|
||||||
|
|
||||||
|
def __call__(self, key, default=None):
|
||||||
|
value = super(LoopsOptions, self).__call__(key)
|
||||||
|
if value is None:
|
||||||
|
value = component.getUtility(IOptions)(key, default)
|
||||||
|
return value
|
||||||
|
|
||||||
def parseContextOptions(self):
|
def parseContextOptions(self):
|
||||||
def result():
|
def result():
|
||||||
|
@ -61,8 +85,4 @@ class LoopsOptions(Options):
|
||||||
code = self.parseContextOptions()
|
code = self.parseContextOptions()
|
||||||
rc = Executor(self).execute(code)
|
rc = Executor(self).execute(code)
|
||||||
if rc:
|
if rc:
|
||||||
raise ExecutionError('\n' + result)
|
raise ExecutionError('\n' + rc)
|
||||||
|
|
||||||
#def __getitem__(self, key):
|
|
||||||
# opt = self.baseOptions.get(key)
|
|
||||||
# return opt
|
|
||||||
|
|
15
config/configure.zcml
Normal file
15
config/configure.zcml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<!-- $Id$ -->
|
||||||
|
|
||||||
|
<configure
|
||||||
|
xmlns:zope="http://namespaces.zope.org/zope"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser"
|
||||||
|
i18n_domain="zope">
|
||||||
|
|
||||||
|
<zope:utility factory="loops.config.base.GlobalOptions" />
|
||||||
|
|
||||||
|
<zope:adapter factory="loops.config.base.LoopsOptions" trusted="True" />
|
||||||
|
<zope:class class="loops.config.base.LoopsOptions">
|
||||||
|
<allow interface="cybertools.meta.interfaces.IOptions" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
|
</configure>
|
|
@ -400,6 +400,7 @@
|
||||||
<include package=".browser" />
|
<include package=".browser" />
|
||||||
<include package=".classifier" />
|
<include package=".classifier" />
|
||||||
<include package=".compound.blog" />
|
<include package=".compound.blog" />
|
||||||
|
<include package=".config" />
|
||||||
<include package=".constraint" />
|
<include package=".constraint" />
|
||||||
<include package=".external" />
|
<include package=".external" />
|
||||||
<include package=".i18n" />
|
<include package=".i18n" />
|
||||||
|
|
|
@ -48,6 +48,8 @@ Recording changes to objects
|
||||||
>>> from loops.organize.tracking.change import recordModification
|
>>> from loops.organize.tracking.change import recordModification
|
||||||
>>> component.provideHandler(recordModification)
|
>>> component.provideHandler(recordModification)
|
||||||
|
|
||||||
|
>>> loopsRoot.options = ['organize.tracking:changes']
|
||||||
|
|
||||||
>>> tTask = concepts['task']
|
>>> tTask = concepts['task']
|
||||||
>>> from loops.concept import Concept
|
>>> from loops.concept import Concept
|
||||||
>>> from loops.setup import addAndConfigureObject
|
>>> from loops.setup import addAndConfigureObject
|
||||||
|
|
|
@ -28,6 +28,7 @@ from zope.cachedescriptors.property import Lazy
|
||||||
from zope.component import adapter
|
from zope.component import adapter
|
||||||
from zope.lifecycleevent.interfaces import IObjectModifiedEvent, IObjectCreatedEvent
|
from zope.lifecycleevent.interfaces import IObjectModifiedEvent, IObjectCreatedEvent
|
||||||
|
|
||||||
|
from cybertools.meta.interfaces import IOptions
|
||||||
from cybertools.tracking.btree import Track, getTimeStamp
|
from cybertools.tracking.btree import Track, getTimeStamp
|
||||||
from loops.concept import ConceptManager
|
from loops.concept import ConceptManager
|
||||||
from loops.resource import ResourceManager
|
from loops.resource import ResourceManager
|
||||||
|
@ -49,14 +50,15 @@ class ChangeManager(object):
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def options(self):
|
def options(self):
|
||||||
return IOptions(self.context)
|
#return IOptions(self.context)
|
||||||
|
return IOptions(self.loopsRoot)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def valid(self):
|
def valid(self):
|
||||||
return not (self.context is None or
|
return (not (self.context is None or
|
||||||
self.storage is None or
|
self.storage is None or
|
||||||
self.person is None)
|
self.person is None)
|
||||||
# and 'changes' in self.options.tracking
|
and 'changes' in self.options('organize.tracking', ()))
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def loopsRoot(self):
|
def loopsRoot(self):
|
||||||
|
|
|
@ -47,6 +47,7 @@ from loops.browser.node import ViewPropertiesConfigurator
|
||||||
from loops.common import NameChooser
|
from loops.common import NameChooser
|
||||||
from loops.concept import Concept
|
from loops.concept import Concept
|
||||||
from loops.concept import IndexAttributes as ConceptIndexAttributes
|
from loops.concept import IndexAttributes as ConceptIndexAttributes
|
||||||
|
from loops.config.base import GlobalOptions, LoopsOptions
|
||||||
from loops.interfaces import ILoopsObject, IIndexAttributes
|
from loops.interfaces import ILoopsObject, IIndexAttributes
|
||||||
from loops.interfaces import IDocument, IFile, ITextDocument
|
from loops.interfaces import IDocument, IFile, ITextDocument
|
||||||
from loops.organize.memberinfo import MemberInfoProvider
|
from loops.organize.memberinfo import MemberInfoProvider
|
||||||
|
@ -119,6 +120,8 @@ class TestSite(object):
|
||||||
component.provideHandler(grantAcquiredSecurity)
|
component.provideHandler(grantAcquiredSecurity)
|
||||||
component.provideHandler(revokeAcquiredSecurity)
|
component.provideHandler(revokeAcquiredSecurity)
|
||||||
component.provideAdapter(BaseSecuritySetter)
|
component.provideAdapter(BaseSecuritySetter)
|
||||||
|
component.provideAdapter(LoopsOptions)
|
||||||
|
component.provideUtility(GlobalOptions())
|
||||||
|
|
||||||
component.provideAdapter(Instance)
|
component.provideAdapter(Instance)
|
||||||
component.provideAdapter(Editor, name='editor')
|
component.provideAdapter(Editor, name='editor')
|
||||||
|
|
4
util.py
4
util.py
|
@ -108,3 +108,7 @@ def getVarDirectory(request=None):
|
||||||
os.path.dirname(cybertools.__file__))))
|
os.path.dirname(cybertools.__file__))))
|
||||||
varDir = os.path.join(instanceHome, 'var')
|
varDir = os.path.join(instanceHome, 'var')
|
||||||
return varDir
|
return varDir
|
||||||
|
|
||||||
|
def getEtcDirectory(request=None):
|
||||||
|
varDir = getVarDirectory(request)
|
||||||
|
return os.path.join(os.path.dirname(varDir), 'etc')
|
||||||
|
|
Loading…
Add table
Reference in a new issue