-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_mocks.py
More file actions
42 lines (35 loc) · 1.25 KB
/
update_mocks.py
File metadata and controls
42 lines (35 loc) · 1.25 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
# import required module
import os
import shutil
print('Mocks updating...')
# assign directory
source_directory = 'unit_test_mocks'
target_directory = 'mocks'
# iterate over files in
# that directory
for root, dirs, files in os.walk('.'):
found = root.find('\\mocks')
if found > 0:
mocks_root = root[:found+6]
for filename in files:
if len(root) > found+7:
target
mock = os.path.join(root[found+7:], filename)
else:
mock = filename
target = os.path.join(mocks_root, mock)
source = os.path.join(source_directory, mock)
target_ct = round(os.stat(target).st_mtime)
source_ct = round(os.stat(source).st_mtime)
if target_ct == source_ct:
continue
if target_ct > source_ct:
print('File: '+target)
print('WARNING! Target file newer than source file! Overwrite? (Y/N)')
yn = input()
if (yn.lower() != 'y'):
print('Skipping overwrite!')
continue
print('Updating: '+target)
shutil.copy2(source, target)
print('Done!')