-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
90 lines (71 loc) · 2.27 KB
/
build.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
import os
import random
import shutil
import sys
import PyInstaller.__main__
def build(name, console, onefile, uac_admin, icon, files, folders):
work_path = "build"
while os.path.isdir(work_path):
work_path = f"build_{random.randint(1, 1_000_000_000)}"
work_path = os.path.join(os.path.abspath("."), work_path)
result_path = os.path.abspath(".")
if os.path.isfile(os.path.join(result_path, f"{name}.exe")):
os.remove(os.path.join(result_path, f"{name}.exe"))
run_list = ['main.py',
'--noconfirm',
'--clean',
'--name', name,
'--workpath', work_path,
'--specpath', work_path,
'--distpath', result_path]
if console:
run_list.append("--console")
else:
run_list.append("--noconsole")
if onefile:
run_list.append("--onefile")
else:
run_list.append("--onedir")
if uac_admin:
run_list.append("--uac-admin")
if icon != "":
icon_path = os.path.join(os.path.abspath("."), icon)
if not os.path.isfile(icon_path):
raise Exception("Invalid icon!")
else:
run_list.extend(('--icon', icon_path))
for file in files:
if os.path.isfile(os.path.join(os.path.abspath("."), file)):
run_list.extend(('--add-data', f'{os.path.join(os.path.abspath("."), file)};{os.path.dirname(file)}'))
else:
raise Exception("Invalid file!")
for folder in folders:
if os.path.isdir(folder):
for walk in os.walk(folder, followlinks=False):
for file in walk[2]:
if os.path.isfile(os.path.join(walk[0], file)):
run_list.extend(('--add-data', f'{os.path.join(os.path.abspath("."), os.path.join(walk[0], file))};{os.path.dirname(os.path.join(walk[0], file))}'))
else:
raise Exception("Invalid folder!")
else:
raise Exception("Invalid folder!")
PyInstaller.__main__.run(run_list)
shutil.rmtree(path=work_path, ignore_errors=True)
def main():
name = "Key-Click"
version = "2.0.1"
console = False
onefile = True
uac_admin = False
icon = "resources\\key-click-icon.ico"
files = []
folders = ["resources"]
if len(sys.argv) > 1 and sys.argv[1] == "--version":
print(version)
elif len(sys.argv) > 1 and sys.argv[1] == "--name":
print(name)
else:
name = f"{name}-v{version}"
build(name, console, onefile, uac_admin, icon, files, folders)
if __name__ == '__main__':
main()