Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | import os |
michael@0 | 2 | import shutil |
michael@0 | 3 | import tempfile |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | # stub file paths |
michael@0 | 7 | files = [('foo.txt',), |
michael@0 | 8 | ('foo', 'bar.txt',), |
michael@0 | 9 | ('foo', 'bar', 'fleem.txt',), |
michael@0 | 10 | ('foobar', 'fleem.txt',), |
michael@0 | 11 | ('bar.txt',), |
michael@0 | 12 | ('nested_tree', 'bar', 'fleem.txt',), |
michael@0 | 13 | ('readonly.txt',), |
michael@0 | 14 | ] |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | def create_stub(): |
michael@0 | 18 | """create a stub directory""" |
michael@0 | 19 | |
michael@0 | 20 | tempdir = tempfile.mkdtemp() |
michael@0 | 21 | try: |
michael@0 | 22 | for path in files: |
michael@0 | 23 | fullpath = os.path.join(tempdir, *path) |
michael@0 | 24 | dirname = os.path.dirname(fullpath) |
michael@0 | 25 | if not os.path.exists(dirname): |
michael@0 | 26 | os.makedirs(dirname) |
michael@0 | 27 | contents = path[-1] |
michael@0 | 28 | f = file(fullpath, 'w') |
michael@0 | 29 | f.write(contents) |
michael@0 | 30 | f.close() |
michael@0 | 31 | return tempdir |
michael@0 | 32 | except Exception, e: |
michael@0 | 33 | try: |
michael@0 | 34 | shutil.rmtree(tempdir) |
michael@0 | 35 | except: |
michael@0 | 36 | pass |
michael@0 | 37 | raise e |