diff --git a/src/MC_Quiet.lua b/src/MC_Quiet.lua new file mode 100644 index 000000000..c4daa226e --- /dev/null +++ b/src/MC_Quiet.lua @@ -0,0 +1,100 @@ +-------------------------------------------------------------------------- +-- When unloading all the positive actions of a module are reversed. So +-- a "setenv()" becomes an unset and so forth. Note that reversing an +-- unload or an unsetenv command is a no-op. +-- +-- @classmod MC_Quiet + +require("strict") + +-------------------------------------------------------------------------- +-- Lmod License +-------------------------------------------------------------------------- +-- +-- Lmod is licensed under the terms of the MIT license reproduced below. +-- This means that Lmod is free software and can be used for both academic +-- and commercial purposes at absolutely no cost. +-- +-- ---------------------------------------------------------------------- +-- +-- Copyright (C) 2008-2018 Robert McLay +-- +-- Permission is hereby granted, free of charge, to any person obtaining +-- a copy of this software and associated documentation files (the +-- "Software"), to deal in the Software without restriction, including +-- without limitation the rights to use, copy, modify, merge, publish, +-- distribute, sublicense, and/or sell copies of the Software, and to +-- permit persons to whom the Software is furnished to do so, subject +-- to the following conditions: +-- +-- The above copyright notice and this permission notice shall be +-- included in all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +-- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +-- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +-- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +-- THE SOFTWARE. +-- +-------------------------------------------------------------------------- + +local MainControl = require("MainControl") +MC_Quiet = inheritsFrom(MainControl) +MC_Quiet.my_name = "MC_Quiet" +MC_Quiet.my_sType = "mt" +MC_Quiet.my_tcl_mode = "remove" + +local M = MC_Quiet +M.always_load = MainControl.quiet +M.always_unload = MainControl.quiet +M.add_property = MainControl.quiet +M.append_path = MainControl.quiet +M.build_unload = MainControl.quiet +M.color_banner = MainControl.quiet +M.complete = MainControl.quiet +M.conflict = MainControl.quiet +M.depends_on = MainControl.quiet +M.depends_on_any = MainControl.quiet +M.error = MainControl.quiet +M.execute = MainControl.quiet +M.extensions = MainControl.quiet +M.family = MainControl.quiet +M.haveDynamicMPATH = MainControl.quiet +M.help = MainControl.quiet +M.inherit = MainControl.quiet +M.load = MainControl.quiet +M.load_any = MainControl.quiet +M.load_usr = MainControl.quiet +M.mgrload = MainControl.quiet +M.myFileName = MainControl.quiet +M.myModuleFullName = MainControl.quiet +M.myModuleUsrName = MainControl.quiet +M.myModuleName = MainControl.quiet +M.myModuleVersion = MainControl.quiet +M.prepend_path = MainControl.quiet +M.prereq = MainControl.quiet +M.prereq_any = MainControl.quiet +M.purge = MainControl.quiet +M.pushenv = MainControl.quiet +M.remove_path = MainControl.quiet +M.remove_property = MainControl.quiet +M.report = MainControl.quiet +M.setenv = MainControl.quiet +M.set_alias = MainControl.quiet +M.set_shell_function = MainControl.quiet +M.source_sh = MainControl.quiet +M.try_load = MainControl.quiet +M.uncomplete = MainControl.quiet +M.unload = MainControl.quiet +M.unload_usr = MainControl.quiet +M.unsetenv = MainControl.quiet +M.unset_alias = MainControl.quiet +M.unset_shell_function = MainControl.quiet +M.usrload = MainControl.quiet +M.whatis = MainControl.quiet +M.LmodBreak = MainControl.quiet + +return M diff --git a/src/MainControl.lua b/src/MainControl.lua index 5eaffdc4e..5eac2c56c 100644 --- a/src/MainControl.lua +++ b/src/MainControl.lua @@ -251,6 +251,7 @@ function M.build(name,mode) local MCSpider = require('MC_Spider') local MCComputeHash = require('MC_ComputeHash') local MCCheckSyntax = require('MC_CheckSyntax') + local MCQuiet = require('MC_Quiet') s_nameTbl = { ["load"] = MCLoad, -- Normal loading of modules @@ -265,6 +266,8 @@ function M.build(name,mode) ["checkSyntax"] = MCCheckSyntax, -- Check the syntax of a module, load, prereq, etc -- are ignored. ["dependencyCk"] = MCDepCk, -- Report any missing dependency modules + ["quiet"] = MCQuiet, -- All operations are NO Ops (A.K.A quiet) + } end diff --git a/src/lmod.in.lua b/src/lmod.in.lua index 5e5e570e5..5da367f60 100644 --- a/src/lmod.in.lua +++ b/src/lmod.in.lua @@ -350,8 +350,9 @@ function main() Shell = BaseShell:build(shellNm) local optionTbl = optionTbl() - MCP = MainControl.build("load") - mcp = MainControl.build("load") + MCP = MainControl.build("load") + MCPQ = MainControl.build("quiet") + mcp = MainControl.build("load") ------------------------------------------------------------------ -- initialize lmod with SitePackage and /etc/lmod/lmod_config.lua diff --git a/src/modfuncs.lua b/src/modfuncs.lua index eb2cec233..68782d909 100644 --- a/src/modfuncs.lua +++ b/src/modfuncs.lua @@ -67,8 +67,8 @@ local dbg = require("Dbg"):dbg() local hook = require("Hook") local max = math.max local _concatTbl = table.concat -local pack = (_VERSION == "Lua 5.1") and argsPack or table.pack -- luacheck: compat - +local pack = (_VERSION == "Lua 5.1") and argsPack or table.pack -- luacheck: compat +local unpack = (_VERSION == "Lua 5.1") and unpack or table.unpack -- luacheck: compat -------------------------------------------------------------------------- -- Special table concat function that knows about strings and numbers. -- @param aa Input array @@ -187,12 +187,11 @@ local function l_validateModules(cmdName, ...) return allGood end - -------------------------------------------------------------------------- -- Convert all function arguments to table form -- first_elem seperated from args for type test -function list_2_Tbl(MCP, mcp, first_elem, ...) - dbg.start{"list_2_Tbl(",l_concatTbl({first_elem, ...},", "),")"} +local function l_list_2_Tbl(first_elem, ...) + dbg.start{"l_list_2_Tbl(",l_concatTbl({first_elem, ...},", "),")"} local my_mcp = nil local t = nil @@ -217,22 +216,12 @@ function list_2_Tbl(MCP, mcp, first_elem, ...) action = true end - if ( not action ) then my_mcp = nil end + if ( not action ) then my_mcp = MCPQ end dbg.print{"OutputTable: ", t, "\n"} - dbg.fini("list_2_Tbl") + dbg.fini("l_list_2_Tbl") return my_mcp, t end -function inTable(tbl, val) - for _, v in ipairs(tbl) do - if v == val then - return true - end - end - return false -end - - -------------------------------------------------------------------------- -- The load function. It can be found in the following forms: -- "load('name'); load('name/1.2'); load(atleast('name','3.2'))", @@ -243,20 +232,15 @@ function load_module(...) local argTable local mcp_old = mcp - mcp, argTable = list_2_Tbl(MCP, mcp, ...) - if (not mcp) then - mcp = mcp_old - dbg.fini("load_module") - return {} - end + mcp, argTable = l_list_2_Tbl( ...) - if (not l_validateModules("load", table.unpack(argTable))) then + if (not l_validateModules("load", unpack(argTable))) then mcp = mcp_old dbg.fini("load_module") return {} end - local b = mcp:load_usr(MName:buildA(mcp:MNameType(), table.unpack(argTable))) + local b = mcp:load_usr(MName:buildA(mcp:MNameType(), unpack(argTable))) mcp = mcp_old dbg.fini("load_module") @@ -359,8 +343,12 @@ end function pushenv(...) dbg.start{"pushenv(",l_concatTbl({...},", "),")"} if (not l_validateArgsWithValue("pushenv",...)) then return end - - mcp:pushenv(...) + local argTable + local mcp_old = mcp + + mcp, argTable = l_list_2_Tbl( ...) + mcp:pushenv(argTable) + mcp = mcp_old dbg.fini("pushenv") return end @@ -382,15 +370,11 @@ function setenv(...) local argTable local mcp_old = mcp - mcp, argTable = list_2_Tbl(MCP, mcp, ...) - if ( not mcp ) then - mcp = mcp_old - return - end + mcp, argTable = l_list_2_Tbl( ...) if (not l_validateArgsWithValue("setenv", argTable)) then return end - mcp:setenv(table.unpack(argTable)) + mcp:setenv(unpack(argTable)) mcp = mcp_old dbg.fini("setenv") return @@ -404,15 +388,11 @@ function unsetenv(...) local argTable local mcp_old = mcp - mcp, argTable = list_2_Tbl(MCP, mcp, ...) - if ( not mcp ) then - mcp = mcp_old - return - end + mcp, argTable = l_list_2_Tbl( ...) if (not l_validateArgsWithValue("unsetenv", argTable)) then return end - mcp:unsetenv(table.unpack(argTable)) + mcp:unsetenv(unpack(argTable)) mcp = mcp_old dbg.fini("unsetenv") return @@ -928,15 +908,10 @@ function unload(...) local argTable local mcp_old = mcp - mcp, argTable = list_2_Tbl(MCP, mcp, ...) - if (not mcp) then - mcp = mcp_old - dbg.fini("unload_module") - return {} - end + mcp, argTable = l_list_2_Tbl( ...) - if (not l_validateModules("unload", table.unpack(argTable))) then return {} end - local b = unload_internal(MName:buildA("mt",table.unpack(argTable))) + if (not l_validateModules("unload", unpack(argTable))) then return {} end + local b = unload_internal(MName:buildA("mt",unpack(argTable))) dbg.fini("unload") return b end diff --git a/src/myGlobals.lua b/src/myGlobals.lua index 6c87a2ff0..4321b094c 100644 --- a/src/myGlobals.lua +++ b/src/myGlobals.lua @@ -490,12 +490,18 @@ cosmic:init{name = "LFS_VERSION", -- ------------------------------------------------------------------------ --- MCP, mcp: MainControl Program objects. These objects implement --- the module functions: load, setenv, prepend_path, etc. +-- MCP, MCPQ, mcp: MainControl Program objects. These objects implement +-- the module functions: load, setenv, prepend_path, etc. +-- -- MCP is always positive. That is, load is load, setenv is --- setenv. Where as mcp is dynamic. It is positive on load +-- setenv. +-- +-- mcp: is dynamic. It is positive on load -- and the reverse on unload. +-- +-- MCPQ is always quiet. ------------------------------------------------------------------------ +MCPQ = false MCP = false mcp = false