-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
90 lines (78 loc) · 2.18 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 time
import shutil
import subprocess
from sys import argv
from pathlib import Path
from build_aux._data import BASE_DIR
from votm import __version__
start = time.time()
argv = " ".join(argv[1:])
SPEC_FILE = [
"manageDist.spec",
"voteDist.spec",
"manageBundledBin.spec",
"voteBundledBin.spec",
]
TEMP_FILE = [f"TEMP_{i}.spec" for i, _ in enumerate(SPEC_FILE)]
for i, j in enumerate(SPEC_FILE):
try:
shutil.copy(BASE_DIR.joinpath(f"build_aux/{j}"), BASE_DIR.joinpath(TEMP_FILE[i]))
except:
for i in TEMP_FILE:
try:
Path(i).unlink()
except:
pass
os.chdir(BASE_DIR)
command = [["pyinstaller", i, "--noconfirm", argv] for i in TEMP_FILE]
if argv.strip() == "":
command = [i[:-1] for i in command]
for i, j in enumerate(command):
try:
print(
f"• Generating Build [{i+1}/{len(command)}]...",
end="",
)
proc = subprocess.run(
j,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
print("ok", end=" ")
print(f"ReturnCode: {proc.returncode}")
except subprocess.CalledProcessError as e:
print(f" Error: {e.returncode}")
raise
dist_dir = BASE_DIR.joinpath("dist")
source = dist_dir.joinpath(f"votm_dist_{__version__}_vote")
target = dist_dir.joinpath(f"votm_dist_{__version__}_manage")
counter = 0
print("• Collecting...")
# collecting
for obj in source.iterdir():
if obj.is_file():
try:
obj.rename(target / obj.name)
except:
pass
counter += 1
if counter > 1000:
break
# renaming
try:
target.rename(target.parent.joinpath(f"votm_dist_{__version__}"))
except FileExistsError:
shutil.rmtree(
target.parent.joinpath(f"votm_dist_{__version__}"), ignore_errors=True
)
target.rename(target.parent.joinpath(f"votm_dist_{__version__}"))
print("• Cleaning up...")
# cleaning up
shutil.rmtree(str(source), ignore_errors=True)
for i in TEMP_FILE:
Path(i).unlink()
end = time.time()
print(f"Build compeletion in {end-start} seconds")