-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.py
36 lines (29 loc) · 946 Bytes
/
module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""This file is supposed to be source (`%run -i module.py` in IPython) in order
to make modules (http://modules.sourceforge.net) available viad the `module`
function.
This may then be used as e.g.
>>> module('load', 'intel/xe2011')
>>> module('list')
"""
import os
import re
import subprocess
if 'MODULEPATH' not in os.environ:
f = open(os.environ['MODULESHOME'] + "/init/.modulespath", "r")
path = []
for line in f.readlines():
line = re.sub("#.*$", '', line)
if line is not '':
path.append(line)
os.environ['MODULEPATH'] = ':'.join(path)
if 'LOADEDMODULES' not in os.environ:
os.environ['LOADEDMODULES'] = ''
def module(*args):
if isinstance(args[0], list):
args = args[0]
else:
args = list(args)
(output, error) = subprocess.Popen(
['/usr/bin/modulecmd', 'python'] +
args, stdout=subprocess.PIPE).communicate()
exec(output)