Files
modules/init/python.in
Xavier Delaruelle c64d18efcf Fix Python autoinit, error and x-resource rendering
Python code used to define the module command (autoinit action) was
broken (syntax errors) and not Python3-compatible. Error rendering is
also fixed here for Python3 compliance. Code used to process x-resource
is adapted to comply with Python recommendation [1] (subprocess.Popen
should be used instead of os.popen).

Python init script is also modified by this commit to use same code as
the one generated by autoinit action with call to subprocess.Popen
rather than os.popen.

[1] https://docs.python.org/2/library/os.html#os.popen
2016-08-13 05:21:15 -05:00

24 lines
677 B
Plaintext

import os, subprocess
os.environ['MODULESHOME'] = '$MODULESHOME'
if 'TCLSH' in os.environ:
TCLSH=os.environ['TCLSH']
else:
if os.path.exists('/usr/bin/tclsh'):
TCLSH="/usr/bin/tclsh"
else:
if os.path.exists('/bin/tclsh') :
TCLSH="/bin/tclsh"
else:
TCLSH=""
if not 'MODULEPATH' in os.environ:
os.environ['MODULEPATH'] = '/mips/tools/freeware/modulefiles'
if not 'LOADEDMODULES' in os.environ:
os.environ['LOADEDMODULES'] = '';
def module(command, *arguments):
exec(subprocess.Popen(['$TCLSH', '$MODULESHOME/modulecmd.tcl', 'python', command] + list(arguments), stdout=subprocess.PIPE).communicate()[0])