11 from __future__
import print_function
12 from future
import standard_library
13 standard_library.install_aliases()
17 from io
import StringIO
18 from BaseMTTUtility
import *
27 BaseMTTUtility.__init__(self)
37 lines = testDef.printOptions(self.
options)
44 if options[
'env_module_wrapper']
is not None:
47 if options[
'verbose']
or options[
'debug'] :
52 mod_pkg = os.environ[
'MODULESHOME']
53 if os.path.isfile(os.path.join(mod_pkg,
"init/env_modules_python.py")) :
55 elif os.path.isfile(os.path.join(mod_pkg,
"init/python.py")) :
58 if options[
'verbose']
or options[
'debug'] :
59 print(
"The --env-module-wrapper switch was not used and module python support via os.environ['MODULESHOME']/init/env_modules_python.py was not found")
62 if options[
'verbose']
or options[
'debug'] :
63 print(
"The --env-module-wrapper switch was not used and module python support via os.environ['MODULESHOME'] was not found")
67 self.
env_module_link = os.path.join(options[
'scratchdir'],
"env_modules_python.py")
74 print(
"Since we are unable to meet this basic user directive,")
75 print(
"we will now abort")
83 return (1,
None,
"Module capability was not found")
88 from env_modules_python
import module
90 return (1,
None,
"No module named env_modules_python found")
94 saved_stdout = sys.stdout
95 saved_stderr = sys.stderr
96 load_stdout = sys.stdout = StringIO()
97 load_stderr = sys.stderr = StringIO()
99 modules = modules.split()
106 return (1,
None,
"Attempt to load environment module " + mod +
" failed")
109 sys.stdout = saved_stdout
110 sys.stderr = saved_stderr
112 status = load_stderr.seek(0, os.SEEK_END)
113 stdout = load_stdout.getvalue()
114 stderr = load_stderr.getvalue()
117 return (status, stdout, stderr)
122 return (1,
None,
"Module capability was not found")
127 from env_modules_python
import module
129 return (1,
None,
"No module named env_modules_python found")
133 saved_stdout = sys.stdout
134 saved_stderr = sys.stderr
135 unload_stdout = sys.stdout = StringIO()
136 unload_stderr = sys.stderr = StringIO()
138 modules = modules.split()
146 return (1,
None,
"Attempt to unload environment module " + mod +
" failed")
149 sys.stdout = saved_stdout
150 sys.stderr = saved_stderr
152 status = unload_stderr.seek(0, os.SEEK_END)
153 stdout = unload_stdout.getvalue()
154 stderr = unload_stderr.getvalue()
155 unload_stdout.close()
156 unload_stderr.close()
157 return (status, stdout, stderr)