[Checkins] SVN: Products.GenericSetup/branches/1.3/Products/GenericSetup/ Backpoprt chunked export / import context fixes.
Tres Seaver
tseaver at palladion.com
Wed Sep 3 18:39:48 EDT 2008
Log message for revision 90772:
Backpoprt chunked export / import context fixes.
Changed:
U Products.GenericSetup/branches/1.3/Products/GenericSetup/context.py
U Products.GenericSetup/branches/1.3/Products/GenericSetup/interfaces.py
U Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/conformance.py
U Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_context.py
-=-
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/context.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/context.py 2008-09-03 20:35:45 UTC (rev 90771)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/context.py 2008-09-03 22:39:47 UTC (rev 90772)
@@ -39,6 +39,8 @@
from Products.PythonScripts.PythonScript import PythonScript
from zope.interface import implements
+from interfaces import IChunkableExportContext
+from interfaces import IChunkableImportContext
from interfaces import IExportContext
from interfaces import IImportContext
from interfaces import ISetupEnviron
@@ -178,7 +180,7 @@
class DirectoryImportContext( BaseContext ):
- implements(IImportContext)
+ implements(IChunkableImportContext)
security = ClassSecurityInfo()
@@ -193,8 +195,8 @@
self._profile_path = profile_path
self._should_purge = bool( should_purge )
- security.declareProtected( ManagePortal, 'readDataFile' )
- def readDataFile( self, filename, subdir=None ):
+ security.declareProtected( ManagePortal, 'openDataFile' )
+ def openDataFile( self, filename, subdir=None ):
""" See IImportContext.
"""
@@ -206,10 +208,18 @@
if not os.path.exists( full_path ):
return None
- file = open( full_path, 'rb' )
- result = file.read()
- file.close()
+ return open( full_path, 'rb' )
+ security.declareProtected( ManagePortal, 'readDataFile' )
+ def readDataFile( self, filename, subdir=None ):
+
+ """ See IImportContext.
+ """
+ result = None
+ file = self.openDataFile( filename, subdir )
+ if file is not None:
+ result = file.read()
+ file.close()
return result
security.declareProtected( ManagePortal, 'getLastModified' )
@@ -265,7 +275,7 @@
class DirectoryExportContext( BaseContext ):
- implements(IExportContext)
+ implements(IChunkableExportContext)
security = ClassSecurityInfo()
@@ -274,10 +284,10 @@
BaseContext.__init__( self, tool, encoding )
self._profile_path = profile_path
- security.declareProtected( ManagePortal, 'writeDataFile' )
- def writeDataFile( self, filename, text, content_type, subdir=None ):
+ security.declareProtected( ManagePortal, 'openDataFile' )
+ def openDataFile( self, filename, content_type, subdir=None ):
- """ See IExportContext.
+ """ See IChunkableExportContext.
"""
if subdir is None:
prefix = self._profile_path
@@ -291,7 +301,14 @@
mode = content_type.startswith( 'text/' ) and 'w' or 'wb'
- file = open( full_path, mode )
+ return open( full_path, mode )
+
+ security.declareProtected( ManagePortal, 'writeDataFile' )
+ def writeDataFile( self, filename, text, content_type, subdir=None ):
+
+ """ See IExportContext.
+ """
+ file = self.openDataFile( filename, content_type, subdir )
file.write( text )
file.close()
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/interfaces.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/interfaces.py 2008-09-03 20:35:45 UTC (rev 90771)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/interfaces.py 2008-09-03 22:39:47 UTC (rev 90772)
@@ -132,7 +132,22 @@
o If 'path' does not point to a directory / folder, return None.
"""
+class IChunkableImportContext( IImportContext ):
+ def openDataFile( filename, subdir=None ):
+
+ """ Open a datafile for reading from the specified location.
+
+ o 'filename' is the unqualified name of the file.
+
+ o 'subdir', if passed, is a path to a subdirectory / folder in
+ which to find the file; if not passed, write the file to the
+ "root" of the target.
+
+ o Return a readable file-like object; the caller is responsible
+ for calling 'close' on it.
+ """
+
class IImportPlugin( IPseudoInterface ):
""" Signature for callables used to import portions of site configuration.
@@ -163,6 +178,24 @@
"root" of the target.
"""
+class IChunkableExportContext( IExportContext ):
+
+ def openDataFile( filename, content_type, subdir=None ):
+
+ """ Open a datafile for writing into the specified location.
+
+ o 'filename' is the unqualified name of the file.
+
+ o 'content_type' is the MIMEtype of the file.
+
+ o 'subdir', if passed, is a path to a subdirectory / folder in
+ which to write the file; if not passed, write the file to the
+ "root" of the target.
+
+ o Return a writeable file-like object; the caller is responsible
+ for calling 'close' on it.
+ """
+
class IExportPlugin( IPseudoInterface ):
""" Signature for callables used to export portions of site configuration.
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/conformance.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/conformance.py 2008-09-03 20:35:45 UTC (rev 90771)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/conformance.py 2008-09-03 22:39:47 UTC (rev 90772)
@@ -45,6 +45,24 @@
verifyClass( IExportContext, self._getTargetClass() )
+class ConformsToIChunkableExportContext:
+
+ def test_IChunkableExportContext_conformance( self ):
+
+ from Products.GenericSetup.interfaces import IChunkableExportContext
+ from zope.interface.verify import verifyClass
+
+ verifyClass( IChunkableExportContext, self._getTargetClass() )
+
+class ConformsToIChunkableImportContext:
+
+ def test_IChunkableImportContext_conformance( self ):
+
+ from Products.GenericSetup.interfaces import IChunkableImportContext
+ from zope.interface.verify import verifyClass
+
+ verifyClass( IChunkableImportContext, self._getTargetClass() )
+
class ConformsToIStepRegistry:
def test_IStepRegistry_conformance( self ):
Modified: Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_context.py
===================================================================
--- Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_context.py 2008-09-03 20:35:45 UTC (rev 90771)
+++ Products.GenericSetup/branches/1.3/Products/GenericSetup/tests/test_context.py 2008-09-03 22:39:47 UTC (rev 90772)
@@ -34,6 +34,8 @@
from conformance import ConformsToISetupContext
from conformance import ConformsToIImportContext
from conformance import ConformsToIExportContext
+from conformance import ConformsToIChunkableExportContext
+from conformance import ConformsToIChunkableImportContext
class DummySite( Folder ):
@@ -48,6 +50,7 @@
class DirectoryImportContextTests( FilesystemTestBase
, ConformsToISetupContext
, ConformsToIImportContext
+ , ConformsToIChunkableImportContext
):
_PROFILE_PATH = '/tmp/ICTTexts'
@@ -339,6 +342,7 @@
class DirectoryExportContextTests( FilesystemTestBase
, ConformsToISetupContext
, ConformsToIExportContext
+ , ConformsToIChunkableExportContext
):
_PROFILE_PATH = '/tmp/ECTTexts'
More information about the Checkins
mailing list