-
Notifications
You must be signed in to change notification settings - Fork 4
/
fix-timestamps
executable file
·107 lines (83 loc) · 2.47 KB
/
fix-timestamps
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
import os
import time
import filecmp
import stat
baseline = int(time.time()) - 3600
def set_timestamp_as_baseline(paths=[]):
for dirname in paths:
for root, dirs, files in os.walk(dirname):
path = root.split(os.sep)
for file in files:
path = os.path.join(root, file)
print("baseline:", path)
os.utime(path, (baseline, baseline))
def set_timestamp_on_directory_pair(dir1, dir2, timestamp):
diff = filecmp.dircmp(dir1, dir2)
# For files which are the same, ensure that timestamp on file
# in dir2 is the same as that in dir1.
for name in diff.same_files:
path1 = os.path.join(dir1, name)
path2 = os.path.join(dir2, name)
print('same:', path2)
stats = os.stat(path1)
os.utime(path2, (stats[stat.ST_MTIME], stats[stat.ST_MTIME]))
for name in diff.diff_files:
path2 = os.path.join(dir2, name)
print('diff:', path2)
os.utime(path2, (timestamp, timestamp))
for dir in diff.common_dirs:
set_timestamp_on_directory_pair(os.path.join(dir1, dir),
os.path.join(dir2, dir), timestamp)
def set_timestamp_on_directories(dirs):
timestamp = baseline + 60
current = None
for next in dirs:
if current is not None:
set_timestamp_on_directory_pair(current, next, timestamp)
timestamp += 60
current = next
common_base_dirs = [
"common-base-v1",
"common-base-v2",
]
set_timestamp_as_baseline(common_base_dirs)
set_timestamp_on_directories(common_base_dirs)
flask_app_dirs = [
"flask-app-v1",
"flask-app-v2",
"flask-app-v3",
"flask-app-v4",
"flask-app-v5",
"flask-app-v6",
"flask-app-v7",
"flask-app-v8",
"flask-app-v9",
]
set_timestamp_as_baseline(flask_app_dirs)
set_timestamp_on_directories(flask_app_dirs)
greeting_dirs = [
"greeting-v1",
"greeting-v2",
"greeting-v3",
"greeting-v4",
"greeting-v5",
"greeting-v6",
"greeting-v7",
"greeting-v8",
]
set_timestamp_as_baseline(greeting_dirs)
set_timestamp_on_directories(greeting_dirs)
python_base_dirs = [
"python-base-v1",
"python-base-v2",
"python-base-v3",
"python-base-v4",
]
set_timestamp_as_baseline(python_base_dirs)
set_timestamp_on_directories(python_base_dirs)
python_onbuild_dirs = [
"python-onbuild-v1",
]
set_timestamp_as_baseline(python_onbuild_dirs)
set_timestamp_on_directories(python_onbuild_dirs)