[Zope-CVS] SVN: GenericSetup/trunk/ Skip files ending with ~ in the filesystem or in a tarball.

Florent Guillaume fg at nuxeo.com
Mon Jan 30 12:48:12 EST 2006


Log message for revision 41502:
  Skip files ending with ~ in the filesystem or in a tarball.

Changed:
  U   GenericSetup/trunk/context.py
  U   GenericSetup/trunk/interfaces.py
  U   GenericSetup/trunk/tests/test_context.py

-=-
Modified: GenericSetup/trunk/context.py
===================================================================
--- GenericSetup/trunk/context.py	2006-01-30 17:38:43 UTC (rev 41501)
+++ GenericSetup/trunk/context.py	2006-01-30 17:48:12 UTC (rev 41502)
@@ -43,6 +43,7 @@
 from interfaces import IImportContext
 from interfaces import IWriteLogger
 from interfaces import SKIPPED_FILES
+from interfaces import SKIPPED_SUFFIXES
 from permissions import ManagePortal
 
 
@@ -217,7 +218,8 @@
         return os.path.isdir( full_path )
 
     security.declareProtected( ManagePortal, 'listDirectory' )
-    def listDirectory( self, path, skip=SKIPPED_FILES ):
+    def listDirectory(self, path, skip=SKIPPED_FILES,
+                      skip_suffixes=SKIPPED_SUFFIXES):
 
         """ See IImportContext.
         """
@@ -229,9 +231,15 @@
         if not os.path.exists( full_path ) or not os.path.isdir( full_path ):
             return None
 
-        names = os.listdir( full_path )
+        names = []
+        for name in os.listdir(full_path):
+            if name in skip:
+                continue
+            if [s for s in skip_suffixes if name.endswith(s)]:
+                continue
+            names.append(name)
 
-        return [ name for name in names if name not in skip ]
+        return names
 
 InitializeClass( DirectoryImportContext )
 
@@ -316,7 +324,8 @@
         if info is not None:
             return info.isdir()
 
-    def listDirectory( self, path, skip=SKIPPED_FILES ):
+    def listDirectory(self, path, skip=SKIPPED_FILES,
+                      skip_suffixes=SKIPPED_SUFFIXES):
 
         """ See IImportContext.
         """
@@ -331,10 +340,18 @@
 
         pfx_len = len(path)
 
-        beneath = [x[pfx_len:] for x in self._archive.getnames()
-                                if x.startswith(path) and x != path]
+        names = []
+        for name in self._archive.getnames():
+            if name == path or not name.startswith(path):
+                continue
+            name = name[pfx_len:]
+            if '/' in name or name in skip:
+                continue
+            if [s for s in skip_suffixes if name.endswith(s)]:
+                continue
+            names.append(name)
 
-        return [x for x in beneath if '/' not in x and x not in skip]
+        return names
 
     def shouldPurge( self ):
 
@@ -580,7 +597,7 @@
             return bool( folderish )
 
     security.declareProtected( ManagePortal, 'listDirectory' )
-    def listDirectory( self, path, skip=() ):
+    def listDirectory(self, path, skip=(), skip_suffixes=()):
 
         """ See IImportContext.
         """
@@ -593,9 +610,16 @@
             if not getattr( subdir, 'isPrincipiaFolderish', False ):
                 return None
 
-            object_ids = subdir.objectIds()
-            return [ x for x in object_ids if x not in skip ]
+            names = []
+            for name in subdir.objectIds():
+                if name in skip:
+                    continue
+                if [s for s in skip_suffixes if name.endswith(s)]:
+                    continue
+                names.append(name)
 
+            return names
+
     security.declareProtected( ManagePortal, 'shouldPurge' )
     def shouldPurge( self ):
 

Modified: GenericSetup/trunk/interfaces.py
===================================================================
--- GenericSetup/trunk/interfaces.py	2006-01-30 17:38:43 UTC (rev 41501)
+++ GenericSetup/trunk/interfaces.py	2006-01-30 17:48:12 UTC (rev 41502)
@@ -21,6 +21,7 @@
 
 BASE, EXTENSION = range(1, 3)
 SKIPPED_FILES = ('CVS', '.svn', '_svn', '_darcs')
+SKIPPED_SUFFIXES = ('~',)
 
 
 class IPseudoInterface( Interface ):

