-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_tasks.py
executable file
·138 lines (100 loc) · 3.93 KB
/
build_tasks.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
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
#!/bin/python
import platform
import os
import glob
import shutil
import datetime
FORCE_REBUILD = True
UI_SOURCE_FOLDER = './forms'
UIPY_TARGET_FOLDER = './pyforms'
QRC_SOURCE_FOLDER = '.'
QRC_PY_TARGET_FOLDER = UIPY_TARGET_FOLDER
QRC_FILENAME = "materials.qrc"
WIN_UIC_EXEC = r"C:\Users\priganns\AppData\Roaming\Python\Python311\Scripts\pyside6-uic.exe "
MAC_UIC_EXEC = ""
LINUX_UIC_EXEC = "pyside6-uic"
MAC_RCC_EXEC = ""
WIN_RCC_EXEC = r"C:\Users\priganns\AppData\Roaming\Python\Python311\Scripts\pyside6-rcc.exe "
LINUX_RCC_EXEC = "pyside6-rcc"
class CmdCol:
Black = "\u001b[30;1m"
Red ="\u001b[31:1m"
Green= "\u001b[32;1m"
Yellow= "\u001b[33;1m"
Blue= "\u001b[34;1m"
Magenta= "\u001b[35;1m"
Cyan = "\u001b[36;1m"
White = "\u001b[37;1m"
Reset = "\u001b[0m"
def print_info(info_str):
i = 'INFO'
print(CmdCol.Cyan+f"[ {i:<5} ] {info_str}"+CmdCol.Reset)
def print_warn(s):
i = 'WARN'
print(CmdCol.Yellow+f"[ {i:<5} ] {s}"+CmdCol.Reset)
def print_err(s):
i = 'ERROR'
print(CmdCol.Red+f"[ {i:<5} ] {s}"+CmdCol.Reset)
def build_target_folder(targetpath):
if os.path.exists(targetpath):
print_warn("Folder exists, deleting content.")
shutil.rmtree(targetpath)
print_info(f"Creating {targetpath} folder")
os.mkdir(targetpath)
with open(targetpath+"/__init__.py",'w') as initFile:
initFile.write(f"#Auto Generated init File\n#Created {datetime.datetime.now()}\nfrom . import materials_rc")
def build_ui_files(sourcepath,targetpath):
sys_name = platform.system()
print_info(f"Converting:")
maxUiFiles = len(glob.glob1(sourcepath,"*.ui"))
convertCounter = 0
for file in os.listdir(sourcepath):
if file.endswith('.ui'):
if sys_name == 'Darwin':
exec_path = MAC_UIC_EXEC
elif sys_name == 'Windows':
exec_path = WIN_UIC_EXEC
else:
exec_path = LINUX_UIC_EXEC
ret = os.system(exec_path+f" {sourcepath}/{file}" +f" -o {targetpath}/ui_{file.replace('.ui','.py')}")
if ret:
print_err(f"Error during system call: {ret}")
convertCounter+=1
print(f"[{round(convertCounter/maxUiFiles*100,1):<5} % ] "+f"{sourcepath+'/'+file:<40} -->\t{UIPY_TARGET_FOLDER}/ui_{file.replace('.ui','.py')}")
def build_resources(sourcepath,targetpath,filename):
sys_name = platform.system()
print_info("Rebuilding QRC Resources:")
if sys_name == 'Darwin':
exec_path = MAC_RCC_EXEC
elif sys_name == 'Windows':
exec_path = WIN_RCC_EXEC
else:
exec_path = LINUX_RCC_EXEC
os.system(exec_path+f" {sourcepath+'/'+filename} -o {targetpath+'/'+filename.replace('.qrc','_rc.py')}")
print(f"[ {'DONE':<5} ] {sourcepath+'/'+filename:<40} -->\t{targetpath+'/'+filename.replace('.qrc','_rc.py')}")
def clean_ui_files(uiFilePath):
stat = 'import materials_rc'
print_info(f"Replacing wrong import statement: {stat}")
fileToChange = len(glob.glob1(uiFilePath,"ui_*.py"))
filesChanged = 0
for file in os.listdir(uiFilePath):
if file[0:3] == 'ui_':
if remove_false_import_statement(uiFilePath+'/'+file,stat):
filesChanged+=1
print(f"[ DONE ] "+f"{uiFilePath}/{file:<25}")
def remove_false_import_statement(file,statement):
with open(file,'r') as pIn:
buf = pIn.read()
res = buf.replace(statement,'#'+statement)
with open(file,'w') as pOut:
pOut.write(res)
return not buf==res
def force_rebuild():
print_info(f"FORCE_REBUILD: {FORCE_REBUILD}")
build_target_folder(UIPY_TARGET_FOLDER)
build_resources(QRC_SOURCE_FOLDER,QRC_PY_TARGET_FOLDER,QRC_FILENAME)
build_ui_files(UI_SOURCE_FOLDER,UIPY_TARGET_FOLDER)
clean_ui_files(UIPY_TARGET_FOLDER)
if __name__ == '__main__':
if FORCE_REBUILD:
force_rebuild()