michael@0: import os michael@0: import shutil michael@0: import tempfile michael@0: michael@0: michael@0: # stub file paths michael@0: files = [('foo.txt',), michael@0: ('foo', 'bar.txt',), michael@0: ('foo', 'bar', 'fleem.txt',), michael@0: ('foobar', 'fleem.txt',), michael@0: ('bar.txt',), michael@0: ('nested_tree', 'bar', 'fleem.txt',), michael@0: ('readonly.txt',), michael@0: ] michael@0: michael@0: michael@0: def create_stub(): michael@0: """create a stub directory""" michael@0: michael@0: tempdir = tempfile.mkdtemp() michael@0: try: michael@0: for path in files: michael@0: fullpath = os.path.join(tempdir, *path) michael@0: dirname = os.path.dirname(fullpath) michael@0: if not os.path.exists(dirname): michael@0: os.makedirs(dirname) michael@0: contents = path[-1] michael@0: f = file(fullpath, 'w') michael@0: f.write(contents) michael@0: f.close() michael@0: return tempdir michael@0: except Exception, e: michael@0: try: michael@0: shutil.rmtree(tempdir) michael@0: except: michael@0: pass michael@0: raise e