Skip to content

Commit

Permalink
mode select progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcawood committed Dec 10, 2024
1 parent 9e2b344 commit 95bc177
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 74 deletions.
4 changes: 4 additions & 0 deletions messageDir/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ return {
e_Args_Not_Strings = [==[Syntax error in file: %{fn}
with command: %{cmdName}, one or more arguments are not strings.
]==], --
e_Mode_Does_Not_Exist = [==[Syntax error in file: %{fn}
with command: %{cmdName}, mode is not defined.
]==], --

e_Args_Not_Table = [==[Syntax error in file: %{fn}
with function: %{func}, is not a table.
]==], --
Expand Down
21 changes: 21 additions & 0 deletions rt/unload/mf/Core/C/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
setenv{"A", "A", mode={"load"}}
setenv{"A", "B", mode={"unload"}}
pushenv{"STACK_VAR", "load_value", mode={"load"}}
pushenv{"STACK_VAR", "unload_value", mode={"unload"}}

-- Path operation tests
prepend_path{"PATH_TEST", "/first", mode={"load"}}
prepend_path{"PATH_TEST", "/unload_first", mode={"unload"}}

append_path{"PATH_TEST", "/last", mode={"load"}}
append_path{"PATH_TEST", "/unload_last", mode={"unload"}}

-- Test remove during specific modes
remove_path{"PATH_TEST", "/to_remove", mode={"unload"}}


--setenv{"AA", "X", mode={"load", "unload"}}
--prepend_path{"FOO", "BAR", mode={"unload", "load"}}
--append_path{"X", "Y", mode={"unload"}}
--load{"D", mode={"unload"}}
--try_load{"J", mode={"unload"}}
4 changes: 4 additions & 0 deletions rt/unload/mf/Core/D/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Test module D
load{"E", mode={"load"}}
-- load{"A", "B", "C", mode="unload"}
setenv("D_LOADED", "yes")
2 changes: 2 additions & 0 deletions rt/unload/mf/Core/E/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Test module E
setenv("E_LOADED", "yes")
2 changes: 2 additions & 0 deletions rt/unload/mf/Core/F/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Test module F
setenv("F_LOADED", "yes")
9 changes: 9 additions & 0 deletions rt/unload/unload.tdesc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ testdescript = {
runLmod unload intel # 7
runLmod load B # 8
runLmod unload B # 9
runLmod load C # 10
runLmod unload C # 11
# Test mode-specific load functionality
runLmod load F # 12 (Load F first for unload test)
runLmod load D # 13 (Should load E, not affect F)
runLmod list # 14 (Should show D, E, and F loaded)
runLmod unload D # 15 (Should unload F, keep E)
runLmod list # 16 (Should show only E loaded)
HOME=$ORIG_HOME
Expand Down
34 changes: 25 additions & 9 deletions src/MT.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1106,19 +1106,34 @@ end

--------------------------------------------------------------------------
-- Build the name of the *family* env. variable.
--local function l_buildFamilyPrefix()
-- if (not s_familyA) then
-- s_familyA = {}
-- s_familyA[1] = "LMOD_FAMILY_"
-- local siteName = hook.apply("SiteName")
-- if (siteName) then
-- s_familyA[2] = siteName .. "_FAMILY_"
-- end
-- end
-- return s_familyA
--end

local function l_buildFamilyPrefix()
dbg.start{"l_buildFamilyPrefix()"}
if (not s_familyA) then
s_familyA = {}
s_familyA[1] = "LMOD_FAMILY_"
dbg.print{"Initializing s_familyA\n"}
s_familyA = { "LMOD_FAMILY_" }
local siteName = hook.apply("SiteName")
dbg.print{"siteName: ", siteName, "\n"}
if (siteName) then
s_familyA[2] = siteName .. "_FAMILY_"
s_familyA[#s_familyA + 1] = siteName .. "_FAMILY_"
end
end
dbg.print{"s_familyA at return: ", s_familyA, "\n"}
dbg.fini("l_buildFamilyPrefix")
return s_familyA
end


--------------------------------------------------------------------------
-- Set the family
-- @param self An MT object
Expand All @@ -1130,12 +1145,11 @@ function M.setfamily(self,familyNm,mName)
local familyA = l_buildFamilyPrefix()
for i = 1,#familyA do
local n = familyA[i] .. familyNm:upper()
MCP:setenv(n, mName)
MCP:setenv(n .. "_VERSION", myModuleVersion())
MCP:setenv{n, mName}
MCP:setenv{n .. "_VERSION", myModuleVersion()}
end
return results
end

--------------------------------------------------------------------------
-- Unset the family
-- @param self An MT object
Expand All @@ -1144,8 +1158,8 @@ function M.unsetfamily(self,familyNm)
local familyA = l_buildFamilyPrefix()
for i = 1,#familyA do
local n = familyA[i] .. familyNm:upper()
MCP:unsetenv(n, "")
MCP:unsetenv(n .. "_VERSION", "")
MCP:unsetenv{n}
MCP:unsetenv{n .. "_VERSION"}
end
self.family[familyNm] = nil
end
Expand Down Expand Up @@ -1625,3 +1639,5 @@ end


return M


117 changes: 100 additions & 17 deletions src/MainControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,15 @@ local function l_compareRequestedLoadsWithActual()
end

local function l_check_for_valid_name(kind, name)
dbg.start{"l_check_for_valid_name(kind=", kind, ", name='", name, "')"}
dbg.print{"Caller stack:\n", debug.traceback(), "\n"}
local l = name:len()
local i, j = name:find("^[a-zA-Z_][a-zA-Z0-9_]*")
if (j ~= l) then
dbg.print{"Invalid name detected: '", name, "'\n"}
LmodError{msg="e_BadName",kind=kind, name=name}
end
dbg.fini("l_check_for_valid_name")
end

local function l_check_for_valid_alias_name(kind, name)
Expand Down Expand Up @@ -312,10 +316,16 @@ end
-- @param name the environment variable name.
-- @param value the environment variable value.
-- @param respect If true, then respect the old value.
function M.setenv(self, name, value, respect)
name = (name or ""):trim()
function M.setenv(self, t)
-- Extract values from table
local name = (t[1] or ""):trim()
local value = t[2]
local respect = t.respect

dbg.start{"MainControl:setenv(\"",name,"\", \"",value,"\", \"",
respect,"\")"}
dbg.print{"setenv context - Mode: ", self:mode(), ", Stack depth: ", FrameStk:singleton():stackDepth(), "\n"}
dbg.print{"setenv caller stack:\n", debug.traceback(), "\n"}

l_check_for_valid_name("setenv",name)

Expand Down Expand Up @@ -343,9 +353,14 @@ end
-- Set an environment variable.
-- This function just sets the name with value in the current env.
function M.setenv_env(self, name, value, respect)
dbg.start{"MainControl:setenv_env - raw inputs: name='", name, "', value='", value, "', respect='", respect, "'"}
if name == nil then
dbg.print{"WARNING: name is nil in setenv_env\n"}
dbg.fini("MainControl:setenv_env")
return
end
name = (name or ""):trim()
dbg.start{"MainControl:setenv_env(\"",name,"\", \"",value,"\", \"",
respect,"\")"}
dbg.print{"MainControl:setenv_env - after trim: name='", name, "'\n"}
posix.setenv(name, value, true)
dbg.fini("MainControl:setenv_env")
end
Expand All @@ -357,10 +372,26 @@ end
-- @param name the environment variable name.
-- @param value the environment variable value.
-- @param respect If true, then respect the old value.
function M.unsetenv(self, name, value, respect)
name = (name or ""):trim()
dbg.start{"MainControl:unsetenv(\"",name,"\", \"",value,"\")"}
function M.unsetenv(self, t)
-- Extract values from table
dbg.start{"MainControl:unsetenv - input table t: ", type(t)}
if type(t) ~= "table" then
dbg.print{"WARNING: Input to unsetenv is not a table, type is ", type(t), "\n"}
dbg.fini("MainControl:unsetenv")
return
end

dbg.print{"t contents:\n"}
for k,v in pairs(t) do
dbg.print{" ", k, " = ", v, "\n"}
end

local name = (t[1] or ""):trim()
local value = t[2]
local respect = t.respect

dbg.print{"After extraction: name='", name, "', value='", value, "', respect='", respect, "'\n"}

l_check_for_valid_name("unsetenv",name)

if (respect and getenv(name) ~= value) then
Expand Down Expand Up @@ -393,18 +424,17 @@ end
-- @param self A MainControl object.
-- @param name the environment variable name.
-- @param value the environment variable value.
function M.pushenv(self, name, value)
name = (name or ""):trim()
function M.pushenv(self, t)
-- Extract values from table
local name = (t[1] or ""):trim()
local value = t[2]

dbg.start{"MainControl:pushenv(\"",name,"\", \"",value,"\")"}

l_check_for_valid_name("pushenv",name)
----------------------------------------------------------------
-- If name exists in the env and the stack version of the name
-- doesn't exist then use the name's value as the initial value
-- for "stackName".

if (value == nil) then
LmodError{msg="e_Missing_Value",func = "pushenv", name = name}
LmodError{msg="e_Missing_Value", func = "pushenv", name = name}
end

local stackName = l_createStackName(name)
Expand Down Expand Up @@ -529,7 +559,7 @@ function M.append_path(self, t)
local delim = t.delim or ":"
local name = t[1]
local value = t[2]
local nodups = not allow_dups( not t.nodups)
local nodups = not allow_dups(not t.nodups)
local priority = t.priority or 0
local frameStk = FrameStk:singleton()
local varT = frameStk:varT()
Expand Down Expand Up @@ -560,7 +590,7 @@ function M.remove_path(self, t)
local delim = t.delim or ":"
local name = t[1]
local value = t[2]
local nodups = not allow_dups( not t.nodups)
local nodups = not allow_dups(not t.nodups)
local priority = t.priority or 0
local where = t.where
local frameStk = FrameStk:singleton()
Expand Down Expand Up @@ -1182,6 +1212,24 @@ function M.load_usr(self, mA)
return {}
end

-- Check if we're in unload mode and handle accordingly
if (self:mode() == "unload") then
-- In unload mode, we want to unload any modules that are loaded
local mt = frameStk:mt()
local mB = {}
for i = 1, #mA do
local mname = mA[i]
if (mname:isloaded()) then
mB[#mB + 1] = mname
end
end
if (#mB > 0) then
l_unRegisterUserLoads(mB)
return self:unload(mB)
end
return {}
end

l_registerUserLoads(mA)
local a = self:load(mA)
dbg.fini("MainControl:load_usr")
Expand All @@ -1195,6 +1243,15 @@ end
function mAList(mA)
local a = {}
for i = 1, #mA do
dbg.print{"Inspecting mA[", i, "] before userName call:\n"}
if type(mA[i]) == "table" then
dbg.print{" Table contents:\n"}
for k,v in pairs(mA[i]) do
dbg.print{" ", k, " = ", type(v), " : ", tostring(v), "\n"}
end
else
dbg.print{" Not a table, type: ", type(mA[i]), "\n"}
end
a[#a + 1] = mA[i]:userName()
end
return concatTbl(a, ", ")
Expand All @@ -1207,7 +1264,18 @@ function M.load(self, mA)
end

local hub = Hub:singleton()
local a = hub:load(mA)

-- Filter modules based on mode
local filteredMA = {}
local currentMode = self:mode()
for i = 1, #mA do
local mname = mA[i]
if not mname.__mode or (mname.__mode and contains(mname.__mode, currentMode)) then
filteredMA[#filteredMA + 1] = mname
end
end

local a = hub:load(filteredMA)

if (not quiet()) then
self:registerAdminMsg(mA)
Expand Down Expand Up @@ -1529,17 +1597,31 @@ function M.family(self, name)
local optionTbl = optionTbl()
local auto_swap = cosmic:value("LMOD_AUTO_SWAP")

dbg.print{"MainControl:family state - fullName: ", fullName, ", sn: ", sn, ", mt type: ", type(mt), "\n"}

l_check_for_valid_name("family",name)

dbg.print{"Before getfamily - name: ", name, "\n"}
local oldName = mt:getfamily(name)
dbg.print{"After getfamily - oldName: ", oldName, "\n"}

if (oldName ~= nil and oldName ~= sn and not expert() ) then
dbg.print{"Found existing family member\n"}
dbg.print{"Family state - oldName: ", oldName, ", sn: ", sn, "\n"}
if (auto_swap ~= "no") then
dbg.print{"Calling familyStackPush\n"}
dbg.print{"Stack push state - oldName: ", oldName, ", sn: ", sn, "\n"}
self.familyStackPush(oldName, sn)
else
LmodError{msg="e_Family_Conflict", name = name, oldName = oldName, fullName = fullName}
end
end

dbg.print{"Before setfamily - name: ", name, " sn: ", sn, "\n"}
dbg.print{"Setfamily state - mt: ", type(mt), ", name: ", name, ", sn: ", sn, "\n"}
mt:setfamily(name,sn)
dbg.print{"After setfamily\n"}

dbg.fini("MainControl:family")
end

Expand Down Expand Up @@ -1868,3 +1950,4 @@ function M.haveDynamicMPATH(self)
end

return M

2 changes: 2 additions & 0 deletions src/loadModuleFile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require("utils")
local dbg = require("Dbg"):dbg()
local concatTbl = table.concat
local getenv = os.getenv
local FrameStk = require("FrameStk")

local s_mfileCountT = {}

Expand All @@ -59,6 +60,7 @@ local s_mfileCountT = {}
-- things like the current list of modules and the shell.
function loadModuleFile(t)
dbg.start{"loadModuleFile(",t.file,")"}
dbg.print{"Stack state - Current mode: ", mode(), ", Frame depth: ", FrameStk:singleton():stackDepth(), "\n"}

local myType = extname(t.file)
local forbiddenT = t.forbiddenT or {}
Expand Down
Loading

0 comments on commit 95bc177

Please sign in to comment.