-
Notifications
You must be signed in to change notification settings - Fork 18
/
version.py
81 lines (74 loc) · 2.65 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import re, sys, fileinput
version = "{{version}}"
def readPodVersion(path):
try:
with open (path, "r", encoding="utf-8") as podspec:
for row in podspec:
if row.strip(" ").startswith("s.version"):
global version
version = row.replace(" ","")
version = re.findall(r'\'([\S\s]+)\'', version)[0]
if version == '':
print("复制失败")
sys.exit(-1)
else:
print('新 version:{}'.format(version))
except Exception as exception:
print(exception)
sys.exit(-1)
def syncReleasPod(replacePath):
try:
for line in fileinput.input(replacePath, backup='', inplace=True):
if line.strip(" ").startswith("s.version"):
old = line.replace(" ", "")
old = re.findall(r'\'([\S\s]+)\'', old)[0]
line = line.replace(old, version)
sys.stderr.write("旧版本:{} 新版本:{}".format(old, version))
print(line.rstrip())
else:
print(line.rstrip())
except Exception as e:
sys.stderr.write(e)
sys.exit(-1)
def syncSDKVersion(replacePath, check=True):
try:
i = 1
versionNum = 0
same = False
for line in fileinput.input(replacePath, backup='', inplace=True):
if line.strip().endswith("version"):
print(line.rstrip())
versionNum = i
elif versionNum != 0 and i == versionNum + 2:
old = line.rstrip().replace(" ", "")
matches = re.findall(r"\@\"([^\"]+)", old)
if len(matches) == 0:
sys.stderr.write("正则提取失败")
else:
old = matches[0]
if check:
same = old == version
else:
line = line.replace(old, version)
sys.stderr.write("旧版本:{} 新版本:{}\n".format(old, version))
print(line.rstrip())
else:
print(line.rstrip())
i += 1
if check and not same:
sys.stderr.write("版本校验失败")
sys.exit(-1)
except Exception as e:
sys.stderr.write(e)
sys.exit(-1)
def main(argv):
print(argv)
print(version)
# 默认同步
if len(argv) == 1:
syncSDKVersion("./WhiteSDK/Classes/WhiteSDK.m", False)
elif argv[1] == 'check':
syncSDKVersion("./WhiteSDK/Classes/WhiteSDK.m", True)
if __name__ == "__main__":
readPodVersion("./WhiteSDK.podspec")
main(sys.argv)