[CMF-checkins] CVS: CMF/CMFSetup - workflow.py:1.31
Yvo Schubbe
y.2004_ at wcm-solutions.de
Thu Nov 18 03:14:41 EST 2004
Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv9115/CMFSetup
Modified Files:
workflow.py
Log Message:
- fixed import of workflow bindings (http://collector.zope.org/CMF/265)
- converted the workflows.xml parsing to minidom
- added a 'typeinfo' dependency to the 'workflow' import step
=== CMF/CMFSetup/workflow.py 1.30 => 1.31 ===
--- CMF/CMFSetup/workflow.py:1.30 Wed Nov 10 08:12:20 2004
+++ CMF/CMFSetup/workflow.py Thu Nov 18 03:14:41 2004
@@ -16,7 +16,6 @@
"""
import re
-from xml.sax import parseString
from xml.dom.minidom import parseString as domParseString
from AccessControl import ClassSecurityInfo
@@ -28,7 +27,6 @@
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from permissions import ManagePortal
-from utils import HandlerBase
from utils import _xmldir
from utils import _getNodeAttribute
from utils import _queryNodeAttribute
@@ -294,10 +292,18 @@
""" Pseudo API.
"""
- parser = _WorkflowToolParser( encoding )
- parseString( xml, parser )
+ reader = getattr(xml, 'read', None)
+ if reader is not None:
+ xml = reader()
- return parser._workflows, parser._bindings
+ dom = domParseString(xml)
+
+ root = dom.getElementsByTagName('workflow-tool')[0]
+
+ workflows = _extractWorkflowNodes(root, encoding)
+ bindings = _extractBindingsNode(root, encoding)
+
+ return workflows, bindings
security.declareProtected( ManagePortal, 'parseWorkflowXML' )
def parseWorkflowXML( self, xml, encoding=None ):
@@ -747,74 +753,85 @@
InitializeClass( WorkflowToolConfigurator )
-class _WorkflowToolParser( HandlerBase ):
+def _getWorkflowFilename( workflow_id ):
- security = ClassSecurityInfo()
+ """ Return the name of the file which holds info for a given type.
+ """
+ return 'workflows/%s/definition.xml' % workflow_id.replace( ' ', '_' )
- def __init__( self, encoding ):
+def _getScriptFilename( workflow_id, script_id, meta_type ):
- self._encoding = encoding
- self._workflows = []
- self._bindings = {}
- self._binding_type = None
+ """ Return the name of the file which holds the script.
+ """
+ wf_dir = workflow_id.replace( ' ', '_' )
+ suffix = _METATYPE_SUFFIXES[ meta_type ]
+ return 'workflows/%s/%s.%s' % ( wf_dir, script_id, suffix )
- security.declarePrivate( 'startElement' )
- def startElement( self, name, attrs ):
+def _extractWorkflowNodes(parent, encoding=None):
- if name in ( 'workflow-tool', 'bindings' ):
- pass
+ result = []
- elif name == 'workflow':
+ for wf_node in parent.getElementsByTagName('workflow'):
- workflow_id = self._extract( attrs, 'workflow_id' )
- meta_type = self._extract( attrs, 'meta_type', workflow_id )
+ workflow_id = _getNodeAttribute(wf_node, 'workflow_id', encoding)
+ meta_type = _queryNodeAttribute(wf_node, 'meta_type', workflow_id,
+ encoding)
+ if meta_type == DCWorkflowDefinition.meta_type:
+ filename = _queryNodeAttribute(wf_node, 'filename', workflow_id,
+ encoding)
+ if filename == workflow_id:
+ filename = _getWorkflowFilename(filename)
+ else:
+ filename = None
- if meta_type == DCWorkflowDefinition.meta_type:
+ result.append( (workflow_id, meta_type, filename) )
- filename = self._extract( attrs, 'filename', workflow_id )
+ return result
- if filename == workflow_id:
- filename = _getWorkflowFilename( filename )
+def _extractBindingsNode(parent, encoding=None):
- else:
- filename = None
+ result = {}
- self._workflows.append( ( workflow_id, meta_type, filename ) )
+ b_node = parent.getElementsByTagName('bindings')[0]
+ default = _extractDefaultChainNode(b_node, encoding)
+ result.update(default)
+ types = _extractTypeNodes(b_node, encoding)
+ result.update(types)
- elif name == 'default':
+ return result
- self._binding_type = None
+def _extractDefaultChainNode(parent, encoding=None):
- elif name == 'type':
+ result = {}
- self._binding_type = self._extract( attrs, 'type_id' )
+ d_node = parent.getElementsByTagName('default')[0]
+ bound_workflows = _extractBoundWorkflowNodes(d_node, encoding)
+ result[None] = bound_workflows
- elif name == 'bound-workflow':
+ return result
- workflow_id = self._extract( attrs, 'workflow_id' )
+def _extractTypeNodes(parent, encoding=None):
- bindings = self._bindings.setdefault( self._binding_type, [] )
- bindings.append( workflow_id )
+ result = {}
- else:
- raise ValueError, 'Unknown element: %s' % name
+ for t_node in parent.getElementsByTagName('type'):
-InitializeClass( _WorkflowToolParser )
+ type_id = _getNodeAttribute(t_node, 'type_id', encoding)
+ bound_workflows = _extractBoundWorkflowNodes(t_node, encoding)
+ result[type_id] = bound_workflows
+ return result
-def _getWorkflowFilename( workflow_id ):
+def _extractBoundWorkflowNodes(parent, encoding=None):
- """ Return the name of the file which holds info for a given type.
- """
- return 'workflows/%s/definition.xml' % workflow_id.replace( ' ', '_' )
+ result = []
-def _getScriptFilename( workflow_id, script_id, meta_type ):
+ for t_node in parent.getElementsByTagName('bound-workflow'):
- """ Return the name of the file which holds the script.
- """
- wf_dir = workflow_id.replace( ' ', '_' )
- suffix = _METATYPE_SUFFIXES[ meta_type ]
- return 'workflows/%s/%s.%s' % ( wf_dir, script_id, suffix )
+ value = _getNodeAttribute(t_node, 'workflow_id', encoding)
+ result.append(value)
+
+ return tuple(result)
def _extractStateNodes( root, encoding=None ):
More information about the CMF-checkins
mailing list