-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_bump.py
84 lines (66 loc) · 2.11 KB
/
version_bump.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
#!/usr/bin/env python
import subprocess
import re
import os
def perl_pie(search, replace, f):
cmd = [
'perl',
'-pi.bak',
'-e',
's/%s/%s/g' % (search, replace),
f
]
subprocess.check_call(cmd)
def main():
data = ''
version_name_pattern = '([0-9]+.[0-9]+)'
version_code_pattern = '([0-9]+)'
version_number_ui_chunk = '<string>version: %s<\/string>'
version_number_android_version_name_chunk = 'android:versionName="%s"'
version_number_android_version_code_chunk = 'android:versionCode="%s"'
with open('android/AndroidManifest.xml', 'r') as input_file:
data = input_file.read()
if not data:
print('Unable to open android/AndroidManifest.xml. Exiting 1.')
exit(1)
version_numbers = re.findall(
version_number_android_version_name_chunk % version_name_pattern,
data
)
build_version = re.findall(
version_number_android_version_code_chunk % version_code_pattern,
data
)
major_version = str(int(version_numbers[0].split('.')[0]))
build_version = str(int(build_version[0]) + 1)
new_version = '%s.%s' % (
major_version,
build_version
)
print('Running perl pie.')
try:
perl_pie(
version_number_ui_chunk % version_name_pattern,
version_number_ui_chunk % new_version,
'views/homeview.ui'
)
perl_pie(
version_number_android_version_name_chunk % version_name_pattern,
version_number_android_version_name_chunk % new_version,
'android/AndroidManifest.xml'
)
perl_pie(
version_number_android_version_code_chunk % version_code_pattern,
version_number_android_version_code_chunk % build_version,
'android/AndroidManifest.xml'
)
except:
print('One or more of the perl pies failed. Exiting 1.')
exit(1)
print('Removing backup files')
os.unlink('views/homeview.ui.bak')
os.unlink('android/AndroidManifest.xml.bak')
print('Fin')
exit(0)
if __name__ == '__main__':
main()