forked from PostgresApp/PostgresApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_download_targets.py
29 lines (28 loc) · 1.13 KB
/
update_download_targets.py
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
import glob
for makefile in glob.glob('src*/makefile'):
print('Processing', makefile)
download_target = 'download: '
clean_target = 'clean: '
with open(makefile, 'r+') as f:
lines = f.readlines()
replace = False
for i in range(len(lines)):
if not lines[i].strip().startswith('#') and 'curl' in lines[i].lower() and ':' in lines[i-1]:
download_target += lines[i-1].partition(':')[0] + ' '
if lines[i].lower().startswith('clean-') and ':' in lines[i]:
clean_target += lines[i].partition(':')[0] + ' '
if 'clean:' in lines[i]:
download_line = i+2
clean_line = i
if 'check:' in lines[i]:
download_line = i+1
if 'download:' in lines[i]:
download_line = i
download_replace = True
if download_replace:
lines[download_line] = download_target+'\n'
else:
lines.insert(download_line, download_target+'\n')
lines[clean_line] = clean_target+'\n'
f.seek(0)
f.writelines(lines)