forked from nds-org/jupyter-et
-
Notifications
You must be signed in to change notification settings - Fork 0
/
et-pkg-installer.py
336 lines (311 loc) · 9.25 KB
/
et-pkg-installer.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env python
import os
import re
import sys
def get_pkg_cmd():
for p in os.environ["PATH"].split(os.pathsep):
for cmd in ["apt-get","dnf","yum","zypper"]:
f = p+os.sep+cmd
if os.path.exists(f):
return cmd
pkg_cmd = get_pkg_cmd()
if pkg_cmd == None:
raise Exception("Could not idenfity operating system")
# the next couple of dicts describe the required packages to compile the ET.
# Each entry uses a human-readable key for the softwre and then either a single
# string for the required packages or a list of strings or lists of acceptable
# sets of alternative packages.
# For example:
# "hdf5":"libhdf5-dev" means that the capability "hdf5" is provided by the
# package "libhdf5-dev".
# "mpi":[ "openmpi-devel", "mpich-devel", "mpich2-devel"] means that any of the
# packages "openmpi-devel", "mpich-devel" or "mpich2-devel" can be used to
# satisfy the "mpi" requirement.
# Finally:
# "mpi":[
# ["libopenmpi-dev","libhdf5-openmpi-dev"],
# ["libmpich-dev","libhdf5-mpich-dev"],
# ["libmpich2-dev","libhdf5-mpich2-dev"]],
# states that any of the mpi+hdf5 pairs are acceptable to satisfy the MPI
# requirement. libhdf5 devel files appear b/c HDF5 optionally depends on MPI
# and can use the MPI version.
debk = {
"perl":"perl",
"gfortran":"gfortran",
"gcc":"gcc",
"g++":"g++",
"papi":"libpapi-dev",
"gsl":"libgsl-dev",
"lapack":"liblapack-dev",
"hdf5":"libhdf5-dev",
"mpi":[
["libopenmpi-dev","libhdf5-openmpi-dev"],
["libmpich-dev","libhdf5-mpich-dev"],
["libmpich2-dev","libhdf5-mpich2-dev"]],
"pkg-config":"pkg-config",
"subversion":"subversion",
"git":"git",
"python":"python",
"patch":"patch",
"make":"make",
"numa":"numactl",
"hwloc":[["libhwloc-dev","hwloc"]],
"ssl":"libssl-dev",
"fftw":"libfftw3-dev",
"curl":"curl",
"which":None,
"rsync":"rsync",
"tar":None,
"hostname":None,
"xargs":None,
"jpeg":"libjpeg-turbo?-dev",
"libtool":None,
"libudev":"libudev-dev",
}
redk = {
"perl":"perl",
"gfortran":"gcc-gfortran",
"gcc":"gcc",
"g++":"gcc-c++",
"papi":"papi-devel",
"gsl":"gsl-devel",
"lapack":"lapack-devel",
"hdf5":"hdf5-devel",
"mpi":[
["openmpi-devel","hdf5-openmpi-devel"],
["mpich-devel","hdf5-mpich-devel"],
["mpich2-devel","hdf5-mpich2-devel"]],
"pkg-config":"pkgconfig",
"subversion":"subversion",
"git":"git",
"python":"python",
"patch":"patch",
"make":"make",
"numa":"numactl-devel",
"hwloc":"hwloc-devel",
"ssl":"openssl-devel",
"fftw":"fftw-devel",
"curl":"curl",
"which":"which", # Used by simfactory
"rsync":"rsync",
"tar":None,
"hostname":"hostname",
"xargs":"findutils",
"jpeg":"libjpeg-turbo-devel",
"libtool":"libtool-ltdl-devel", # Needed to link on this platform
"libudev":None,
}
susek = {
"perl":"perl",
"gfortran":"gcc-fortran",
"gcc":"gcc",
"g++":"gcc-c++",
"papi":"papi-devel",
"gsl":"gsl-devel",
"lapack":"lapack-devel",
"hdf5":"hdf5-devel",
"mpi":[
"openmpi-devel",
"mpich-devel",
"mpich2-devel"],
"subversion":"subversion",
"pkg-config":"pkg-config",
"git":"git",
"python":"python",
"patch":"patch",
"make":"make",
"numa":"libnuma-devel",
"hwloc":"hwloc-devel",
"ssl":"libopenssl-devel",
"fftw":"fftw3-devel",
"curl":"curl",
"which":"which",
"hostname":"hostname",
"rsync":"rsync",
"tar":"tar",
"xargs":None,
"jpeg":"libjpeg8-devel",
"libtool":None,
"libudev":None,
}
cmds = {
"perl":"perl",
"gfortran":"gfortran",
"gcc":"gcc",
"g++":"g++",
"papi":None,
"gsl":None,
"lapack":None,
"hdf5":None,
"mpi":None,
"pkg-config":"pkg-config",
"subversion":"svn",
"git":"git",
"python":"python",
"patch":"patch",
"make":"make",
"numa":None,
"hwloc":None,
"ssl":None,
"fftw":None,
"curl":"curl",
"which":"which",
"rsync":"rsync",
"tar":"tar",
"hostname":"hostname",
"xargs":"xargs",
"jpeg":None,
"libtool":None,
"libudev":None,
}
# Check that both tables have the same keys
def check(h1,h2):
for k in h1:
assert k in h2, k
for k in h2:
assert k in h1, k
check(debk,redk)
check(redk,susek)
check(redk,cmds)
install_cache = {}
# The kcmd or "key command" parameter is the
# name of the package installed. Frequently,
# this is the same as a linux shell command.
# When that is the case, one can search the
# path for the command in question rather tha
# querying a package manager.
def installed1(kcmd,cmd):
global install_cache
if type(cmd) == list:
install_count = 0
missing = []
for c in cmd:
res = installed1(kcmd,c);
install_count += res["installed"]
missing += res["missing"]
return {"installed":install_count,"missing":missing}
if cmds[kcmd] is not None:
for path in os.environ["PATH"].split(":"):
path = re.sub(r'/+$','',path)
if os.path.exists(path+'/'+cmds[kcmd]):
return {"installed":1,"missing":[]}
return {"installed":0,"missing":[cmd]}
if pkg_cmd == "apt-get":
if cmd in install_cache:
return install_cache[cmd]
ex = (os.system("dpkg -s "+cmd) == 0)
install_cache[cmd] = ex
if ex:
return {"installed":1,"missing":[]}
if pkg_cmd == "yum" or pkg_cmd == "dnf" or pkg_cmd == "zypper":
if install_cache == {}:
install_cache = {}
for pkg in os.popen("rpm -qa"):
one_pkg = re.sub("-[^-]+-[^-]+$","",pkg)
install_cache[one_pkg]=1
if cmd in install_cache:
return {"installed":1,"missing":[]}
return {"installed":0,"missing":[cmd]}
def installed(kcmd,cmd):
if type(cmd) == str:
return installed1(kcmd,cmd)
elif type(cmd) == list:
answer = None
for c in cmd:
res = installed1(kcmd,c)
nin = len(res["missing"])
ins = res["installed"]
if nin==0:
return res
elif answer == None:
answer = res
elif ins > answer["installed"]:
answer = res
elif ins == answer["installed"] and nin < len(answer["missing"]):
answer = res
return answer
return {"installed":0,"missing":[]}
pkgs = None
if pkg_cmd == "apt-get":
pkgs = debk
elif pkg_cmd == "dnf" or pkg_cmd == "yum":
pkgs = redk
elif pkg_cmd == "zypper":
pkgs = susek
else:
raise Exception("No package manager")
if pkgs == None:
raise Exception("Could not determine what packages to install")
def install():
answer={"installed":0,"missing":[]}
fd = open("install-for-cactus.sh","w")
for k in pkgs:
p = pkgs[k]
res = installed(k,p)
answer["installed"] += res["installed"]
answer["missing"] += res["missing"]
if len(answer["missing"]) == 0:
fd.write("# All packages are installed\n")
else:
# Special thing for Centos
if os.path.exists("/etc/centos-release"):
epel = installed("epel-release", None)
if len(epel["missing"]) > 0:
fd.write(pkg_cmd+" install -y epel-release\n")
first = True
for c in answer["missing"]:
if type(c) == str:
if type(c) == str:
if first:
first = False
fd.write(pkg_cmd)
fd.write(" install -y")
fd.write(' ')
fd.write(c)
elif type(c) == list:
for cc in c:
if first:
first = False
fd.write(pkg_cmd)
fd.write(" install -y")
fd.write(' ')
fd.write(cc)
else:
raise Exception()
fd.write("\n")
fd.close()
sys.stdout.write("Install file 'install-for-cactus.sh' has been written\n")
def gets(c,k):
pre = c+" install -y "
if type(k) == str:
return pre+k
elif type(k) == list:
if type(k[0]) == list:
return " ".join(k[0])
elif type(k[0]) == str:
return pre+k[0]
else:
raise Exception()
elif type(k) == type(None):
return " "
else:
raise Exception(str(type(k)))
if __name__ == "__main__":
if len(sys.argv)>1 and sys.argv[1] == "--table":
fd = open("install-for-cactus.html","w")
fd.write("<table>\n");
fd.write("<tr><th>Package</th><th>Debian/Mint/Ubuntu</th>"+
"<th>fedora</th><th>centos</th><th>opensuse</th></tr>\n")
for k in debk:
fd.write('<tr>')
fd.write("<td>"+k+"</td>")
fd.write("<td>"+gets("apt-get",debk[k])+"</td>")
fd.write("<td>"+gets("dnf",redk[k])+"</td>")
fd.write("<td>"+gets("yum",redk[k])+"</td>")
fd.write("<td>"+gets("zypper",susek[k])+"</td>")
fd.write("</tr>\n")
fd.write("</table>\n")
fd.close()
sys.stdout.write("Install file 'install-for-cactus.html' has been written\n")
else:
install()