-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_version.py
executable file
·60 lines (51 loc) · 1.99 KB
/
update_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# !/usr/bin/python
# -*- coding: utf-8 -*-
import re
import os
import codecs
MAX = 1000
def update_version():
updated_content = None
new_version = None
with codecs.open('setup.py', 'r', encoding='utf-8') as cfg:
content = cfg.read()
version_pattern = r'version\s*=\s*\"(\d+\.\d+\.\d+)\"'
ret = re.search(version_pattern, content)
if ret:
old_version = ret.group(1)
new_version = old_version.split('.')
count = len(new_version)
isValidVer = True
for num in new_version:
if int(num) >= MAX:
isValidVer = False
break
if not isValidVer:
print("The Version Number is not valid!!!")
exit(-1)
isReachMaxVer = True
for num in new_version:
if int(num) != MAX - 1:
isReachMaxVer = False
if isReachMaxVer:
print("The Version has reach the max version number!!!")
exit(-1)
lastIndex = count - 1
index = lastIndex
increase_index = lastIndex
advance = 0
while index >= 0:
addition = int(new_version[index]) + advance + ( 1 if index == increase_index else 0)
number = addition % MAX
advance = int(addition / MAX)
new_version[index] = str(number)
index = index - 1
new_version = '.'.join(new_version)
updated_content = content.replace(content[ret.start(1):ret.end(1)], new_version)
if new_version and updated_content:
with codecs.open('setup.py', 'w', encoding='utf-8') as cfg:
cfg.write(updated_content)
with codecs.open(os.path.join('OrzMC','app', 'Version.py'), 'w', encoding='utf-8') as version:
version.write('ORZMC_VERSION_NUMBER="%s"' % new_version)
if __name__ == '__main__':
update_version()