[Zope-CMF] Re: Abusing GenericSetup during traditional installs

yuppie y.2006_ at wcm-solutions.de
Mon Jul 31 07:10:40 EDT 2006


Hi Martin!

Martin Aspeli wrote:
> If anyone has a 
> more complete and concise code example for this use case, please let me 
> know.

Ok. Wrote a prototype for you.

HTH, Yuppie



import logging
import os

from zope.component import queryMultiAdapter
from zope.interface import implements
from Products.GenericSetup.interfaces import IBody
from Products.GenericSetup.interfaces import ISetupEnviron
from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition

from Products import MyProduct # XXX: adjust


class SetupEnviron(object):

     """Context for body im- and exporter.
     """

     implements(ISetupEnviron)

     def getLogger(self, name):
         return logging.getLogger('GenericSetup.%s' % name)

     def shouldPurge(self):
         return True


def install(self):
     wftool = getToolByName(self, 'portal_workflow')

     # create empty workflow
     obj_id = 'myWorkflow'
     wftool._setObject(obj_id, DCWorkflowDefinition(obj_id))
     obj = getattr(wftool, obj_id)

     # create import context
     environ = SetupEnviron()

     # get XML body
     product_path = os.path.split(MyProduct.__file__)[0]
     f_name = os.path.join(product_path, 'Extensions', 'definition.xml')
     f = file(f_name)
     body = f.read()
     f.close()

     # apply XML body to adapted workflow and environ
     adapted = queryMultiAdapter((obj, environ), IBody)
     adapted.body = body

     return 'done'



More information about the Zope-CMF mailing list