-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.py
96 lines (80 loc) · 2.67 KB
/
builder.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
85
86
87
88
89
90
91
92
93
94
95
96
import subprocess
import sys
import re
pathRevisionFile = "ReNode/app/REVISION.py"
pathVersionFile = "ReNode/app/VERSION.py"
deployProjectPath = "C:/Users/Илья/Documents/Arma 3 - Other Profiles/User/missions/resdk_fork.vr/ReNode" #TODO
print(f"Start builder. Args: {sys.argv}")
# arguments inputed: major, minor
#get arguments
doUpdateMajor = False
doUpdateMinor = False
updateVersionFileTask = False
deploySource = False
deployExeOnly = False
args = sys.argv
if len(args) > 1:
#iterate
for argval in args[1:]:
if argval == "major":
doUpdateMajor = True
updateVersionFileTask = True
elif argval == "minor":
doUpdateMinor = True
updateVersionFileTask = True
elif argval in ["deploy","deploy_exe"]:
deploySource = True
updateVersionFileTask = True
if argval == "deploy_exe":
deployExeOnly = True
if updateVersionFileTask:
print("Update version file")
# read version file
versioncontent = open(pathVersionFile).read()
# regex get version values from array
version = re.findall(r'\d+', versioncontent)
#parse version str to int
version = [int(x) for x in version]
if doUpdateMajor:
version[0] += 1
if doUpdateMinor:
version[1] += 1
# write to version file
with open(pathVersionFile, 'w') as f:
f.write("global_version = " + str(version))
# write git short to revision file
print("Update revision file")
# get git rev-parse
revision = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8')
revision = str(revision).replace('\\n', '').replace('\r','').replace('\n','')
with open(pathRevisionFile, 'w') as f:
f.write("global_revision = \"" + str(revision) + "\"")
if deploySource:
import os
import sys
import shutil
try:
data = """
pyinstaller --noconfirm --onefile --windowed --icon "./data/icon.ico" --name "ReNode" --hidden-import "NodeGraphQt" --additional-hooks-dir "./NodeGraphQt-0.6.11" --paths "." "./main.py"
"""
return_ = os.system(data)
print("Compiler result " + str(return_))
if return_ != 0:
raise Exception("Compiler error: Code " + str(return_))
#cleanup deploy folder
print(f'Exists data: {os.path.exists(deployProjectPath + "/data")}')
if os.path.exists(deployProjectPath + "/data") and not deployExeOnly:
shutil.rmtree(deployProjectPath + "/data")
print(f'Exists executable: {os.path.exists(deployProjectPath + "/ReNode.exe")}')
if os.path.exists(deployProjectPath + "/ReNode.exe"):
os.remove(deployProjectPath + "/ReNode.exe")
print("Copy files...")
dest = deployProjectPath
if not deployExeOnly:
shutil.copytree('./data',dest+"/data")
shutil.copyfile('./dist/ReNode.exe',dest+"/ReNode.exe")
print('Done')
sys.exit(0)
except Exception as e:
print(e)
sys.exit(1)