Mercurial > treepkg
changeset 120:007d7f2aa184
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
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 21 May 2008 16:46:16 +0000 |
parents | 92116333ef77 |
children | 890bb70920d6 |
files | test/filesupport.py |
diffstat | 1 files changed, 18 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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 <bh@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"""