| 1 |
from __future__ import print_function |
| 2 |
import os, sys, re, subprocess |
| 3 |
|
| 4 |
# define modules runtime quarantine configuration |
| 5 |
@[email protected]['MODULES_RUN_QUARANTINE'] = '@RUN_QUARANTINE@' |
| 6 |
@setquarvars@@os.environ['RUNENV_VAR'] = 'RUNENV_VAL'@ |
| 7 |
@notsetquarvars@#os.environ['MODULES_RUN_QUARANTINE'] = 'ENVVARNAME' |
| 8 |
@notsetquarvars@ |
| 9 |
# setup quarantine if defined |
| 10 |
_mlre = os.environ.copy() |
| 11 |
if 'MODULES_RUN_QUARANTINE' in os.environ: |
| 12 |
for _mlv in os.environ['MODULES_RUN_QUARANTINE'].split(): |
| 13 |
if re.match('^[A-Za-z_][A-Za-z0-9_]*$', _mlv): |
| 14 |
if _mlv in os.environ: |
| 15 |
_mlre['__MODULES_QUAR_' + _mlv] = os.environ[_mlv] |
| 16 |
_mlrv = 'MODULES_RUNENV_' + _mlv |
| 17 |
if _mlrv in os.environ: |
| 18 |
_mlre[_mlv] = os.environ[_mlrv] |
| 19 |
else: |
| 20 |
_mlre[_mlv] = '' |
| 21 |
_mlre['__MODULES_QUARANTINE_SET'] = '1' |
| 22 |
|
| 23 |
# define module command and surrounding initial environment (default value |
| 24 |
# for MODULESHOME, MODULEPATH, LOADEDMODULES and parse of init config files) |
| 25 |
out, err = subprocess.Popen(['@TCLSH@', '@libexecdir@/modulecmd.tcl', 'python', 'autoinit'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=_mlre).communicate() |
| 26 |
|
| 27 |
exec(out) |
| 28 |
if err.decode(): |
| 29 |
print(err.decode(), end='', file=sys.stderr) |
| 30 |
|
| 31 |
# clean temp variables |
| 32 |
del _mlre |
| 33 |
del out |
| 34 |
del err |