added loops.process - work in progress

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1276 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-07-28 11:24:53 +00:00
parent 3d472a943d
commit 2d21f273ad
9 changed files with 300 additions and 22 deletions

View file

@ -30,11 +30,11 @@
<allow
attributes="getSiteManager" />
<require
permission="zope.ManageServices"
attributes="setSiteManager" />
<require
permission="zope.View"
interface="zope.app.container.interfaces.IReadContainer" />
@ -46,7 +46,7 @@
<!--<require
permission="zope.View"
interface="loops.interfaces.ILoops" />-->
<require
permission="zope.View"
attributes="getLoopsUri loopsTraverse getConceptManager
@ -79,7 +79,7 @@
<require
permission="zope.View"
attributes="getTypePredicate getDefaultPredicate getTypeConcept" />
</content>
<interface
@ -242,22 +242,22 @@
for="loops.interfaces.INode"
provides="zope.app.dublincore.interfaces.IZopeDublinCore"
trusted="True" />
<adapter factory="loops.common.LoopsDCAdapter"
for="loops.interfaces.IConcept"
provides="zope.app.dublincore.interfaces.IZopeDublinCore"
trusted="True" />
<adapter factory="loops.common.LoopsDCAdapter"
for="loops.interfaces.IDocument"
provides="zope.app.dublincore.interfaces.IZopeDublinCore"
trusted="True" />
<adapter factory="loops.common.LoopsDCAdapter"
for="loops.interfaces.IMediaAsset"
provides="zope.app.dublincore.interfaces.IZopeDublinCore"
trusted="True" />
<class class="loops.common.LoopsDCAdapter">
<require like_class="zope.app.dublincore.annotatableadapter.ZDCAnnotatableAdapter" />
</class>
@ -265,16 +265,16 @@
<adapter factory="loops.concept.IndexAttributes" />
<adapter factory="loops.resource.IndexAttributes" />
<adapter factory="loops.resource.IndexableResource" />
<adapter factory="loops.resource.DocumentReadFileAdapter" />
<adapter factory="loops.resource.DocumentWriteFileAdapter" />
<adapter factory="loops.type.ConceptType" />
<adapter factory="loops.type.ResourceType" />
<adapter factory="loops.type.LoopsTypeManager" />
<adapter factory="loops.type.TypeConcept" />
<adapter factory="loops.query.QueryConcept" trusted="True" />
<class class="loops.query.QueryConcept">
<require permission="zope.View"
@ -283,7 +283,7 @@
set_schema="loops.query.IQueryConcept" />
</class>
<adapter factory="loops.setup.SetupManager" />
<adapter factory="loops.external.NodesLoader" />
<adapter factory="loops.external.NodesExporter" />
@ -318,6 +318,7 @@
<include package=".knowledge" />
<include package=".organize" />
<include package=".process" />
<include package=".browser" />
</configure>

75
process/README.txt Normal file
View file

@ -0,0 +1,75 @@
===============================================================
loops - Linked Objects for Organization and Processing Services
===============================================================
($Id$)
Note: This package depends on cybertools.knowledge and cybertools.organize.
Let's do some basic set up
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
>>> site = placefulSetUp(True)
>>> from zope import component, interface
>>> from zope.app import zapi
and setup a simple loops site with a concept manager and some concepts
(with all the type machinery, what in real life is done via standard
ZCML setup):
>>> from cybertools.relation.interfaces import IRelationRegistry
>>> from cybertools.relation.registry import DummyRelationRegistry
>>> relations = DummyRelationRegistry()
>>> component.provideUtility(relations, IRelationRegistry)
>>> from cybertools.typology.interfaces import IType
>>> from loops.interfaces import IConcept, ITypeConcept
>>> from loops.type import ConceptType, TypeConcept
>>> component.provideAdapter(ConceptType, (IConcept,), IType)
>>> component.provideAdapter(TypeConcept, (IConcept,), ITypeConcept)
>>> from loops.interfaces import ILoops
>>> from loops.setup import ISetupManager
>>> from loops.process.setup import SetupManager
>>> component.provideAdapter(SetupManager, (ILoops,), ISetupManager,
... name='process')
>>> from loops import Loops
>>> loopsRoot = site['loops'] = Loops()
>>> from loops.setup import SetupManager
>>> setup = SetupManager(loopsRoot)
>>> concepts, resources, views = setup.setup()
We need some type concepts for controlling the meaning of the concepts objects,
these have already been created during setup:
>>> process = concepts['process']
Manage processes
================
The classes used in this package are just adapters to IConcept.
>>> from loops.process.definition import ProcessDefinition
>>> from cybertools.process.interfaces import IProcessDefinition
>>> component.provideAdapter(ProcessDefinition, (IConcept,), IProcessDefinition)
We start with creating a process definition.
Note that in order to discern the concepts created
from their typeInterface adapters we here append a 'C' to the name of
the variables:
>>> from loops.concept import Concept
>>> myProcessC = concepts['myProcess'] = Concept(u'A Simple Process')
>>> myProcessC.conceptType = process
>>> myProcess = IProcessDefinition(myProcessC)
Fin de partie
=============
>>> placefulTearDown()

4
process/__init__.py Normal file
View file

@ -0,0 +1,4 @@
"""
$Id$
"""

27
process/configure.zcml Normal file
View file

