-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilecmp_mkexamples.py
More file actions
47 lines (32 loc) · 1.17 KB
/
filecmp_mkexamples.py
File metadata and controls
47 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
def mkfile(filename, body=None):
with open(filename, "wt") as f:
f.write(body or filename)
def make_example_dir(top):
if not os.path.exists(top):
os.mkdir(top)
curdir = os.getcwd()
os.chdir(top)
os.mkdir("dir1")
os.mkdir("dir2")
mkfile("dir1/file_only_in_dir1")
mkfile("dir2/file_only_in_dir2")
os.mkdir("dir1/dir_only_in_dir1")
os.mkdir("dir2/dir_only_in_dir2")
os.mkdir("dir1/common_dir")
os.mkdir("dir2/common_dir")
mkfile("dir1/common_file", "this file is the same")
os.link("dir1/common_file", "dir2/common_file")
mkfile("dir1/contents_differ")
mkfile("dir2/contents_differ")
# update the access and modification times so most of the stat results will match.
st = os.stat("dir1/contents_differ")
os.utime("dir2/contents_differ", (st.st_atime, st.st_mtime))
mkfile("dir1/file_in_dir1", "This is a file in dir1")
os.mkdir("dir2/file_in_dir1")
os.chdir(curdir)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__) or os.getcwd())
make_example_dir("example")
make_example_dir("example/dir1/common_dir")
make_example_dir("example/dir2/common_dir")