forked from EESSI/software-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_lmodrc.py
executable file
·47 lines (36 loc) · 964 Bytes
/
create_lmodrc.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
#!/usr/bin/env python3
#
# Create lmodrc.lua configuration file for Lmod.
#
import os
import sys
DOT_LMOD = '.lmod'
TEMPLATE_LMOD_RC = """propT = {
}
scDescriptT = {
{
["dir"] = "%(prefix)s/%(dot_lmod)s/cache",
["timestamp"] = "%(prefix)s/%(dot_lmod)s/cache/timestamp",
},
}
"""
def error(msg):
sys.stderr.write("ERROR: %s\n" % msg)
sys.exit(1)
if len(sys.argv) != 2:
error("Usage: %s <software prefix>" % sys.argv[0])
prefix = sys.argv[1]
if not os.path.exists(prefix):
error("Prefix directory %s does not exist!" % prefix)
lmodrc_path = os.path.join(prefix, DOT_LMOD, 'lmodrc.lua')
lmodrc_txt = TEMPLATE_LMOD_RC % {
'dot_lmod': DOT_LMOD,
'prefix': prefix,
}
try:
os.makedirs(os.path.dirname(lmodrc_path), exist_ok=True)
with open(lmodrc_path, 'w') as fp:
fp.write(lmodrc_txt)
except (IOError, OSError) as err:
error("Failed to create %s: %s" % (lmodrc_path, err))
print(lmodrc_path)