Skip to content

Commit

Permalink
Allow init/env_modules_python.py.in to take a string or an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McLay committed Aug 5, 2019
1 parent 5ffa747 commit 72221c0
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 56 deletions.
5 changes: 5 additions & 0 deletions README.new
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ Lmod 8.1+
(8.1.8) * Issue #401: Use LMOD_PKG to determine where the lmod/etc directory is.
(8.1.9) * Issue #401: Create and use LMOD_ROOT to be the parent lmod directory is located.
(8.1.10) * Add colorize() and color_banner() to sandbox for better message to users.
(8.1.11) * Allow init/env_modules_python.py.in to take a string or an array.
* Change the way that Lmod determines the command. Misspellings now fail.
* Add finalize hook to match startup hook.
* improved help message for disable

9 changes: 8 additions & 1 deletion init/env_modules_python.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import os, sys


def module(command, *arguments):
proc = Popen(['@PKG@/libexec/lmod', 'python', command] + list(arguments), stdout=PIPE, stderr=PIPE)
numArgs = len(arguments)
A = ['@PKG@/libexec/lmod', 'python', command]
if (numArgs == 1):
A += arguments[0].split()
else:
A += list(arguments)

proc = Popen(A, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
err_out=sys.stderr
if (os.environ.get('LMOD_REDIRECT','@redirect@') != 'no'):
Expand Down
4 changes: 3 additions & 1 deletion messageDir/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ Pour chercher le contenu des modules pour des mots clés, exécute z
]==],
m_Properties = " Propriétés:\n",
m_ProvidedBy = nil,
m_ProvidedFrom = nil,
m_ProvByModules = nil,
m_Regex_Spider = [==[%{border} Pour trouver d'autres correspondances à votre recherche, exécutez :
$ module -r spider '.*%{name}.*'
Expand Down Expand Up @@ -344,7 +346,7 @@ L'environnement par défaut ne contient aucun module
style_hlp = "Style contrôlé par le site pour \"avail\" : %{styleA} (défaut: %{default})",
rt_hlp = "Test de régression de Lmod",
dbg_hlp = "Trace du programme écrite vers stderr",
dbg_hlp2 = "Trace du programme écrite vers stderr, (ou dbglvl est 1, 2, 3, ...)",
dbg_hlp2 = "Trace du programme écrite vers stderr, ( dbglvl est 1, 2, 3, ...)",
pin_hlp = "Lors d'une restauration, utiliser la version spécifiée, et ignorer la version par défaut",
avail_hlp = "Affiche seulement les modules par défaut lorsque la commande avail est utilisée",
quiet_hlp = "N'affiche pas les avertissements",
Expand Down
2 changes: 1 addition & 1 deletion rt/i18n/err.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Options:
-s availStyle --style=availStyle Style contrôlé par le site pour "avail" : system (défaut: system)
--regression_testing Test de régression de Lmod
-D Trace du programme écrite vers stderr
--debug=dbglvl Trace du programme écrite vers stderr, (ou dbglvl est 1, 2, 3, ...)
--debug=dbglvl Trace du programme écrite vers stderr, ( dbglvl est 1, 2, 3, ...)
--pin_versions=pinVersions Lors d'une restauration, utiliser la version spécifiée, et ignorer la version par défaut
-d --default Affiche seulement les modules par défaut lorsque la commande avail est utilisée
-q --quiet N'affiche pas les avertissements
Expand Down
2 changes: 1 addition & 1 deletion rt/python/err.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ProjectDIR/rt/python/mf/Core
bad/1.0 foobar/1.0 (L)
A/1.0 (L) B/1.1 (L) bad/1.0 bar/2.0 (L) foobar/1.0 (L)
Where:
L: Module is loaded
Use "module spider" to find all possible modules.
Expand Down
1 change: 1 addition & 0 deletions rt/python/mf/Core/A/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setenv(myModuleName(), myModuleVersion())
1 change: 1 addition & 0 deletions rt/python/mf/Core/B/1.1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setenv(myModuleName(), myModuleVersion())
2 changes: 2 additions & 0 deletions rt/python/mf/Core/bar/2.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setenv("BAR","2.0")
setenv("N","^ucx.yalla")
2 changes: 1 addition & 1 deletion rt/python/out.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
os.environ['FOOBAR']: "1.0.1"
os.environ['M']: "^ucx.yalla"
ProjectDIR/rt/python/mf/Core
bad/1.0 foobar/1.0 (L)
A/1.0 (L) B/1.1 (L) bad/1.0 bar/2.0 (L) foobar/1.0 (L)
Where:
L: Module is loaded
Use "module spider" to find all possible modules.
Expand Down
3 changes: 2 additions & 1 deletion rt/python/python.tdesc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ import os, sys
sys.path.insert(0,"$(outputDir)/init/")
from env_modules_python import module
module("load","foobar bar")
module("load","A","B")
module("load","foobar")
print ("os.environ['FOOBAR']: ",'"' + os.environ['FOOBAR'] + '"')
print ("os.environ['M']: ", '"' + os.environ['M'] + '"')
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ local function new(self)
local locSitePkg = locatePkg("SitePackage") or "unknown"

if (locSitePkg ~= "unknown") then
local std_sha1 = "ed697fcb8f232ce5923c0c180d387b803b42b9f6"
local std_md5 = "7631181fc8ebc18d5bf6729c85af44d0"
local std_sha1 = "1fa3d8f24793042217b8474904136fdde72d42dd"
local std_md5 = "3c785db2ee60bc8878fe1b576c890a0f"
local HashSum = "@path_to_hashsum@"
if (HashSum:sub(1,1) == "@") then
local a = { "sha1sum", "shasum", "md5sum", "md5" }
Expand Down
110 changes: 62 additions & 48 deletions src/lmod.in.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,50 +275,59 @@ function main()
local isAvailTbl = { name = "isAvail", checkMPATH = false, cmd = IsAvail }

local lmodCmdA = {
{'^ad' , loadTbl },
{'^ap' , keywordTbl },
{'^av' , availTbl },
{'^del' , unloadTbl },
{'^des' , mcTbl },
{'^disable' , disableTbl },
{'^dis' , showTbl },
{'^era' , unloadTbl },
{'^gd' , gdTbl },
{'^getd' , gdTbl },
{'^h' , helpTbl },
{'^is[Aa]vail' , isAvailTbl },
{'^is[-_]avail' , isAvailTbl },
{'^is[Ll]oaded' , isLoadedTbl },
{'^is[-_]loaded', isLoadedTbl },
{'^k' , keywordTbl },
{'^ld' , savelistTbl },
{'^listd' , savelistTbl },
{'^lo' , loadTbl },
{'^l' , listTbl },
{'^mc' , mcTbl },
{'^pu' , purgeTbl },
{'^refr' , refreshTbl },
{'^rel' , updateTbl },
{'^rem' , unloadTbl },
{'^rese' , resetTbl },
{'^rm' , unloadTbl },
{'^r' , restoreTbl },
{'^savel' , savelistTbl },
{'^sd' , saveTbl },
{'^sea' , searchTbl },
{'^setd' , saveTbl },
{'^sh' , showTbl },
{'^sl' , savelistTbl },
{'^sp' , spiderTbl },
{'^sw' , swapTbl },
{'^s' , saveTbl },
{'^table' , tblLstTbl },
{'^try' , tryAddTbl },
{'^unuse$' , unuseTbl },
{'^unl' , unloadTbl },
{'^up' , updateTbl },
{'^use$' , useTbl },
{'^w' , whatisTbl },
{cmd = 'add', min = 2, action = loadTbl },
{cmd = 'avail', min = 2, action = availTbl },
{cmd = 'delete', min = 3, action = unloadTbl },
{cmd = 'describe', min = 3, action = mcTbl },
{cmd = 'disable', min = 4, action = disableTbl },
{cmd = 'display', min = 3, action = showTbl },
{cmd = 'erase', min = 3, action = unloadTbl },
{cmd = 'gd', min = 2, action = gdTbl },
{cmd = 'getdefault', min = 4, action = gdTbl },
{cmd = 'help', min = 1, action = helpTbl },
{cmd = 'isAvail', min = 3, action = isAvailTbl },
{cmd = 'isavail', min = 3, action = isAvailTbl },
{cmd = 'is_avail', min = 4, action = isAvailTbl },
{cmd = 'is-avail', min = 4, action = isAvailTbl },
{cmd = 'isLoaded', min = 3, action = isLoadedTbl },
{cmd = 'isloaded', min = 3, action = isLoadedTbl },
{cmd = 'is_loaded', min = 4, action = isLoadedTbl },
{cmd = 'is-loaded', min = 4, action = isLoadedTbl },
{cmd = 'keyword', min = 1, action = keywordTbl },
{cmd = 'ld', min = 2, action = savelistTbl },
{cmd = 'listdefaults', min = 5, action = savelistTbl },
{cmd = 'load', min = 2, action = loadTbl },
{cmd = 'list', min = 1, action = listTbl },
{cmd = 'mcc', min = 2, action = mcTbl },
{cmd = 'purge', min = 2, action = purgeTbl },
{cmd = 'refresh', min = 4, action = refreshTbl },
{cmd = 'reload', min = 3, action = updateTbl },
{cmd = 'remove', min = 3, action = unloadTbl },
{cmd = 'reset', min = 4, action = resetTbl },
{cmd = 'rm', min = 2, action = unloadTbl },
{cmd = 'restore', min = 1, action = restoreTbl },
{cmd = 'savelist', min = 5, action = savelistTbl },
{cmd = 'sd', min = 2, action = saveTbl },
{cmd = 'search', min = 3, action = searchTbl },
{cmd = 'setdefault', min = 4, action = saveTbl },
{cmd = 'show', min = 2, action = showTbl },
{cmd = 'sl', min = 2, action = savelistTbl },
{cmd = 'spider', min = 2, action = spiderTbl },
{cmd = 'swap', min = 2, action = swapTbl },
{cmd = 'save', min = 1, action = saveTbl },
{cmd = 'tablelist', min = 5, action = tblLstTbl },
{cmd = 'try-load', min = 5, action = tryAddTbl },
{cmd = 'try-add', min = 5, action = tryAddTbl },
{cmd = 'try_load', min = 5, action = tryAddTbl },
{cmd = 'try_add', min = 5, action = tryAddTbl },
{cmd = 'tryload', min = 4, action = tryAddTbl },
{cmd = 'tryadd', min = 4, action = tryAddTbl },
{cmd = 'try', min = 3, action = tryAddTbl },
{cmd = 'unload', min = 3, action = unloadTbl },
{cmd = 'unuse', min = 3, action = unuseTbl },
{cmd = 'update', min = 2, action = updateTbl },
{cmd = 'use', min = 3, action = useTbl },
{cmd = 'whatis', min = 1, action = whatisTbl },
}

build_i18n_messages()
Expand Down Expand Up @@ -451,17 +460,21 @@ function main()

------------------------------------------------------------
-- Search for command, quit if command is unknown.
local cmdT = false
local cmdT = false
local cmdName = false
if (userCmd) then
local uLen = userCmd:len()
for _, v in ipairs(lmodCmdA) do
if (userCmd:find(v[1])) then
cmdT = v[2]
local found = userCmd:find(v.cmd:sub(1,uLen),1,true)
if (found == 1 and uLen >= v.min) then
cmdT = v.action
cmdName = cmdT.name
break
end
end
end

hook.apply("startup", userCmd)
hook.apply("startup", cmdName)

local checkMPATH = (cmdT) and cmdT.checkMPATH or false
dbg.print{"Calling Master:singleton(checkMPATH) w checkMPATH: ",checkMPATH,"\n"}
Expand Down Expand Up @@ -531,6 +544,7 @@ function main()
vPATH:prt();
end

hook.apply("finalize", cmdName)
ExitHookA.apply()
dbg.fini("lmod")

Expand Down

0 comments on commit 72221c0

Please sign in to comment.