[CMF-checkins] CVS: CMF/CMFSetup - interfaces.py:1.4 tool.py:1.2
Tres Seaver
tseaver at zope.com
Sun May 23 16:32:14 EDT 2004
Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv14985
Modified Files:
interfaces.py tool.py
Log Message:
- interfaces.py:
o Add API for updating / requesting the profile directory of the tool,
and the product (if any) to which it is relative.
o Add accessors to get tool's import and export step registries.
- tool.py:
o Create empty import / export step registries in __init__.
o Implement the new profile directory APIs.
o Implement the new registry accessors.
o Load registries from XML files in profile directory when it is
updated.
=== CMF/CMFSetup/interfaces.py 1.3 => 1.4 ===
--- CMF/CMFSetup/interfaces.py:1.3 Sun May 23 14:57:38 2004
+++ CMF/CMFSetup/interfaces.py Sun May 23 16:31:43 2004
@@ -254,6 +254,41 @@
""" API for SetupTool.
"""
+ def getProfileProduct():
+
+ """ Return the name of the product defining our current profile.
+
+ o Return None if the current profile is not relative to a product.
+ """
+
+ def getProfileDirectory( relative_to_product=False ):
+
+ """ Return the path to the directory containing profile information.
+
+ o If 'relative_to_product', return it relative to the root directory
+ of our profile product.
+ """
+
+ def setProfileDirectory( path, product_name=None ):
+
+ """ Set the path to the directory containing profile information.
+
+ o If 'product_name' is not None, compute the fully-qualified path
+ relative to the product's root directory.
+
+ o Update the import and export step registries from that directory.
+ """
+
+ def getImportStepRegistry():
+
+ """ Return the IImportStepRegistry for the tool.
+ """
+
+ def getExportStepRegistry():
+
+ """ Return the IExportStepRegistry for the tool.
+ """
+
def runSetupStep( step_id, purge_old=True, run_dependencies=True ):
""" Execute a given setup step
=== CMF/CMFSetup/tool.py 1.1 => 1.2 ===
--- CMF/CMFSetup/tool.py:1.1 Sun May 23 14:57:38 2004
+++ CMF/CMFSetup/tool.py Sun May 23 16:31:43 2004
@@ -2,6 +2,7 @@
$Id$
"""
+import os
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass
@@ -11,6 +12,8 @@
from interfaces import ISetupTool
from permissions import ManagePortal
+from registry import ImportStepRegistry
+from registry import ExportStepRegistry
class SetupTool( UniqueObject, Folder ):
@@ -22,8 +25,85 @@
id = 'portal_setup'
meta_type = 'Portal Setup Tool'
+ IMPORT_STEPS_XML = 'import-steps.xml'
+ EXPORT_STEPS_XML = 'export-steps.xml'
+
+ _product_name = None
+ _profile_directory = None
+ _root_directory = None
+
security = ClassSecurityInfo()
+
+ def __init__( self ):
+
+ self._import_registry = ImportStepRegistry()
+ self._export_registry = ExportStepRegistry()
+
+ security.declareProtected( ManagePortal, 'getProfileProduct' )
+ def getProfileProduct( self ):
+
+ """ See ISetupTool.
+ """
+ return self._product_name
+
+ security.declareProtected( ManagePortal, 'getProfileDirectory' )
+ def getProfileDirectory( self, relative_to_product=False ):
+
+ """ See ISetupTool.
+ """
+ if relative_to_product:
+ if not self._product_name:
+ raise ValueError(
+ 'Profile directory is not relative to any product.' )
+ else:
+ if self._product_name:
+ return self._getFullyQualifiedProfileDirectory()
+
+ return self._profile_directory
+
+ security.declareProtected( ManagePortal, 'setProfileDirectory' )
+ def setProfileDirectory( self, path, product_name=None ):
+
+ """ See ISetupTool.
+ """
+ if product_name is not None:
+ try:
+ product = __import__( 'Products.%s' % product_name
+ , globals(), {}, ['initialize' ] )
+ except ImportError:
+ raise ValueError, 'Not a valid product name: %s' % product_name
+
+ root = self._root_directory = product.__path__[0]
+
+ if not os.path.exists( os.path.join( root, path ) ):
+ raise ValueError, 'Invalid path: %s' % path
+
+ else:
+ if not os.path.exists( path ):
+ raise ValueError, 'Invalid path: %s' % path
+
+ self._root_directory = None
+
+ self._profile_directory = path
+ self._product_name = product_name
+
+ self._updateImportStepsRegistry()
+ self._updateExportStepsRegistry()
+ security.declareProtected( ManagePortal, 'getImportStepRegistry' )
+ def getImportStepRegistry( self ):
+
+ """ See ISetupTool.
+ """
+ return self._import_registry
+
+ security.declareProtected( ManagePortal, 'getImportStepRegistry' )
+ def getExportStepRegistry( self ):
+
+ """ See ISetupTool.
+ """
+ return self._export_registry
+
security.declareProtected( ManagePortal, 'executeStep' )
def runSetupStep( self, step_id, run_dependencies=True, purge_old=True ):
@@ -69,5 +149,45 @@
""" See ISetupTool.
"""
+
+ #
+ # Helper methods
+ #
+ security.declarePrivate( '_getFullyQualifiedProfileDirectory' )
+ def _getFullyQualifiedProfileDirectory( self ):
+
+ """ Return the fully-qualified directory path of our profile.
+ """
+ if self._root_directory is not None:
+ return os.path.join( self._root_directory
+ , self._profile_directory )
+
+ return self._profile_directory
+
+ security.declarePrivate( '_updateImportStepsRegistry' )
+ def _updateImportStepsRegistry( self ):
+
+ """ Update our import steps registry from our profile.
+ """
+ fq = self._getFullyQualifiedProfileDirectory()
+
+ f = open( os.path.join( fq, self.IMPORT_STEPS_XML ), 'r' )
+ xml = f.read()
+ f.close()
+
+ self._import_registry.importFromXML( xml )
+
+ security.declarePrivate( '_updateExportStepsRegistry' )
+ def _updateExportStepsRegistry( self ):
+
+ """ Update our export steps registry from our profile.
+ """
+ fq = self._getFullyQualifiedProfileDirectory()
+
+ f = open( os.path.join( fq, self.EXPORT_STEPS_XML ), 'r' )
+ xml = f.read()
+ f.close()
+
+ self._export_registry.importFromXML( xml )
InitializeClass( SetupTool )
More information about the CMF-checkins
mailing list