[CMF-checkins] SVN: CMF/trunk/GenericSetup/ Add a 'notes' API to
the contexts, to allow recording status messages.
Tres Seaver
tseaver at palladion.com
Sun Sep 25 18:38:27 EDT 2005
Log message for revision 38635:
Add a 'notes' API to the contexts, to allow recording status messages.
o This API may soon disappear, to be replaced by a more general annotation.
o Factored out a common base class for the contexts.
Changed:
U CMF/trunk/GenericSetup/context.py
U CMF/trunk/GenericSetup/interfaces.py
U CMF/trunk/GenericSetup/tests/common.py
-=-
Modified: CMF/trunk/GenericSetup/context.py
===================================================================
--- CMF/trunk/GenericSetup/context.py 2005-09-25 22:27:59 UTC (rev 38634)
+++ CMF/trunk/GenericSetup/context.py 2005-09-25 22:38:27 UTC (rev 38635)
@@ -42,25 +42,15 @@
from interfaces import IImportContext
from permissions import ManagePortal
+class BaseContext( Implicit ):
-class DirectoryImportContext( Implicit ):
-
- implements(IImportContext)
-
security = ClassSecurityInfo()
- def __init__( self
- , tool
- , profile_path
- , should_purge=False
- , encoding=None
- ):
+ def __init__( self, tool ):
- self._site = aq_parent( aq_inner( tool ) )
self._tool = tool
- self._profile_path = profile_path
- self._should_purge = bool( should_purge )
- self._encoding = encoding
+ self._site = aq_parent( aq_inner( tool ) )
+ self._notes = []
security.declareProtected( ManagePortal, 'getSite' )
def getSite( self ):
@@ -76,6 +66,31 @@
"""
return self._tool
+ security.declareProtected( ManagePortal, 'notes' )
+ def note( self, category, message ):
+
+ """ See ISetupContext.
+ """
+ self._notes.append( ( category, message ) )
+
+class DirectoryImportContext( BaseContext ):
+
+ implements(IImportContext)
+
+ security = ClassSecurityInfo()
+
+ def __init__( self
+ , tool
+ , profile_path
+ , should_purge=False
+ , encoding=None
+ ):
+
+ BaseContext.__init__( self, tool )
+ self._profile_path = profile_path
+ self._should_purge = bool( should_purge )
+ self._encoding = encoding
+
security.declareProtected( ManagePortal, 'getEncoding' )
def getEncoding( self ):
@@ -153,7 +168,7 @@
InitializeClass( DirectoryImportContext )
-class DirectoryExportContext( Implicit ):
+class DirectoryExportContext( BaseContext ):
implements(IExportContext)
@@ -161,24 +176,9 @@
def __init__( self, tool, profile_path ):
- self._site = aq_parent( aq_inner( tool ) )
- self._tool = tool
+ BaseContext.__init__( self, tool )
self._profile_path = profile_path
- security.declareProtected( ManagePortal, 'getSite' )
- def getSite( self ):
-
- """ See ISetupContext.
- """
- 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 ):
@@ -203,7 +203,7 @@
InitializeClass( DirectoryExportContext )
-class TarballImportContext( Implicit ):
+class TarballImportContext( BaseContext ):
implements(IImportContext)
@@ -211,8 +211,7 @@
def __init__( self, tool, archive_bits, encoding=None, should_purge=False ):
- self._site = aq_parent( aq_inner( tool ) )
- self._tool = tool
+ BaseContext.__init__( self, tool )
timestamp = time.gmtime()
self._archive_stream = StringIO(archive_bits)
self._archive = TarFile.open( 'foo.bar', 'r:gz'
@@ -220,20 +219,6 @@
self._encoding = encoding
self._should_purge = bool( should_purge )
- security.declareProtected( ManagePortal, 'getSite' )
- def getSite( self ):
-
- """ See ISetupContext.
- """
- return aq_self(self._site)
-
- security.declareProtected( ManagePortal, 'getSetupTool' )
- def getSetupTool( self ):
-
- """ See ISetupContext.
- """
- return self._tool
-
def getEncoding( self ):
""" See IImportContext.
@@ -309,7 +294,7 @@
return None
-class TarballExportContext( Implicit ):
+class TarballExportContext( BaseContext ):
implements(IExportContext)
@@ -317,8 +302,7 @@
def __init__( self, tool ):
- self._site = aq_parent( aq_inner( tool ) )
- self._tool = tool
+ BaseContext.__init__( self, tool )
timestamp = time.gmtime()
archive_name = ( 'setup_tool-%4d%02d%02d%02d%02d%02d.tar.gz'
% timestamp[:6] )
@@ -328,20 +312,6 @@
self._archive = TarFile.open( archive_name, 'w:gz'
, self._archive_stream )
- security.declareProtected( ManagePortal, 'getSite' )
- def getSite( self ):
-
- """ See ISetupContext.
- """
- 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 ):
@@ -374,7 +344,7 @@
InitializeClass( TarballExportContext )
-class SnapshotExportContext( Implicit ):
+class SnapshotExportContext( BaseContext ):
implements(IExportContext)
@@ -382,24 +352,9 @@
def __init__( self, tool, snapshot_id ):
- self._tool = tool = aq_inner( tool )
- self._site = aq_parent( tool )
+ BaseContext.__init__( self, tool )
self._snapshot_id = snapshot_id
- security.declareProtected( ManagePortal, 'getSite' )
- def getSite( self ):
-
- """ See ISetupContext.
- """
- 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 ):
@@ -480,7 +435,7 @@
InitializeClass( SnapshotExportContext )
-class SnapshotImportContext( Implicit ):
+class SnapshotImportContext( BaseContext ):
implements(IImportContext)
@@ -493,26 +448,11 @@
, encoding=None
):
- self._tool = tool = aq_inner( tool )
- self._site = aq_parent( tool )
+ BaseContext.__init__( self, tool )
self._snapshot_id = snapshot_id
self._encoding = encoding
self._should_purge = bool( should_purge )
- security.declareProtected( ManagePortal, 'getSite' )
- def getSite( self ):
-
- """ See ISetupContext.
- """
- 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/trunk/GenericSetup/interfaces.py
===================================================================
--- CMF/trunk/GenericSetup/interfaces.py 2005-09-25 22:27:59 UTC (rev 38634)
+++ CMF/trunk/GenericSetup/interfaces.py 2005-09-25 22:38:27 UTC (rev 38635)
@@ -40,6 +40,18 @@
""" Return the site object being configured / dumped.
"""
+ def note(category, message):
+
+ """ Record a logging message from within a handler.
+
+ o 'category' is a string defining the source of the message.
+
+ o 'message' is the text of the message itself.
+
+ o XXX This API may disappear soon, to be replaced by a more
+ general annotation.
+ """
+
class IImportContext( ISetupContext ):
def getEncoding():
Modified: CMF/trunk/GenericSetup/tests/common.py
===================================================================
--- CMF/trunk/GenericSetup/tests/common.py 2005-09-25 22:27:59 UTC (rev 38634)
+++ CMF/trunk/GenericSetup/tests/common.py 2005-09-25 22:38:27 UTC (rev 38635)
@@ -200,6 +200,7 @@
self._purge = purge
self._encoding = encoding
self._files = {}
+ self._notes = []
def getSite( self ):
return self._site
@@ -221,6 +222,10 @@
return self._purge
+ def note( self, component, message ):
+
+ self._notes.append( ( component, message ) )
+
def dummy_handler( context ):
pass
More information about the CMF-checkins
mailing list