[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ Add 'IChunkedImportContext' interface, allowing RAM-efficient chunked reads
Tres Seaver
tseaver at palladion.com
Mon Aug 18 19:20:33 EDT 2008
Log message for revision 89988:
Add 'IChunkedImportContext' interface, allowing RAM-efficient chunked reads
of large files, and implement for 'DirectoryImportContext'.
(https://bugs.launchpad.net/zope-cmf/+bug/259233)
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/trunk/Products/GenericSetup/context.py
U Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/conformance.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-08-18 22:53:42 UTC (rev 89987)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2008-08-18 23:20:33 UTC (rev 89988)
@@ -4,6 +4,10 @@
GenericSetup 1.5.0 (unreleased)
-------------------------------
+- Add 'IChunkedImportContext' interface, allowing RAM-efficient chunked
+ reads of large files, and implement for 'DirectoryImportContext'.
+ (https://bugs.launchpad.net/zope-cmf/+bug/259233)
+
- Add <genericsetup:upgradeDepends> ZCML tag; defines a specialized upgrade
step that re-applies one or more import steps from the GS profile during
an upgrade process
Modified: Products.GenericSetup/trunk/Products/GenericSetup/context.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/context.py 2008-08-18 22:53:42 UTC (rev 89987)
+++ Products.GenericSetup/trunk/Products/GenericSetup/context.py 2008-08-18 23:20:33 UTC (rev 89988)
@@ -40,6 +40,7 @@
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
@@ -179,7 +180,7 @@
class DirectoryImportContext( BaseContext ):
- implements(IImportContext)
+ implements(IChunkableImportContext)
security = ClassSecurityInfo()
@@ -194,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.
"""
@@ -207,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' )
Modified: Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py 2008-08-18 22:53:42 UTC (rev 89987)
+++ Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py 2008-08-18 23:20:33 UTC (rev 89988)
@@ -133,7 +133,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.
Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/conformance.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/conformance.py 2008-08-18 22:53:42 UTC (rev 89987)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/conformance.py 2008-08-18 23:20:33 UTC (rev 89988)
@@ -54,6 +54,15 @@
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/trunk/Products/GenericSetup/tests/test_context.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py 2008-08-18 22:53:42 UTC (rev 89987)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py 2008-08-18 23:20:33 UTC (rev 89988)
@@ -35,6 +35,7 @@
from conformance import ConformsToIImportContext
from conformance import ConformsToIExportContext
from conformance import ConformsToIChunkableExportContext
+from conformance import ConformsToIChunkableImportContext
class DummySite( Folder ):
@@ -49,6 +50,7 @@
class DirectoryImportContextTests( FilesystemTestBase
, ConformsToISetupContext
, ConformsToIImportContext
+ , ConformsToIChunkableImportContext
):
_PROFILE_PATH = '/tmp/ICTTexts'
More information about the Checkins
mailing list