[CMF-checkins] CVS: CMF/CMFSetup - context.py:1.3 interfaces.py:1.7
tool.py:1.6
Tres Seaver
tseaver at zope.com
Sun May 23 21:53:14 EDT 2004
Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv15342
Modified Files:
context.py interfaces.py tool.py
Log Message:
- context.py:
o Add a new export context type, TarballExportContext, which creates
an on-the-fly tarball from the calls to 'writeDataFile'.
- interfaces.py:
o Document extended interface for 'runExportStep' and 'runAllExportSteps'.
- tool.py:
o Set up always-on export step for the two step registries.
o Implement 'runExportStep' and 'runAllExportSteps' using
TarballExportContext.
=== CMF/CMFSetup/context.py 1.2 => 1.3 ===
--- CMF/CMFSetup/context.py:1.2 Sun May 23 17:05:08 2004
+++ CMF/CMFSetup/context.py Sun May 23 21:52:43 2004
@@ -5,6 +5,10 @@
$Id$
"""
import os
+import time
+from tarfile import TarFile
+from tarfile import TarInfo
+from StringIO import StringIO
from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
@@ -142,3 +146,41 @@
file.close()
InitializeClass( ExportContext )
+
+class TarballExportContext( ExportContext ):
+
+ __implements__ = ( IExportContext, )
+
+ security = ClassSecurityInfo()
+
+ def __init__( self, tool ):
+
+ self._site = aq_parent( aq_inner( tool ) )
+ timestamp = time.gmtime()
+ archive_name = ( 'portal_setup-%4d%02d%02d%02d%02d%02d.tar.gz'
+ % timestamp[:6] )
+
+ self._archive_stream = StringIO()
+ self._archive = TarFile.open( archive_name, 'w:gz'
+ , self._archive_stream )
+
+ security.declareProtected( ManagePortal, 'writeDataFile' )
+ def writeDataFile( self, filename, text, content_type, subdir=None ):
+
+ """ See IExportContext.
+ """
+ if subdir is not None:
+ filename = os.path.join( subdir, filename )
+
+ stream = StringIO( text )
+ info = TarInfo( filename )
+ info.size = len( text )
+ self._archive.addfile( info, stream )
+
+ security.declareProtected( ManagePortal, 'getArchive' )
+ def getArchive( self ):
+
+ """ Close the archive, and return it as a big string.
+ """
+ self._archive.close()
+ return self._archive_stream.getvalue()
=== CMF/CMFSetup/interfaces.py 1.6 => 1.7 ===
--- CMF/CMFSetup/interfaces.py:1.6 Sun May 23 17:59:15 2004
+++ CMF/CMFSetup/interfaces.py Sun May 23 21:52:43 2004
@@ -238,7 +238,7 @@
o 'id' is the unique identifier for this step
- o 'step' should implement IExportPlugin.
+ o 'handler' should implement IExportPlugin.
o 'title' is a one-line UI description for this step.
If None, the first line of the documentation string of the step
@@ -328,14 +328,32 @@
def runExportStep( step_id ):
- """ Return a tarball containing artifacts from one export step.
+ """ Generate a tarball containing artifacts from one export step.
o 'step_id' identifies the export step.
+
+ o Return a mapping, with keys:
+
+ 'steps' -- a sequence of IDs of the steps run.
+
+ 'messages' -- a dictionary holding messages returned from each
+ step
+
+ 'tarball' -- the stringified tar-gz data.
"""
def runAllExportSteps():
- """ Return a tarball created using all export steps.
+ """ Generate a tarball containing artifacts from all export steps.
+
+ o Return a mapping, with keys:
+
+ 'steps' -- a sequence of IDs of the steps run.
+
+ 'messages' -- a dictionary holding messages returned from each
+ step
+
+ 'tarball' -- the stringified tar-gz data.
"""
def createSnapshot( snapshot_id ):
=== CMF/CMFSetup/tool.py 1.5 => 1.6 ===
--- CMF/CMFSetup/tool.py:1.5 Sun May 23 17:59:15 2004
+++ CMF/CMFSetup/tool.py Sun May 23 21:52:43 2004
@@ -9,11 +9,12 @@
from OFS.Folder import Folder
from Products.CMFCore.utils import UniqueObject
+from Products.CMFCore.utils import getToolByName
from interfaces import ISetupTool
from permissions import ManagePortal
from context import ImportContext
-from context import ExportContext
+from context import TarballExportContext
from registry import ImportStepRegistry
from registry import ExportStepRegistry
@@ -40,6 +41,10 @@
self._import_registry = ImportStepRegistry()
self._export_registry = ExportStepRegistry()
+ self._export_registry.registerStep( 'step_registries'
+ , exportStepRegistries
+ , 'Export import / export steps.'
+ )
security.declareProtected( ManagePortal, 'getProfileProduct' )
def getProfileProduct( self ):
@@ -159,12 +164,38 @@
""" See ISetupTool.
"""
+ context = TarballExportContext( self )
+ handler = self._export_registry.getStep( step_id )
+
+ if handler is None:
+ raise ValueError( 'Invalid export step: %s' % step_id )
+
+ message = handler( context )
+
+ return { 'steps' : [ step_id ]
+ , 'messages' : { step_id : message }
+ , 'tarball' : context.getArchive()
+ }
security.declareProtected(ManagePortal, 'runAllExportSteps')
def runAllExportSteps( self ):
""" See ISetupTool.
"""
+ context = TarballExportContext( self )
+
+ steps = self._export_registry.listSteps()
+ messages = {}
+ for step_id in steps:
+
+ handler = self._export_registry.getStep( step_id )
+ messages[ step_id ] = handler( context )
+
+
+ return { 'steps' : steps
+ , 'messages' : messages
+ , 'tarball' : context.getArchive()
+ }
security.declareProtected( ManagePortal, 'createSnapshot')
def createSnapshot( self, snapshot_id ):
@@ -241,3 +272,19 @@
return handler( context )
InitializeClass( SetupTool )
+
+
+def exportStepRegistries( context ):
+
+ """ Built-in handler for exporting import / export step registries.
+ """
+ site = context.getSite()
+ tool = getToolByName( site, 'portal_setup' )
+
+ import_steps_xml = tool.getImportStepRegistry().exportAsXML()
+ context.writeDataFile( 'import_steps.xml', import_steps_xml, 'text/xml' )
+
+ export_steps_xml = tool.getExportStepRegistry().exportAsXML()
+ context.writeDataFile( 'export_steps.xml', export_steps_xml, 'text/xml' )
+
+ return 'Step registries exported'
More information about the CMF-checkins
mailing list