mirror of
https://github.com/envmodules/modules.git
synced 2026-06-03 00:33:18 +08:00
Rename 'perl' in 'perl.pm' and 'python' into 'python.py' to get same init script filename than C-version.
25 lines
956 B
Python
25 lines
956 B
Python
import os, re, subprocess
|
|
|
|
def module(command, *arguments):
|
|
exec(subprocess.Popen(['@TCLSH@', '@libexecdir@/modulecmd.tcl', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
|
|
|
|
os.environ['MODULESHOME'] = '@prefix@'
|
|
|
|
if not 'MODULEPATH' in os.environ:
|
|
if os.access('@initdir@/.modulespath', os.R_OK):
|
|
pathlist = []
|
|
for fline in open('@initdir@/.modulespath', 'r').read().splitlines():
|
|
patharg = re.match('^\s*(.*?)[\s#].*$', fline)
|
|
if patharg and patharg.group(1):
|
|
pathlist.append(patharg.group(1))
|
|
os.environ['MODULEPATH'] = ':'.join(pathlist)
|
|
else:
|
|
os.environ['MODULEPATH'] = ''
|
|
|
|
if not 'LOADEDMODULES' in os.environ:
|
|
os.environ['LOADEDMODULES'] = ''
|
|
|
|
# load modulerc only if module environment is empty
|
|
if os.access('@initdir@/modulerc', os.R_OK) and not os.environ['MODULEPATH'] and not os.environ['LOADEDMODULES']:
|
|
module('source', '@initdir@/modulerc')
|