forked from SasaKaranovic/VU-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_version.py
40 lines (31 loc) · 1.43 KB
/
make_version.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
32
33
34
35
36
37
38
39
40
'''
Simple python script to dynamically add version tag to HTML files
'''
import os.path
from datetime import datetime
def apply_version_tag(filepath, tag_placeholder, tag_value):
if not os.path.isfile(filepath):
print(f'Not a file! {filepath}')
return False
with open(filepath, 'r', encoding='utf-8') as template:
content = template.read()
if tag_placeholder in content:
print(f"Patching `{filepath}` with tag `{tag_value}`")
content = content.replace(tag_placeholder, tag_value)
with open(filepath, 'w', encoding='utf-8') as stamped:
stamped.write(content)
return True
if __name__ == '__main__':
# Add version tag to HTML template
dt = datetime.now()
version_tag = dt.strftime('%Y%m%d')
footer_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'www', 'views', 'footer.html')
apply_version_tag(footer_path, '{{VU_VERSION}}', version_tag)
# Update installer version
version_major = dt.strftime('%Y')
version_minor = dt.strftime('%m')
version_build = dt.strftime('%d')
installer_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'installer', 'install.nsi')
apply_version_tag(installer_path, '{{VU_VERSION_MAJOR}}', version_major)
apply_version_tag(installer_path, '{{VU_VERSION_MINOR}}', version_minor)
apply_version_tag(installer_path, '{{VU_VERSION_BUILD}}', version_build)