[Treepkg-commits] r45 - trunk/test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 21 18:46:17 CEST 2008


Author: bh
Date: 2008-05-21 18:46:16 +0200 (Wed, 21 May 2008)
New Revision: 45

Modified:
   trunk/test/filesupport.py
Log:
Extend/Modify FileTestMixin.create_files:

 - Make it possible to specify the permissions of the files

 - Remove the file hierarchy if it already exists

 - Create the base directory and its parents if it doesn't exist


Modified: trunk/test/filesupport.py
===================================================================
--- trunk/test/filesupport.py	2008-05-21 13:20:36 UTC (rev 44)
+++ trunk/test/filesupport.py	2008-05-21 16:46:16 UTC (rev 45)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2008 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -73,23 +73,33 @@
         return dirname
 
     def create_files(self, directory, filedesc):
-        """Creates a hieararchy of directories and files in directory.
+        """Creates a hierarchy of directories and files in directory.
         The filedesc parameter should be a sequence of (name, contents)
-        pairs.  Each pair describes one entry of the directory.  If
-        contents is an instance of list, the entry is a subdirectory and
-        the contents is a list in the same format as filedesc and passed
+        pairs or (name, permissions, contents) triples.  Each item of
+        the sequence describes one entry of the directory.  If contents
+        is an instance of list, the entry is a subdirectory and the
+        contents is a list in the same format as filedesc and passed
         recursively to the create_files method.  If contents is a
         string, the new directory entry is a normal file and contents is
-        the contents of the file.
+        the contents of the file.  The permissions if present, should be
+        an int specifying the files permissions (setting permissions
+        doesn't work yet for directories).
         """
-        for name, contents in filedesc:
+        shutil.rmtree(directory, True)
+        os.makedirs(directory)
+        for item in filedesc:
+            if len(item) == 3:
+                name, permissions, contents = item
+            else:
+                name, contents = item
+                permissions = None # use default permissions
             if isinstance(contents, list):
                 # a list as contents indicates a directory
                 newdir = os.path.join(directory, name)
                 os.mkdir(newdir)
                 self.create_files(newdir, contents)
             else:
-                writefile(os.path.join(directory, name), contents)
+                writefile(os.path.join(directory, name), contents, permissions)
 
     def checkFileContents(self, filename, contents):
         """check the contents of a file"""



More information about the Treepkg-commits mailing list