forked from hmphus/there-edge
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SyncVersion.py
100 lines (89 loc) · 3.14 KB
/
SyncVersion.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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import sys
def get_version():
with open('Installer/Installer.vdproj', 'r', encoding='utf-8-sig') as file:
lines = [l.strip() for l in file.readlines()]
path = ['']
for line in lines:
if line == '{':
path.append('')
continue
if line == '}':
path.pop()
continue
match = re.search(r'"([^"]+)" = "([^"]+)"', line)
if match is not None:
path[-1] = match.group(1)
if '.'.join(path) == 'DeployProject.Deployable.Product.ProductVersion':
return match.group(2).split(':')[1]
continue
match = re.search(r'"([^"]+)"', line)
if match is not None:
path[-1] = match.group(1)
continue
return None
def apply_version_rc(name, version):
with open('%s/%s.rc' % (name, name), 'r', encoding='utf-16') as file:
lines = [l.rstrip('\n') for l in file.readlines()]
for (i, line) in enumerate(lines):
match = re.match(r'^ ([A-Z]+?)VERSION ', line)
if match is not None:
line = ' %sVERSION %s' % (
match.group(1),
','.join(version.split('.') + ['0']),
)
lines[i] = line
continue
match = re.match(r'^( +)VALUE "([A-Za-z]+)Version",', line)
if match is not None:
line = '%sVALUE "%sVersion", "%s.0"' % (
match.group(1),
match.group(2),
version,
)
lines[i] = line
continue
with open('%s/%s.rc' % (name, name), 'w', encoding='utf-16') as file:
file.write('\n'.join(lines) + '\n')
def apply_version_py(name, version):
lines = [
"# -*- coding: utf-8 -*-",
"",
"VERSION = '%s'" % version,
]
with open('%s/version.py' % name, 'w') as file:
file.write('\n'.join(lines))
def apply_version_rs(name, version):
with open('%s/version.rs' % name, 'r') as file:
lines = [l.rstrip('\n') for l in file.readlines()]
for (i, line) in enumerate(lines):
match = re.match(r'^( +(?:file|prod)vers=\()[0-9]+, [0-9]+, [0-9]+, [0-9]+(\).*$)', line)
if match is not None:
line = '%s%s%s' % (
match.group(1),
', '.join(version.split('.') + ['0']),
match.group(2),
)
lines[i] = line
continue
match = re.match(r'^( +StringStruct\(u\'(?:File|Product)Version\', u\')[.0-9]+(\'\).*$)', line)
if match is not None:
line = '%s%s.0%s' % (
match.group(1),
version,
match.group(2),
)
lines[i] = line
continue
with open('%s/version.rs' % name, 'w') as file:
file.write('\n'.join(lines) + '\n')
if __name__ == '__main__':
version = get_version()
print('Version: %s' % version)
apply_version_rc('BrowserProxy', version)
apply_version_rc('FlashProxy', version)
apply_version_py('SetupThereEdge', version)
apply_version_rs('SetupThereEdge', version)