forked from yunshengtian/AutoOED
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.py
More file actions
146 lines (119 loc) · 4.37 KB
/
bundle.py
File metadata and controls
146 lines (119 loc) · 4.37 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
import os, platform, shutil
from multiprocessing import Process, freeze_support
from argparse import ArgumentParser
def main():
'''
Parse bundle type from command input
'''
parser = ArgumentParser()
parser.add_argument(
'--type',
type=str,
choices=['all', 'personal', 'team', 'team_manager', 'team_scientist', 'team_technician'],
default='all',
)
parser.add_argument(
'--zip',
default=False,
action='store_true',
)
parser.add_argument(
'--serial',
default=False,
action='store_true',
)
args = parser.parse_args()
'''
Software names and scripts for different bundle types
'''
names = {
'personal': 'AutoOED',
'team_manager': 'AutoOED_Manager',
'team_scientist': 'AutoOED_Scientist',
'team_technician': 'AutoOED_Technician',
}
names['team'] = [names['team_manager'], names['team_scientist'], names['team_technician']]
names['all'] = [names['personal']] + names['team']
scripts = {
'personal': 'run_personal.py',
'team_manager': 'run_team_manager.py',
'team_scientist': 'run_team_scientist.py',
'team_technician': 'run_team_technician.py',
}
scripts['team'] = [scripts['team_manager'], scripts['team_scientist'], scripts['team_technician']]
scripts['all'] = [scripts['personal']] + scripts['team']
name, script = names[args.type], scripts[args.type]
'''
Bundle directories
'''
base_dir = './bundle'
build_dir = os.path.join(base_dir, 'build')
dist_dir = os.path.join(base_dir, 'dist')
spec_dir = os.path.join(base_dir, 'spec')
for work_dir in [base_dir, build_dir, dist_dir, spec_dir]:
os.makedirs(work_dir, exist_ok=True)
for work_dir in [build_dir, dist_dir]:
if type(name) == list:
for curr_name in name:
curr_work_dir = os.path.join(work_dir, curr_name)
if os.path.exists(curr_work_dir):
shutil.rmtree(curr_work_dir)
os.makedirs(curr_work_dir)
else:
curr_work_dir = os.path.join(work_dir, name)
if os.path.exists(curr_work_dir):
shutil.rmtree(curr_work_dir)
os.makedirs(curr_work_dir)
'''
Bundle commands
'''
sep = os.pathsep
base_cmd = f'''
pyinstaller --windowed --onedir \
--add-data "../../problem/custom{sep}problem/custom" \
--add-data "../../problem/data{sep}problem/data" \
--add-data "../../problem/predefined{sep}problem/predefined" \
--add-data "../../examples{sep}examples" \
--add-data "../../system/static{sep}system/static" \
--hidden-import "PIL._tkinter_finder" \
--hidden-import "pymoo.cython.non_dominated_sorting" \
--hidden-import "sklearn.neighbors._typedefs" \
--hidden-import "sklearn.neighbors._quad_tree" \
--hidden-import "sklearn.tree._utils" \
--hidden-import "sklearn.utils._cython_blas" \
--workpath {build_dir} \
--distpath {dist_dir} \
--specpath {spec_dir} \
'''
if type(name) == list:
all_cmds = [base_cmd + f'-y -n {curr_name} {curr_script}' for curr_name, curr_script in zip(name, script)]
else:
all_cmds = [base_cmd + f'-y -n {name} {script}']
'''
Bundle operations
'''
if args.serial:
for cmd in all_cmds:
os.system(cmd)
else:
processes = []
for cmd in all_cmds:
processes.append(Process(target=os.system, args=(cmd,)))
[p.start() for p in processes]
[p.join() for p in processes]
system = platform.system()
if args.zip:
if type(name) == list:
for curr_name in name:
if system == 'Darwin':
os.system(f"cd {dist_dir} && zip -r {os.path.join('..', curr_name)}.zip ./{curr_name}.app")
else:
shutil.make_archive(os.path.join(base_dir, curr_name), 'zip', root_dir=dist_dir, base_dir=curr_name)
else:
if system == 'Darwin':
os.system(f"cd {dist_dir} && zip -r {os.path.join('..', name)}.zip ./{name}.app")
else:
shutil.make_archive(os.path.join(base_dir, name), 'zip', root_dir=dist_dir, base_dir=name)
if __name__ == '__main__':
freeze_support()
main()