-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
184 lines (175 loc) · 7.54 KB
/
build.py
File metadata and controls
184 lines (175 loc) · 7.54 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#-----------------------------------------------------------
# BUILD
# Module used to build .exe file from current files using
# pyInstaller. All needed documentation is written here
# in further comment blocks.
#-----------------------------------------------------------
import sys; sys.pycache_prefix = "_temp/cache"
import PyInstaller.__main__
import PyInstaller
import os; fpath = os.path.dirname(os.path.abspath("build.py"))
from core.file_system.repo_manag import file_lister, dir_lister
from distutils.dir_util import copy_tree
from os.path import exists
import stat, shutil, traceback
#-----------------------------------------------------------
# FORGE
# Function used to execute pyInstaller commands precised
# later in module
# References DefaultRun class as configurator for all
# options (when changing devices, change directories paths)
#-----------------------------------------------------------
class DefaultRun:
# ----------------------------------------------------------------------
# CONFIGURATION OF BUILD
# Adjust values here to make build customised more to your needs
# ----------------------------------------------------------------------
# directory of the game
core_path = f"{fpath}/"
game_name = "Isle of Ansur"
icon_path = core_path + "ioa.ico"
# directory for outcome
export_path = "D:/Ministerstwo Kalibracyjne/PyCharm_Projects/[builds]/"
full_export_path = export_path + game_name + "/"
# ----------------------------------------------------------------------
# REFERENCE DOCS
# https://github.com/pyinstaller/pyinstaller/blob/v4.5.1/doc/usage.rst
# ----------------------------------------------------------------------
forge_builder = [
core_path + "main.py",
"--onedir",
"--onefile",
"--noupx", # if you are going to change this, please redirect upx to net source (requests library?) or import files if license allows you to do so
"--clean",
"--name=" + game_name,
"--icon=" + icon_path,
"--distpath=" + export_path + game_name + "/",
"--workpath=" + core_path + "system/cache/pyinstaller",
"--specpath=" + core_path + "system/cache/pyinstaller"
]
ommitted_elements = [ # list of files that are deleted after finishing the build
full_export_path + ".git",
full_export_path + ".idea",
full_export_path + ".dev",
full_export_path + ".fps",
full_export_path + ".breakpoints",
full_export_path + ".gitignore",
full_export_path + "modding_guide.odt",
full_export_path + "roadmap.md",
full_export_path + "temp.md",
full_export_path + "core/data/pack_manag/pack_errors.yaml",
full_export_path + "core/data/pack_manag/pack_order.yaml",
# folders not used anymore
full_export_path + "docsv",
full_export_path + "gui",
full_export_path + "core/assets/fonts",
# caches
full_export_path + "_temp",
full_export_path + "__pycache__",
full_export_path + "gui/__pycache__",
full_export_path + "system/__pycache__",
full_export_path + "utils/__pycache__",
full_export_path + "system/core/__pycache__",
full_export_path + "system/cache/__pycache__",
full_export_path + "system/cache/pyinstaller",
# rubbish
full_export_path + "ioase.nim",
full_export_path + "ioase.nims",
full_export_path + "todoes.md",
full_export_path + "pjs.html"
]
@classmethod
def patch(cls, patchName) -> list:
return [
cls.core_path + "patch.py",
"--onedir",
"--onefile",
"--noupx",
"--clean",
"--name=" + patchName,
"--distpath=" + cls.export_path + cls.game_name + "/",
"--workpath=" + cls.core_path + "system/cache/pyinstaller",
"--specpath=" + cls.core_path + "system/cache/pyinstaller"
]
# function used to delete elements excluded in list above
def file_deleting(delete_list):
def on_rm_error(func, path, exc_info):
os.chmod(path, stat.S_IWRITE)
os.unlink(path)
for i in delete_list:
try:
shutil.rmtree(i, onerror=on_rm_error)
except FileNotFoundError: pass
# removes logs
for l in file_lister(f"{DefaultRun.full_export_path}core/logs/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}core/logs/{l}", onerror=on_rm_error)
except: pass
# removes packs
for pk in file_lister(f"{DefaultRun.full_export_path}packs/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}packs/{pk}", onerror=on_rm_error)
except: pass
# removes saves
for sv in file_lister(f"{DefaultRun.full_export_path}saves/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}saves/{sv}", onerror=on_rm_error)
except: pass
for sv in dir_lister(f"{DefaultRun.full_export_path}saves/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}saves/{sv}", onerror=on_rm_error)
except: pass
# removes scripts that are not vanilla
for scr in file_lister(f"{DefaultRun.full_export_path}scripts/"):
if scr != "example_script.py":
try:
shutil.rmtree(f"{DefaultRun.full_export_path}scripts/{scr}", onerror=on_rm_error)
except: pass
# removes mods that are not vanilla:
# statpacks
for stp in dir_lister(f"{DefaultRun.full_export_path}stats/"):
if stp != "ansur":
try:
shutil.rmtree(f"{DefaultRun.full_export_path}stats/{stp}", onerror=on_rm_error)
except: pass
for stp in file_lister(f"{DefaultRun.full_export_path}stats/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}stats/{stp}", onerror=on_rm_error)
except: pass
# worldpacks
for wdp in dir_lister(f"{DefaultRun.full_export_path}worlds/"):
if wdp != "ansur":
try:
shutil.rmtree(f"{DefaultRun.full_export_path}worlds/{wdp}", onerror=on_rm_error)
except: pass
for wdp in file_lister(f"{DefaultRun.full_export_path}worlds/"):
try:
shutil.rmtree(f"{DefaultRun.full_export_path}worlds/{wdp}", onerror=on_rm_error)
except: pass
# main function for running builder
def forge():
PyInstaller.__main__.run(
DefaultRun.forge_builder
)
copy_tree(DefaultRun.core_path, DefaultRun.full_export_path) # copies all files over
file_deleting(DefaultRun.ommitted_elements) # deletes files excluded in list
if exists("patch.py"):
# handler of possible patch - please include comment with such syntax to set patch name:
# # PATCH_NAME = nameOfThePatch
with open("patch.py") as p_file:
p_name = "Patch"
for line in p_file.readlines():
if line.startswith("# PATCH_NAME = "):
p_name = line.replace("# PATCH_NAME = ", "").replace("\n", "")
PyInstaller.__main__.run(DefaultRun.patch(p_name))
#============================================================================================================
print('{:^65}'.format("\33[35m ------------------------------"))
print('{:^65}'.format(" ISLE OF ANSUR BUILD CONSTRUCTOR "))
print("\n")
print('{:^65}'.format("----------------------------"))
print('{:^65}'.format("------------------------------------------------------------------------- \033[0m"))
try:
forge()
print('{:^75}'.format("\033[92m Build successful \033[0m"))
except:
traceback.print_exc()