Newer
Older
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
##
# Copyright 2013-2022 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for building and installing IMOD, implemented as an easyblock
@author: Benjamin Roberts (Landcare Research NZ Ltd)
"""
import os
import shutil
from easybuild.easyblocks.generic.binary import Binary
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import remove_dir
from easybuild.tools.run import run_cmd
class EB_IMOD(Binary):
"""Support for building/installing IMOD."""
def install_step(self):
"""Install IMOD using install script."""
# -dir: Choose location of installation directory
# -skip: do not attempt to deploy resource files in /etc
# -yes: do not prompt for confirmation
script = '{0}_{1}{2}.sh'.format(self.name.lower(), self.version, self.cfg['versionsuffix'])
cmd = "bash {0} -dir {1} -script {1} -skip -yes".format(script, self.installdir)
run_cmd(cmd, log_all=True, simple=True)
# The assumption by the install script is that installdir will be something
# like /usr/local. So it creates, within the specified install location, a
# number of additional directories within which to install IMOD. We will,
# therefore, move the contents of these directories up and throw away the
# directories themselves. Doing so apparently is not a problem so long as
# IMOD_DIR is correctly set in the module.
link_to_remove = os.path.join(self.installdir, self.name)
dir_to_remove = os.path.join(self.installdir, "{0}_{1}".format(self.name.lower(), self.version))
try:
for entry in os.listdir(dir_to_remove):
shutil.move(os.path.join(dir_to_remove, entry), self.installdir)
if os.path.realpath(link_to_remove) != os.path.realpath(dir_to_remove):
raise EasyBuildError("Something went wrong: %s doesn't point to %s", link_to_remove, dir_to_remove)
remove_dir(dir_to_remove)
os.remove(link_to_remove)
except OSError as err:
raise EasyBuildError("Failed to clean up install dir: %s", err)
def sanity_check_step(self):
"""Custom sanity check for IMOD."""
custom_paths = {
'files': ['bin/imod', 'IMOD-linux.sh', 'IMOD-linux.sh', 'installIMOD'],
'dirs': ['lib'],
}
super(EB_IMOD, self).sanity_check_step(custom_paths=custom_paths)
def make_module_extra(self):
"""Define IMOD specific variables in generated module file."""
txt = super(EB_IMOD, self).make_module_extra()
txt += self.module_generator.set_environment('IMOD_DIR', self.installdir)
txt += self.module_generator.set_environment('IMOD_PLUGIN_DIR',
os.path.join(self.installdir, 'lib', 'imodplug'))
txt += self.module_generator.set_environment('IMOD_QTLIBDIR', os.path.join(self.installdir, 'qtlib'))
if os.getenv('JAVA_HOME') is None:
raise EasyBuildError("$JAVA_HOME is not defined for some reason -- check environment")
else:
txt += self.module_generator.set_environment('IMOD_JAVADIR', os.getenv('JAVA_HOME'))
txt += self.module_generator.set_environment('FOR_DISABLE_STACK_TRACE', '1')
txt += self.module_generator.set_alias('subm', "submfg $* &")
txt += self.module_generator.msg_on_load("Please set the environment variable $IMOD_CALIB_DIR if appropriate.\n")
txt += self.module_generator.msg_on_load("bash users run: 'source $EBROOTIMOD/IMOD-linux.sh\n")
txt += self.module_generator.msg_on_load("csh users run: 'source $EBROOTIMOD/IMOD-linux.csh'\n")
return txt