mirror of
https://github.com/envmodules/modules.git
synced 2026-06-03 00:33:18 +08:00
Make compatibility module function to always return a value to be able to check function result either new main version or compat version is called. Adapt cmake, perl, python and ruby compat module function to return a true value. Always true is returned as compat version does not handle returning error exit code.
35 lines
1.7 KiB
Python
35 lines
1.7 KiB
Python
import os, re, subprocess
|
|
|
|
# define modules runtine quarantine configuration
|
|
@setquarvars@os.environ['MODULES_RUN_QUARANTINE'] = '@RUN_QUARANTINE@'
|
|
@setquarvars@@os.environ['RUNENV_VAR'] = 'RUNENV_VAL'@
|
|
@notsetquarvars@#os.environ['MODULES_RUN_QUARANTINE'] = 'ENVVARNAME'
|
|
@notsetquarvars@
|
|
# setup quarantine if defined
|
|
_mlre = os.environ.copy()
|
|
if 'MODULES_RUN_QUARANTINE' in os.environ:
|
|
for _mlv in os.environ['MODULES_RUN_QUARANTINE'].split():
|
|
if re.match('^[A-Za-z_][A-Za-z0-9_]*$', _mlv):
|
|
if _mlv in os.environ:
|
|
_mlre[_mlv + '_modquar'] = os.environ[_mlv]
|
|
_mlrv = 'MODULES_RUNENV_' + _mlv
|
|
if _mlrv in os.environ:
|
|
_mlre[_mlv] = os.environ[_mlrv]
|
|
else:
|
|
_mlre[_mlv] = ''
|
|
|
|
# define module command and surrounding initial environment (default value
|
|
# for MODULESHOME, MODULEPATH, LOADEDMODULES and parse of init/.modulespath)
|
|
exec(subprocess.Popen(['@TCLSH@', '@libexecdir@/modulecmd.tcl', 'python', 'autoinit'], stdout=subprocess.PIPE, env=_mlre).communicate()[0])
|
|
|
|
# clean temp variable used to setup quarantine
|
|
del _mlre
|
|
@compatversion@
|
|
@compatversion@# redefine module command if compat version has been activated
|
|
@compatversion@if 'MODULES_USE_COMPAT_VERSION' in os.environ and os.environ['MODULES_USE_COMPAT_VERSION'] == '1':
|
|
@compatversion@ # set module command in accordance with active version
|
|
@compatversion@ def module(command, *arguments):
|
|
@compatversion@ exec(subprocess.Popen(['@libexecdir@/modulecmd-compat', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
|
|
@compatversion@ # return value as done on new main version
|
|
@compatversion@ return True
|