@ -0,0 +1,27 @@
<!-- $Id$ -->
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope"
>
<!-- process/workflow management stuff -->
<zope:adapter factory="loops.process.definition.ProcessDefinition"
provides="cybertools.process.interfaces.IProcessDefinition"
trusted="True" />
<zope:class class="loops.process.definition.ProcessDefinition">
<require permission="zope.View"
interface="cybertools.process.interfaces.IProcessDefinition" />
<require permission="zope.ManageContent"
set_schema="cybertools.process.interfaces.IProcessDefinition" />
</zope:class>
<!-- setup -->
<zope:adapter factory="loops.process.setup.SetupManager"
name="process" />
</configure>

60
process/definition.py Normal file
View file

@ -0,0 +1,60 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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
#
"""
Adapters for IConcept providing interfaces from the
cybertools.knowledge package.
$Id$
"""
from zope import interface, component
from zope.app import zapi
from zope.component import adapts
from zope.interface import implements
from zope.cachedescriptors.property import Lazy
from cybertools.typology.interfaces import IType
from cybertools.process.interfaces import IProcessDefinition
from cybertools.process.definition import ProcessDefinition as BaseProcessDefinition
from loops.interfaces import IConcept
from loops.type import TypeInterfaceSourceList, AdapterBase
# register type interfaces - (TODO: use a function for this)
TypeInterfaceSourceList.typeInterfaces += (IProcessDefinition,)
class ProcessAdapterMixin(object):
@Lazy
def conceptManager(self):
return self.context.getLoopsRoot().getConceptManager()
@Lazy
def successorPred(self):
return self.conceptManager['successor']
class ProcessDefinition(AdapterBase, BaseProcessDefinition, ProcessAdapterMixin):
""" A typeInterface adapter for concepts of type 'process'.
"""
implements(IProcessDefinition)

33
process/interfaces.py Normal file
View file

@ -0,0 +1,33 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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
#
"""
Interfaces for process/workflow management with loops.
$Id$
"""
from zope.interface import Interface, Attribute
from zope import interface, component, schema
from zope.i18nmessageid import MessageFactory
from zope.security.proxy import removeSecurityProxy
from cybertools.process.interfaces import IProcessDefinition
_ = MessageFactory('zope')

50
process/setup.py Normal file
View file

@ -0,0 +1,50 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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
#
"""
Automatic setup of a loops site for the process package.
$Id$
"""
from zope.component import adapts
from zope.interface import implements, Interface
from cybertools.process.interfaces import IProcessDefinition
from loops.concept import Concept
from loops.interfaces import ITypeConcept
from loops.setup import SetupManager as BaseSetupManager
class SetupManager(BaseSetupManager):
def setup(self):
concepts = self.context.getConceptManager()
type = concepts.getTypeConcept()
predicate = concepts['predicate']
# type concepts:
process = self.addObject(concepts, Concept, 'process', title=u'Process',
conceptType=type)
processTypeAdapter = ITypeConcept(process)
if not processTypeAdapter.typeInterface:
processTypeAdapter.typeInterface = IProcessDefinition
# predicates:
successor = self.addObject(concepts, Concept, 'successor', title=u'successor',
conceptType=predicate)

24
process/tests.py Executable file
View file

@ -0,0 +1,24 @@
# $Id$
import unittest, doctest
from zope.testing.doctestunit import DocFileSuite
from zope.app.testing import ztapi
from zope.interface.verify import verifyClass
from loops.organize.party import Person
class Test(unittest.TestCase):
"Basic tests for the process sub-package."
def testSomething(self):
pass
def test_suite():
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
return unittest.TestSuite((
unittest.makeSuite(Test),
DocFileSuite('README.txt', optionflags=flags),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

22
type.py
View file

@ -39,9 +39,9 @@ from loops.resource import Resource, Document, MediaAsset
class LoopsType(BaseType):
adapts(ILoopsObject)
factoryMapping = dict(concept=Concept, resource=Resource)
containerMapping = dict(concept='concepts', resource='resources')
@ -60,7 +60,7 @@ class LoopsType(BaseType):
tp = self.typeProvider
typeName = tp is None and 'unknown' or str(zapi.getName(tp))
return ':'.join(('loops', self.qualifiers[0], typeName,))
@Lazy
def typeInterface(self):
adapter = zapi.queryAdapter(self.typeProvider, ITypeConcept)
@ -79,11 +79,11 @@ class LoopsType(BaseType):
if ti is None or not issubclass(ti, IResourceAdapter):
return ('concept',)
return ('resource',)
@Lazy
def factory(self):
return self.factoryMapping.get(self.qualifiers[0], Concept)
@Lazy
def defaultContainer(self):
return self.root[self.containerMapping.get(self.qualifiers[0], 'concept')]
@ -107,7 +107,7 @@ class LoopsTypeInfo(LoopsType):
class ConceptType(LoopsType):
""" The IType adapter for concept objects.
""" The IType adapter for concept objects.
Probably obsolete because all real stuff has gone to LoopsType.
"""
@ -186,7 +186,7 @@ class LoopsTypeManager(TypeManager):
return ConceptTypeInfo(self.context.loopsTraverse(token))
return ResourceTypeInfo(self.context, resolve(token))
@property
@property
def types(self):
return self.conceptTypes() + self.resourceTypes()
@ -277,10 +277,10 @@ class AdapterBase(object):
"""
adapts(IConcept)
_attributes = ('context', '__parent__', )
_schemas = list(IConcept)
def __init__(self, context):
self.context = context # to get the permission stuff right
self.__parent__ = context
@ -300,3 +300,7 @@ class AdapterBase(object):
if attr not in self._schemas:
raise AttributeError(attr)
def __eq__(self, other):
return self.context == other.context