-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildutil.py
47 lines (43 loc) · 1.22 KB
/
buildutil.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
import sys, os, shutil
from os.path import dirname, join
VERSION_FILE = join(dirname(__file__), "src", "data", "buildno.txt")
def MakeArtifact():
with open(VERSION_FILE) as f:
ver = f.read()
shutil.copytree(join(dirname(__file__), "bin"), join(dirname(__file__), "artifacts", ver))
def MakeVersion(add="0.0.1", no=None):
with open(VERSION_FILE) as f:
ver = f.read()
if " " in ver:
ver, alp = ver.split(" ", maxsplit=1)
alp = " " + alp
else:
alp = ""
if no is None:
ver = [int(s) for s in ver.split(".")]
add = [int(s) for s in add.split(".")]
for i in range(len(add)):
ver[i] += add[i]
shouldzero = False
for i in range(len(add)):
if shouldzero:
ver[i] = 0
if add[i] > 0:
shouldzero = True
ver = ".".join([str(s) for s in ver])
else:
ver = no
with open(VERSION_FILE, "w") as f:
f.write(ver + alp)
if __name__=='__main__':
if len(sys.argv) >= 2:
if sys.argv[1] == "version":
if len(sys.argv) >= 3:
if sys.argv[2] == "add" and len(sys.argv) >= 4:
MakeVersion(add=sys.argv[3])
else:
MakeVersion(no=" ".join(sys.argv[2:]))
elif sys.argv[1] == "artifact":
MakeArtifact()
else:
print(f"Usage: python {sys.argv[0]} (args)\n\tversion add x.y.z\n\tversion x.y.z ...")