-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.py
59 lines (53 loc) · 1.58 KB
/
bump_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
# Author: Pierce Brooks
import os
import sys
from packaging.version import parse
def bump(path, before, after, affix):
success = False
if not (os.path.exists(path)):
return success
before = affix+before+affix
after = affix+after+affix
descriptor = open(path, "r")
lines = descriptor.readlines()
descriptor.close()
for i in range(len(lines)):
line = lines[i]
if not (before in line):
continue
lines[i] = line.replace(before, after)
success = True
#print(before+" = "+after)
break
descriptor = open(path, "w")
for i in range(len(lines)):
line = lines[i]
descriptor.write(line)
descriptor.close()
return success
def run(version):
if not ("." in version):
return -1
after = parse(version)
before = str(after.major)+"."+str(after.minor-1)
success = bump(os.path.join(os.getcwd(), "upload.bat"), before, str(after), "-")
success = bump(os.path.join(os.getcwd(), "setup.py"), before, str(after), "\"") and success
before += "."+str(after.micro)
if (len(str(after).split(".")) > 2):
success = bump(os.path.join(os.getcwd(), "buildster", "__init__.py"), before, str(after), "\"") and success
else:
success = bump(os.path.join(os.getcwd(), "buildster", "__init__.py"), before, str(after)+"."+str(after.micro), "\"") and success
if not (success):
return -2
return 0
def launch(arguments):
if (len(arguments) < 2):
return False
version = arguments[1]
result = run(version)
print(str(result))
if not (result == 0):
return False
return True
if (__name__ == "__main__"):
print(str(launch(sys.argv)))