[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ - fixed export and import of directory structures

Yvo Schubbe y.2009 at wcm-solutions.de
Sun Dec 13 06:19:13 EST 2009


Log message for revision 106440:
  - fixed export and import of directory structures

Changed:
  U   Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
  U   Products.GenericSetup/trunk/Products/GenericSetup/context.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	2009-12-13 11:09:33 UTC (rev 106439)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2009-12-13 11:19:13 UTC (rev 106440)
@@ -4,7 +4,7 @@
 1.5.0 (unreleased)
 ------------------
 
-- 
+- tarball contexts: Fixed export and import of directory structures.
 
 
 1.5.0b1 (2009-09-25)

Modified: Products.GenericSetup/trunk/Products/GenericSetup/context.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/context.py	2009-12-13 11:09:33 UTC (rev 106439)
+++ Products.GenericSetup/trunk/Products/GenericSetup/context.py	2009-12-13 11:19:13 UTC (rev 106440)
@@ -21,6 +21,7 @@
 import os
 import time
 from StringIO import StringIO
+from tarfile import DIRTYPE
 from tarfile import TarFile
 from tarfile import TarInfo
 
@@ -328,7 +329,6 @@
     def __init__( self, tool, archive_bits, encoding=None,
                   should_purge=False ):
         BaseContext.__init__( self, tool, encoding )
-        timestamp = time.gmtime()
         self._archive_stream = StringIO(archive_bits)
         self._archive = TarFile.open( 'foo.bar', 'r:gz'
                                     , self._archive_stream )
@@ -388,9 +388,7 @@
             name = name[pfx_len:]
             if name in skip:
                 continue
-            # In earlier Python versions directories would always have a
-            # slash in their name.
-            if '/' in name or info.isdir():
+            if '/' in name and not info.isdir():
                 continue
             if [s for s in skip_suffixes if name.endswith(s)]:
                 continue
@@ -444,6 +442,16 @@
         if subdir is not None:
             filename = '/'.join( ( subdir, filename ) )
 
+        parents = filename.split('/')[:-1]
+        while parents:
+            path = '/'.join(parents) + '/'
+            if path not in self._archive.getnames():
+                info = TarInfo(path)
+                info.type = DIRTYPE
+                info.mtime = time.time()
+                self._archive.addfile(info)
+            parents.pop()
+
         stream = StringIO( text )
         info = TarInfo( filename )
         info.size = len( text )

Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py	2009-12-13 11:09:33 UTC (rev 106439)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_context.py	2009-12-13 11:19:13 UTC (rev 106440)
@@ -445,21 +445,21 @@
             stream = StringIO(v)
             info = TarInfo(k)
             info.size = len(v)
-            info.mtime = mod_time
+            info.mtime = modtime
             archive.addfile(info, stream)
 
-        def _addMember(path, data, modtime):
+        def _addMember(filename, data, modtime):
             from tarfile import DIRTYPE
-            elements = path.split('/')
-            parents = filter(None, [elements[x] for x in range(len(elements))])
-            for parent in parents:
-                info = TarInfo()
-                info.name = parent
-                info.size = 0
-                info.mtime = mod_time
-                info.type = DIRTYPE
-                archive.addfile(info, StringIO())
-            _addOneMember(path, data, modtime)
+            parents = filename.split('/')[:-1]
+            while parents:
+                path = '/'.join(parents) + '/'
+                if path not in archive.getnames():
+                    info = TarInfo(path)
+                    info.type = DIRTYPE
+                    info.mtime = modtime
+                    archive.addfile(info)
+                parents.pop()
+            _addOneMember(filename, data, modtime)
 
         file_items = file_dict.items() or [('dummy', '')] # empty archive barfs
 
@@ -658,8 +658,6 @@
 
         site, tool, ctx = self._makeOne( { FILENAME: printable } )
 
-        # Beware! The test setup actually does add two entries into the
-        # context. One is a folder and should be filtered out.
         self.assertEqual( len( ctx.listDirectory( None ) ), 1 )
         self.failUnless( FILENAME in ctx.listDirectory( None ) )
 
@@ -815,7 +813,8 @@
 
         fileish = StringIO( ctx.getArchive() )
 
-        self._verifyTarballContents( fileish, [ 'foo.txt', 'bar/baz.txt' ] )
+        self._verifyTarballContents( fileish,
+                                     ['foo.txt', 'bar', 'bar/baz.txt'] )
         self._verifyTarballEntry( fileish, 'foo.txt', printable )
         self._verifyTarballEntry( fileish, 'bar/baz.txt', digits )
 



More information about the checkins mailing list