# HG changeset patch # User Bernhard Herzog # Date 1211388376 0 # Node ID 007d7f2aa18479afe17d1456735f339d8f038a55 # Parent 92116333ef779b683e11cc81e30f7ad173ccf12b 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 diff -r 92116333ef77 -r 007d7f2aa184 test/filesupport.py --- a/test/filesupport.py Wed May 21 13:20:36 2008 +0000 +++ b/test/filesupport.py Wed May 21 16:46:16 2008 +0000 @@ -1,4 +1,4 @@ -# Copyright (C) 2007 by Intevation GmbH +# Copyright (C) 2007, 2008 by Intevation GmbH # Authors: # Bernhard Herzog # @@ -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"""