-
Notifications
You must be signed in to change notification settings - Fork 36
/
install.py
executable file
·241 lines (168 loc) · 6.69 KB
/
install.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import os
import sys
import stat
import subprocess
os.environ['PYTHONUNBUFFERED'] = '1'
CWD = os.getcwd()
sys.path.append(str(CWD) + '/common')
import common
def gen_wrapper_script(wrapper_script):
"""
Generate wrapper script (shell) for python script.
"""
print('>>> Generate wrapper script "' + str(wrapper_script) + '" ...')
try:
python_path = os.path.dirname(os.path.abspath(sys.executable))
python_script = str(wrapper_script) + '.py'
ld_library_path_setting = ''
if 'LD_LIBRARY_PATH' in os.environ:
ld_library_path_setting = 'export LD_LIBRARY_PATH=' + str(os.environ['LD_LIBRARY_PATH'])
with open(wrapper_script, 'w') as TS:
TS.write("""#!/bin/bash
# Set python3 path.
export PATH=""" + str(python_path) + """:$PATH
# Set install path.
export IFP_INSTALL_PATH=""" + str(CWD) + """
# Set LD_LIBRARY_PATH.
""" + str(ld_library_path_setting) + """
# Execute ifp.py.
python3 $IFP_INSTALL_PATH/""" + str(python_script) + """ $@
""")
os.chmod(wrapper_script, stat.S_IRWXU+stat.S_IRWXG+stat.S_IRWXO)
except Exception as err:
print('*Error*: Failed on generating top script "' + str(wrapper_script) + '": ' + str(err))
sys.exit(1)
def gen_wrapper_scripts():
script_list = ['bin/ifp',
'action/check/scripts/gen_checklist_scripts',
'action/check/scripts/gen_checklist_summary',
'action/check/scripts/ic_check',
'action/check/scripts/view_checklist_report']
for wrapper_script in script_list:
gen_wrapper_script(wrapper_script)
def gen_config_file():
"""
Generate config file <IFP_INSTALL_PATH>/conf/config.py.
"""
config_file = str(CWD) + '/config/config.py'
print('')
print('>>> Generate config file "' + str(config_file) + '".')
if os.path.exists(config_file):
print('*Warning*: config file "' + str(config_file) + '" already exists, will not update it.')
else:
try:
with open(config_file, 'w') as CF:
CF.writelines('## admin settings: Only administrator can modify below settings\n')
for key, dic in common.config.admin_setting_dic.items():
value = dic['value']
note = dic['note']
CF.writelines('# ' + str(note) + '\n')
if isinstance(value, str):
value = '\"' + value + '\"'
CF.writelines(str(key) + ' = ' + str(value) + '\n\n')
CF.writelines('## IFP Config settings: Users can define personal settings in ~/.ifp/config/config.py, Below are default value.\n')
for key, dic in common.config.user_setting_dic.items():
value = dic['value']
note = dic['note']
CF.writelines('# ' + str(note) + '\n')
if isinstance(value, str):
value = '\"' + value + '\"'
CF.writelines(str(key) + ' = ' + str(value) + '\n\n')
os.chmod(config_file, stat.S_IRWXU+stat.S_IRWXG+stat.S_IRWXO)
except Exception as error:
print('*Error*: Failed on opening config file "' + str(config_file) + '" for write: ' + str(error))
sys.exit(1)
def gen_top_sh_env():
"""
Generate top environment file <IFP_INSTALL_PATH>/config/env.sh.
"""
top_env_file = str(CWD) + '/config/env.sh'
print('>>> Generate top sh environment file "' + str(top_env_file) + '" ...')
try:
with open(top_env_file, 'w') as TCF:
TCF.write("""
#### Default EDA tool settings ####
# Set default TESSENT setting.
# Set default DC setting.
# Set default GENUS setting.
# Set default FORMALITY setting.
# Set default LEC setting.
# Set default PT setting.
# Set default TEMPUS setting.
# Set default ICC2 setting.
# Set default INNOVUS setting.
###################################
# Set lsfMonitor path.
export PATH=""" + str(CWD) + """/tools/lsfMonitor/monitor/bin:$PATH
# Set default soffice path.
""")
except Exception as err:
print('*Error*: Failed on generating top environment file "' + str(top_env_file) + '": ' + str(err))
sys.exit(1)
def gen_top_csh_env():
"""
Generate top csh environment file <IFP_INSTALL_PATH>/config/env.csh.
"""
top_env_file = str(CWD) + '/config/env.csh'
print('>>> Generate top csh environment file "' + str(top_env_file) + '" ...')
try:
with open(top_env_file, 'w') as TCF:
TCF.write("""
#### Default EDA tool settings ####
# Set default TESSENT setting.
# Set default DC setting.
# Set default GENUS setting.
# Set default FORMALITY setting.
# Set default LEC setting.
# Set default PT setting.
# Set default TEMPUS setting.
# Set default ICC2 setting.
# Set default INNOVUS setting.
###################################
# Set lsfMonitor path.
setenv PATH """ + str(CWD) + """/tools/lsfMonitor/monitor/bin:$PATH
# Set default soffice path.
""")
except Exception as err:
print('*Error*: Failed on generating top envionment file "' + str(top_env_file) + '": ' + str(err))
sys.exit(1)
def update_tools():
"""
Update string "EXPECTED_PYTHON" and "IFP_INSTALL_PATH" on specified tools.
"""
print('>>> Update EXPECTED_PYTHON/IFP_INSTALL_PATH settings for specified tools ...')
expectedPython = os.path.abspath(sys.executable)
toolList = [str(CWD) + '/action/check/scripts/gen_checklist_scripts.py',
str(CWD) + '/action/check/scripts/gen_checklist_summary.py',
str(CWD) + '/action/check/scripts/ic_check.py',
str(CWD) + '/action/check/scripts/view_checklist_report.py']
for tool in toolList:
with open(tool, 'r+') as TOOL:
lines = TOOL.read()
TOOL.seek(0)
lines = lines.replace('<EXPECTED_PYTHON>', expectedPython)
lines = lines.replace('<IFP_INSTALL_PATH>', CWD)
TOOL.write(lines)
def install_tools():
print('>>> Install tool "lsfMonitor" ...')
command = 'cd tools/lsfMonitor; ' + str(sys.executable) + ' install.py'
SP = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = SP.communicate()
return_code = SP.returncode
if return_code != 0:
print('*Error*: Failed on installing tool "lsfMonitor": ' + str(stdout, 'utf-8'))
sys.exit(1)
################
# Main Process #
################
def main():
gen_wrapper_scripts()
gen_config_file()
gen_top_sh_env()
gen_top_csh_env()
update_tools()
install_tools()
print('')
print('Install successfully!')
if __name__ == '__main__':
main()