modulecmd: derive prefix from directory of init scripts

This commit is contained in:
2025-01-09 09:49:15 +01:00
parent 7047c82e75
commit 756c00b921
4 changed files with 47 additions and 53 deletions
+10 -7
View File
@@ -1,13 +1,16 @@
import os, re, subprocess
#
# :FIXME:
# - add error handling
# - needs testing!
#
import subprocess, pathlib
def module(*args):
os.environ['PMODULES_MODULEFILES_DIR']='modulefiles'
pm_home=os.environ['PMODULES_HOME']
os.environ['PMODULES_DIR']=pm_home
modulecmd=os.path.join(pm_home, 'bin', 'modulecmd')
dir=pathlib.Path(__file__).parent
modulecmd=pathlib.PurePath.joinpath(dir, '..', 'bin', 'modulecmd').resolve()
if type(args[0]) == type([]):
args = args[0]
cmd = [modulecmd, 'python'] + args[0]
else:
cmd = [modulecmd, 'python'] + list(args)
(output, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
(output, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
exec(output)