Modified: GenericSetup/trunk/tests/test_context.py
===================================================================
--- GenericSetup/trunk/tests/test_context.py	2006-01-30 17:38:43 UTC (rev 41501)
+++ GenericSetup/trunk/tests/test_context.py	2006-01-30 17:48:12 UTC (rev 41502)
@@ -299,6 +299,7 @@
         FILENAME = os.path.join( SUBDIR, 'nested.txt' )
         self._makeFile( FILENAME, printable )
         self._makeFile( os.path.join( SUBDIR, 'another.txt' ), 'ABC' )
+        self._makeFile( os.path.join( SUBDIR, 'another.txt~' ), '123' )
         self._makeFile( os.path.join( SUBDIR, 'CVS/skip.txt' ), 'DEF' )
         self._makeFile( os.path.join( SUBDIR, '.svn/skip.txt' ), 'GHI' )
 
@@ -309,6 +310,7 @@
         self.assertEqual( len( names ), 2 )
         self.failUnless( 'nested.txt' in names )
         self.failUnless( 'another.txt' in names )
+        self.failIf( 'another.txt~' in names )
         self.failIf( 'CVS' in names )
         self.failIf( '.svn' in names )
 
@@ -319,15 +321,18 @@
         FILENAME = os.path.join( SUBDIR, 'nested.txt' )
         self._makeFile( FILENAME, printable )
         self._makeFile( os.path.join( SUBDIR, 'another.txt' ), 'ABC' )
+        self._makeFile( os.path.join( SUBDIR, 'another.bak' ), '123' )
         self._makeFile( os.path.join( SUBDIR, 'CVS/skip.txt' ), 'DEF' )
         self._makeFile( os.path.join( SUBDIR, '.svn/skip.txt' ), 'GHI' )
 
         site = DummySite( 'site' ).__of__( self.root )
         ctx = self._makeOne( site, self._PROFILE_PATH )
 
-        names = ctx.listDirectory( SUBDIR, ( 'nested.txt', ) )
+        names = ctx.listDirectory(SUBDIR, skip=('nested.txt',),
+                                  skip_suffixes=('.bak',))
         self.assertEqual( len( names ), 3 )
         self.failIf( 'nested.txt' in names )
+        self.failIf( 'nested.bak' in names )
         self.failUnless( 'another.txt' in names )
         self.failUnless( 'CVS' in names )
         self.failUnless( '.svn' in names )
@@ -720,15 +725,20 @@
         PATH1 = '%s/%s' % ( SUBDIR, FILENAME1 )
         FILENAME2 = 'another.txt'
         PATH2 = '%s/%s' % ( SUBDIR, FILENAME2 )
+        FILENAME3 = 'another.bak'
+        PATH3 = '%s/%s' % ( SUBDIR, FILENAME3 )
 
         site, tool, ctx = self._makeOne( { PATH1: printable
                                          , PATH2: uppercase
+                                         , PATH3: 'xyz'
                                          } )
 
-        names = ctx.listDirectory( SUBDIR, skip=( FILENAME1, ) )
+        names = ctx.listDirectory(SUBDIR, skip=(FILENAME1,),
+                                  skip_suffixes=('.bak',))
         self.assertEqual( len( names ), 1 )
         self.failIf( FILENAME1 in names )
         self.failUnless( FILENAME2 in names )
+        self.failIf( FILENAME3 in names )
 
 
 class TarballExportContextTests( FilesystemTestBase
@@ -1402,17 +1412,22 @@
         SUBDIR = 'subdir'
         FILENAME1 = 'nested.txt'
         FILENAME2 = 'another.txt'
+        FILENAME3 = 'another.bak'
 
         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
         file1 = self._makeFile( tool, SNAPSHOT_ID, FILENAME1, printable
                               , subdir=SUBDIR )
         file2 = self._makeFile( tool, SNAPSHOT_ID, FILENAME2, uppercase
                               , subdir=SUBDIR )
+        file3 = self._makeFile( tool, SNAPSHOT_ID, FILENAME3, 'abc'
+                              , subdir=SUBDIR )
 
-        names = ctx.listDirectory( SUBDIR, skip=( FILENAME1, ) )
+        names = ctx.listDirectory(SUBDIR, skip=(FILENAME1,),
+                                  skip_suffixes=('.bak',))
         self.assertEqual( len( names ), 1 )
         self.failIf( FILENAME1 in names )
         self.failUnless( FILENAME2 in names )
+        self.failIf( FILENAME3 in names )
 
 
 def test_suite():



More information about the Zope-CVS mailing list