[Checkins] SVN: Products.GenericSetup/branches/1.4/Products/GenericSetup/ Merge chunked export / import; prep 1.4.2 release.

Tres Seaver tseaver at palladion.com
Mon Sep 22 16:13:39 EDT 2008


Log message for revision 91370:
  Merge chunked export / import;  prep 1.4.2 release.

Changed:
  U   Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt
  U   Products.GenericSetup/branches/1.4/Products/GenericSetup/context.py
  U   Products.GenericSetup/branches/1.4/Products/GenericSetup/interfaces.py
  U   Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/conformance.py
  U   Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_context.py

-=-
Modified: Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt	2008-09-22 20:04:09 UTC (rev 91369)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/CHANGES.txt	2008-09-22 20:13:39 UTC (rev 91370)
@@ -1,9 +1,17 @@
 GenericSetup Product Changelog
 ==============================
 
-GenericSetup 1.4.2 (unreleased)
+GenericSetup 1.4.2 (2008-09-22)
 -------------------------------
 
+- Add 'IChunkedImportContext' interface, allowing RAM-efficient chunked
+  reads of large files, and implement for 'DirectoryImportContext'.
+  (https://bugs.launchpad.net/zope-cmf/+bug/259233)
+
+- Add 'IChunkedExportContext' interface, allowing RAM-efficient chunked
+  writes of large files, and implement for 'DirectoryExportContext'.
+  (https://bugs.launchpad.net/zope-cmf/+bug/257365)
+
 - Update local component registry importer to prevent it from overwriting
   existing utilities if they are already of the correct type
 

Modified: Products.GenericSetup/branches/1.4/Products/GenericSetup/context.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/context.py	2008-09-22 20:04:09 UTC (rev 91369)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/context.py	2008-09-22 20:13:39 UTC (rev 91370)
@@ -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.4/Products/GenericSetup/interfaces.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/interfaces.py	2008-09-22 20:04:09 UTC (rev 91369)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/interfaces.py	2008-09-22 20:13:39 UTC (rev 91370)
@@ -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.
@@ -164,6 +179,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.4/Products/GenericSetup/tests/conformance.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/conformance.py	2008-09-22 20:04:09 UTC (rev 91369)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/conformance.py	2008-09-22 20:13:39 UTC (rev 91370)
@@ -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.4/Products/GenericSetup/tests/test_context.py
===================================================================
--- Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_context.py	2008-09-22 20:04:09 UTC (rev 91369)
+++ Products.GenericSetup/branches/1.4/Products/GenericSetup/tests/test_context.py	2008-09-22 20:13:39 UTC (rev 91370)
@@ -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