-
Notifications
You must be signed in to change notification settings - Fork 42
/
uddocs.py
31 lines (24 loc) · 1.05 KB
/
uddocs.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
30
31
import os.path as path
from lifelib._dirs import TEMPLATES
proj_dir = path.normpath(path.dirname(path.abspath(__file__)) + "\\..")
projects = TEMPLATES
def inplace_change(filename, oldstr, newstr):
# Code taken from:
# https://stackoverflow.com/questions/4128144/replace-string-within-file-contents
# Safely read the input filename using 'with'
with open(filename, mode='r', encoding='utf-8') as f:
s = f.read()
if oldstr not in s:
print('"{oldstr}" not found in {filename}.'.format(**locals()))
return
# Safely write the changed content, if found in the file
msg = 'Changing "{oldstr}" to "{newstr}" in {filename}'.format(**locals())
with open(filename, mode='w', encoding='utf-8') as f:
print(msg)
s = s.replace(oldstr, newstr)
f.write(s)
for prj in projects:
s = (proj_dir + "\\lifelib\\projects\\" + prj + "\\").replace("\\", "\\\\")
trg = ".\\build\\html\\projects\\generated\\" + prj + ".build_input.html"
if path.exists(trg):
inplace_change(trg, s, '')