[CMF-checkins] SVN: CMF/branches/goldegg-phase-1/GenericSetup/
Remove hard-wiring of the tool's ID in handler code.
Tres Seaver
tseaver at palladion.com
Sat Sep 24 05:49:55 EDT 2005
Log message for revision 38580:
Remove hard-wiring of the tool's ID in handler code.
Instead, handlers which need to find the tool may use a new API on the
context, 'getSetupTool'.
Changed:
U CMF/branches/goldegg-phase-1/GenericSetup/context.py
U CMF/branches/goldegg-phase-1/GenericSetup/interfaces.py
U CMF/branches/goldegg-phase-1/GenericSetup/tests/common.py
U CMF/branches/goldegg-phase-1/GenericSetup/tests/test_tool.py
U CMF/branches/goldegg-phase-1/GenericSetup/tool.py
-=-
Modified: CMF/branches/goldegg-phase-1/GenericSetup/context.py
===================================================================
--- CMF/branches/goldegg-phase-1/GenericSetup/context.py 2005-09-24 09:48:56 UTC (rev 38579)
+++ CMF/branches/goldegg-phase-1/GenericSetup/context.py 2005-09-24 09:49:54 UTC (rev 38580)
@@ -57,6 +57,7 @@
):
self._site = aq_parent( aq_inner( tool ) )
+ self._tool = tool
self._profile_path = profile_path
self._should_purge = bool( should_purge )
self._encoding = encoding
@@ -68,6 +69,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
security.declareProtected( ManagePortal, 'getEncoding' )
def getEncoding( self ):
@@ -154,6 +162,7 @@
def __init__( self, tool, profile_path ):
self._site = aq_parent( aq_inner( tool ) )
+ self._tool = tool
self._profile_path = profile_path
security.declareProtected( ManagePortal, 'getSite' )
@@ -163,6 +172,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
security.declareProtected( ManagePortal, 'writeDataFile' )
def writeDataFile( self, filename, text, content_type, subdir=None ):
@@ -196,6 +212,7 @@
def __init__( self, tool, archive_bits, encoding=None, should_purge=False ):
self._site = aq_parent( aq_inner( tool ) )
+ self._tool = tool
timestamp = time.gmtime()
self._archive_stream = StringIO(archive_bits)
self._archive = TarFile.open( 'foo.bar', 'r:gz'
@@ -210,6 +227,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
def getEncoding( self ):
""" See IImportContext.
@@ -294,6 +318,7 @@
def __init__( self, tool ):
self._site = aq_parent( aq_inner( tool ) )
+ self._tool = tool
timestamp = time.gmtime()
archive_name = ( 'setup_tool-%4d%02d%02d%02d%02d%02d.tar.gz'
% timestamp[:6] )
@@ -310,6 +335,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
security.declareProtected( ManagePortal, 'writeDataFile' )
def writeDataFile( self, filename, text, content_type, subdir=None ):
@@ -361,6 +393,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
security.declareProtected( ManagePortal, 'writeDataFile' )
def writeDataFile( self, filename, text, content_type, subdir=None ):
@@ -467,6 +506,13 @@
"""
return aq_self(self._site)
+ security.declareProtected( ManagePortal, 'getSetupTool' )
+ def getSetupTool( self ):
+
+ """ See ISetupContext.
+ """
+ return self._tool
+
security.declareProtected( ManagePortal, 'getEncoding' )
def getEncoding( self ):
Modified: CMF/branches/goldegg-phase-1/GenericSetup/interfaces.py
===================================================================
--- CMF/branches/goldegg-phase-1/GenericSetup/interfaces.py 2005-09-24 09:48:56 UTC (rev 38579)
+++ CMF/branches/goldegg-phase-1/GenericSetup/interfaces.py 2005-09-24 09:49:54 UTC (rev 38580)
@@ -35,6 +35,11 @@
""" Return the site object being configured / dumped.
"""
+ def getSetupTool():
+
+ """ Return the site object being configured / dumped.
+ """
+
class IImportContext( ISetupContext ):
def getEncoding():
Modified: CMF/branches/goldegg-phase-1/GenericSetup/tests/common.py
===================================================================
--- CMF/branches/goldegg-phase-1/GenericSetup/tests/common.py 2005-09-24 09:48:56 UTC (rev 38579)
+++ CMF/branches/goldegg-phase-1/GenericSetup/tests/common.py 2005-09-24 09:49:54 UTC (rev 38580)
@@ -176,13 +176,17 @@
class DummyExportContext:
- def __init__( self, site ):
+ def __init__( self, site, tool=None ):
self._site = site
+ self._tool = tool
self._wrote = []
def getSite( self ):
return self._site
+ def getSetupTool( self ):
+ return self._tool
+
def writeDataFile( self, filename, text, content_type, subdir=None ):
if subdir is not None:
filename = '%s/%s' % ( subdir, filename )
@@ -190,8 +194,9 @@
class DummyImportContext:
- def __init__( self, site, purge=True, encoding=None ):
+ def __init__( self, site, purge=True, encoding=None, tool=None ):
self._site = site
+ self._tool = tool
self._purge = purge
self._encoding = encoding
self._files = {}
@@ -199,6 +204,9 @@
def getSite( self ):
return self._site
+ def getSetupTool( self ):
+ return self._tool
+
def getEncoding( self ):
return self._encoding
Modified: CMF/branches/goldegg-phase-1/GenericSetup/tests/test_tool.py
===================================================================
--- CMF/branches/goldegg-phase-1/GenericSetup/tests/test_tool.py 2005-09-24 09:48:56 UTC (rev 38579)
+++ CMF/branches/goldegg-phase-1/GenericSetup/tests/test_tool.py 2005-09-24 09:49:54 UTC (rev 38580)
@@ -700,7 +700,7 @@
from Products.GenericSetup.tool import exportToolset
site = self._initSite()
- context = DummyExportContext( site )
+ context = DummyExportContext( site, tool=site.setup_tool )
exportToolset( context )
@@ -721,7 +721,7 @@
toolset.addRequiredTool( 'mandatory', 'path.to.one' )
toolset.addRequiredTool( 'obligatory', 'path.to.another' )
- context = DummyExportContext( site )
+ context = DummyExportContext( site, tool=site.setup_tool )
exportToolset( context )
@@ -742,7 +742,7 @@
from Products.GenericSetup.tool import importToolset
site = self._initSite()
- context = DummyImportContext( site )
+ context = DummyImportContext( site, tool=site.setup_tool )
context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
importToolset( context )
@@ -769,7 +769,7 @@
for tool_id in TOOL_IDS:
self.failUnless( tool_id in site.objectIds() )
- context = DummyImportContext( site )
+ context = DummyImportContext( site, tool=site.setup_tool )
context._files[ TOOLSET_XML ] = _FORBIDDEN_TOOLSET_XML
importToolset( context )
@@ -786,7 +786,7 @@
site = self._initSite()
self.assertEqual( len( site.objectIds() ), 1 )
- context = DummyImportContext( site )
+ context = DummyImportContext( site, tool=site.setup_tool )
context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
importToolset( context )
@@ -814,7 +814,7 @@
self.assertEqual( len( site.objectIds() ), 3 )
- context = DummyImportContext( site )
+ context = DummyImportContext( site, tool=site.setup_tool )
context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
importToolset( context )
@@ -840,7 +840,7 @@
self.assertEqual( len( site.objectIds() ), 3 )
- context = DummyImportContext( site )
+ context = DummyImportContext( site, tool=site.setup_tool )
context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
importToolset( context )
Modified: CMF/branches/goldegg-phase-1/GenericSetup/tool.py
===================================================================
--- CMF/branches/goldegg-phase-1/GenericSetup/tool.py 2005-09-24 09:48:56 UTC (rev 38579)
+++ CMF/branches/goldegg-phase-1/GenericSetup/tool.py 2005-09-24 09:49:54 UTC (rev 38580)
@@ -51,8 +51,7 @@
""" Built-in handler for exporting import / export step registries.
"""
- site = context.getSite()
- setup_tool = getattr(site, 'setup_tool')
+ setup_tool = context.getSetupTool()
import_steps_xml = setup_tool.getImportStepRegistry().generateXML()
context.writeDataFile('import_steps.xml', import_steps_xml, 'text/xml')
@@ -73,7 +72,7 @@
if xml is None:
return 'Toolset: Nothing to import.'
- setup_tool = getattr(site, 'setup_tool')
+ setup_tool = context.getSetupTool()
toolset = setup_tool.getToolsetRegistry()
toolset.parseXML(xml, encoding)
@@ -114,8 +113,7 @@
""" Export required / forbidden tools to XML file.
"""
- site = context.getSite()
- setup_tool = getattr(site, 'setup_tool')
+ setup_tool = context.getSetupTool()
toolset = setup_tool.getToolsetRegistry()
xml = toolset.generateXML()
More information about the CMF-checkins
mailing list