Files
modules/init/python.in
Xavier Delaruelle 3a1847d0a4 init: set MODULEPATH if not defined
Initialize MODULEPATH variable if not defined, with an empty string or
with the content of the init/.modulespath file if it exists and it is
readable. This file contains a list of module paths, one per line or
many per line separated by colon character.

This way of initializing MODULEPATH has been retrieved from C version
init scripts in order for sysadmins to keep a familiar concept to set
default MODULEPATH.
2017-03-06 05:32:01 +01:00

24 lines
877 B
Plaintext

import os, re, subprocess
def module(command, *arguments):
exec(subprocess.Popen(['@TCLSH@', '@MODULESHOME@/modulecmd.tcl', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])
os.environ['MODULESHOME'] = '@MODULESHOME@'
if not 'MODULEPATH' in os.environ:
if os.access('@MODULESHOME@/init/.modulespath', os.R_OK):
pathlist = []
for fline in open('@MODULESHOME@/init/.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'] = ''
if os.access('@MODULESHOME@/init/modulerc', os.R_OK):
module('source', '@MODULESHOME@/init/modulerc')