Created
August 20, 2015 08:54
-
-
Save ZedThree/4f6ab6037e9dacf26d44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def moduleinit(): | |
"""Make sure various environment variables are set correctly | |
""" | |
if 'MODULE_VERSION' not in os.environ: | |
os.environ['MODULE_VERSION_STACK'] = '3.2.10' | |
os.environ['MODULE_VERSION'] = '3.2.10' | |
else: | |
os.environ['MODULE_VERSION_STACK'] = os.environ['MODULE_VERSION'] | |
os.environ['MODULESHOME'] = '/usr/share/Modules/3.2.10' | |
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): | |
"""Pass arguments as separate items in list""" | |
if type(args[0]) == type([]): | |
args = args[0] | |
else: | |
args = list(args) | |
(output, error) = subprocess.Popen(['/usr/share/Modules/{0:s}/bin/modulecmd'.format(os.environ['MODULE_VERSION']), 'python'] + | |
args, stdout=subprocess.PIPE).communicate() | |
exec(output) | |
# Use like: | |
moduleinit() | |
module(["load","foo"]) # equivalent to 'module load foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment