main.tcl.in (modules-5.1.1.tar.bz2) | : | main.tcl.in (modules-5.2.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU General Public License for more details. | # GNU General Public License for more details. | |||
# | # | |||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | |||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
########################################################################## | ########################################################################## | |||
# exit in a clean manner by closing interaction with external components | # exit in a clean manner by flushing and closing interaction with external | |||
proc cleanupAndExit {code} { | # components | |||
# finish output document if json format enabled | proc flushAndExit {code} { | |||
if {[isStateEqual report_format json]} { | # output all shell code generated on stdout | |||
# render error messages all together | renderFlush | |||
if {[info exists ::g_report_erralist]} { | # output last messages on the report file descriptor and close it | |||
# ignite report first to get eventual error message from report | reportFlush | |||
# initialization in order 'foreach' got all messages prior firing | ||||
report "\"errors\": \[" 1 | ||||
foreach {sev msg} $::g_report_erralist { | ||||
# split message in lines | ||||
lappend dispmsglist "\n{ \"severity\": \"$sev\", \"message\": \[\ | ||||
\"[join [split [charEscaped $msg \"] \n] {", "}]\" \] }" | ||||
} | ||||
report "[join $dispmsglist ,] \]" | ||||
} | ||||
# inhibit next content separator if output is ending | ||||
if {[isStateDefined report_sep_next]} { | ||||
unsetState report_sep_next | ||||
} | ||||
report \} | ||||
} | ||||
# close pager if enabled | ||||
if {[isStateDefined reportfd] && ![isStateEqual reportfd stderr]} { | ||||
catch {flush [getState reportfd]} | ||||
catch {close [getState reportfd]} | ||||
} | ||||
exit $code | exit $code | |||
} | } | |||
# runs the global RC files if they exist | # runs the global RC files if they exist | |||
proc runModulerc {} { | proc runModulerc {} { | |||
set rclist {} | ||||
if {[set rcfile [getConf rcfile]] ne {}} { | ||||
# if MODULERCFILE is a dir, look at a modulerc file in it | ||||
if {[file isdirectory $rcfile]\ | ||||
&& [file isfile $rcfile/modulerc]} { | ||||
lappend rclist $rcfile/modulerc | ||||
} elseif {[file isfile $rcfile]} { | ||||
lappend rclist $rcfile | ||||
} | ||||
} | ||||
if {[file isfile @etcdir@/rc]} { | ||||
lappend rclist @etcdir@/rc | ||||
} | ||||
if {[info exists ::env(HOME)] && [file isfile $::env(HOME)/.modulerc]} { | ||||
lappend rclist $::env(HOME)/.modulerc | ||||
} | ||||
setState rc_running 1 | setState rc_running 1 | |||
foreach rc $rclist { | foreach rc [getGlobalRcFileList] { | |||
if {[file readable $rc]} { | reportDebug "Executing $rc" | |||
reportDebug "Executing $rc" | cmdModuleSource load $rc | |||
cmdModuleSource load $rc | lappendState rc_loaded $rc | |||
lappendState rc_loaded $rc | ||||
} | ||||
} | } | |||
unsetState rc_running | unsetState rc_running | |||
# identify alias or symbolic version set in these global RC files to be | # identify alias or symbolic version set in these global RC files to be | |||
# able to include them or not in output or resolution processes | # able to include them or not in output or resolution processes | |||
array set ::g_rcAlias [array get ::g_moduleAlias] | array set ::g_rcAlias [array get ::g_moduleAlias] | |||
array set ::g_rcVersion [array get ::g_moduleVersion] | array set ::g_rcVersion [array get ::g_moduleVersion] | |||
array set ::g_rcVirtual [array get ::g_moduleVirtual] | array set ::g_rcVirtual [array get ::g_moduleVirtual] | |||
} | } | |||
skipping to change at line 151 | skipping to change at line 110 | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
set cmdvalid [expr {$command in [list load unload reload use unuse source\ | set cmdvalid [expr {$command in [list load unload reload use unuse source\ | |||
switch display avail aliases path paths list whatis search purge save\ | switch display avail aliases path paths list whatis search purge save\ | |||
restore saverm saveshow savelist initadd initprepend initswitch initrm\ | restore saverm saveshow savelist initadd initprepend initswitch initrm\ | |||
initlist initclear autoinit clear config help test prepend-path\ | initlist initclear autoinit clear config help test prepend-path\ | |||
append-path remove-path is-loaded is-saved is-used is-avail info-loaded\ | append-path remove-path is-loaded is-saved is-used is-avail info-loaded\ | |||
sh-to-mod edit try-load refresh state load-any]}] | sh-to-mod edit try-load refresh state load-any lint mod-to-sh reset\ | |||
stash stashpop stashrm stashshow stashclear stashlist]}] | ||||
reportDebug "(command=$command, cmdvalid=$cmdvalid, cmdempty=$cmdempty)" | reportDebug "(command=$command, cmdvalid=$cmdvalid, cmdempty=$cmdempty)" | |||
return [list $command $cmdvalid $cmdempty] | return [list $command $cmdvalid $cmdempty] | |||
} | } | |||
# analyze arg list passed to a module cmd to set options | # analyze arg list passed to a module cmd to set options | |||
proc parseModuleCommandArgs {topcall cmd ignerr args} { | proc parseModuleCommandArgs {topcall cmd ignerr args} { | |||
set show_oneperline 0 | set show_oneperline 0 | |||
set show_mtime 0 | set show_mtime 0 | |||
set show_filter {} | set show_filter {} | |||
skipping to change at line 173 | skipping to change at line 133 | |||
set search_match [getConf search_match] | set search_match [getConf search_match] | |||
set dump_state 0 | set dump_state 0 | |||
set addpath_pos prepend | set addpath_pos prepend | |||
set not_req 0 | set not_req 0 | |||
set tag_list {} | set tag_list {} | |||
set otherargs {} | set otherargs {} | |||
# parse argument list | # parse argument list | |||
foreach arg $args { | foreach arg $args { | |||
if {[info exists nextargisval]} { | if {[info exists nextargisval]} { | |||
##nagelfar vartype nextargisval varName | ||||
set $nextargisval $arg | set $nextargisval $arg | |||
unset nextargisval | unset nextargisval | |||
} elseif {[info exists nextargisvaltosplit]} { | } elseif {[info exists nextargisvaltosplit]} { | |||
##nagelfar vartype nextargisvaltosplit varName | ||||
set $nextargisvaltosplit [split $arg :] | set $nextargisvaltosplit [split $arg :] | |||
unset nextargisvaltosplit | unset nextargisvaltosplit | |||
} elseif {[info exists ignore_next_arg]} { | } elseif {[info exists ignore_next_arg]} { | |||
unset ignore_next_arg | unset ignore_next_arg | |||
} else { | } else { | |||
switch -glob -- $arg { | switch -glob -- $arg { | |||
-j - --json { | -j - --json { | |||
# enable json output only on supported command | # enable json output only on supported command | |||
if {$cmd in [list avail savelist list search whatis]} { | if {$cmd in [list avail savelist stashlist list search\ | |||
whatis]} { | ||||
setState report_format json | setState report_format json | |||
set show_oneperline 0 | set show_oneperline 0 | |||
set show_mtime 0 | set show_mtime 0 | |||
} | } | |||
} | } | |||
-t - --terse { | -t - --terse { | |||
set show_oneperline 1 | set show_oneperline 1 | |||
set show_mtime 0 | set show_mtime 0 | |||
setState report_format terse | setState report_format terse | |||
} | } | |||
skipping to change at line 226 | skipping to change at line 189 | |||
set output_arg --output | set output_arg --output | |||
} elseif {!$ignerr} { | } elseif {!$ignerr} { | |||
knerror "Unsupported option '--output' on $cmd sub-command" | knerror "Unsupported option '--output' on $cmd sub-command" | |||
} | } | |||
} | } | |||
--tag=* - --tag { | --tag=* - --tag { | |||
# option is only valid for specific sub-commands | # option is only valid for specific sub-commands | |||
# unload allowed not to raise error on unload/load mixed ml cmd | # unload allowed not to raise error on unload/load mixed ml cmd | |||
if {$cmd in [list load try-load load-any switch unload]} { | if {$cmd in [list load try-load load-any switch unload]} { | |||
if {$arg eq {--tag}} { | if {$arg eq {--tag}} { | |||
##nagelfar ignore Found constant | ||||
set nextargisvaltosplit tag_list | set nextargisvaltosplit tag_list | |||
} else { | } else { | |||
set tag_list [split [string range $arg 6 end] :] | set tag_list [split [string range $arg 6 end] :] | |||
if {[llength $tag_list] == 0} { | if {[llength $tag_list] == 0} { | |||
knerror "Missing value for '--tag' option" | knerror "Missing value for '--tag' option" | |||
} | } | |||
} | } | |||
} elseif {!$ignerr} { | } elseif {!$ignerr} { | |||
knerror "Unsupported option '--tag' on $cmd sub-command" | knerror "Unsupported option '--tag' on $cmd sub-command" | |||
} | } | |||
skipping to change at line 253 | skipping to change at line 217 | |||
} | } | |||
-p - --prepend - -prepend { | -p - --prepend - -prepend { | |||
if {$cmd eq {use}} { | if {$cmd eq {use}} { | |||
set addpath_pos prepend | set addpath_pos prepend | |||
} else { | } else { | |||
lappend otherargs $arg | lappend otherargs $arg | |||
} | } | |||
} | } | |||
--all { | --all { | |||
# include hidden modules only on a limited set of command | # include hidden modules only on a limited set of command | |||
if {$cmd in [list avail aliases search whatis ml list]} { | if {$cmd in [list avail aliases search whatis ml list lint\ | |||
savelist]} { | ||||
setState hiding_threshold 2 | setState hiding_threshold 2 | |||
} else { | } else { | |||
lappend otherargs $arg | lappend otherargs $arg | |||
} | } | |||
} | } | |||
-a { | -a { | |||
# -a option has a different meaning whether sub-command is use | # -a option has a different meaning whether sub-command is use | |||
# or one of the search/listing sub-commands | # or one of the search/listing sub-commands | |||
if {$cmd eq {use}} { | if {$cmd eq {use}} { | |||
set addpath_pos append | set addpath_pos append | |||
} elseif {$cmd in [list avail aliases search whatis ml list]} { | } elseif {$cmd in [list avail aliases search whatis ml list\ | |||
lint savelist]} { | ||||
setState hiding_threshold 2 | setState hiding_threshold 2 | |||
} else { | } else { | |||
lappend otherargs $arg | lappend otherargs $arg | |||
} | } | |||
} | } | |||
-d - --default { | -d - --default { | |||
# in case of *-path command, -d means --delim | # in case of *-path command, -d means --delim | |||
if {$arg eq {-d} && [string match *-path $cmd]} { | if {$arg eq {-d} && [string match *-path $cmd]} { | |||
lappend otherargs $arg | lappend otherargs $arg | |||
} else { | } else { | |||
skipping to change at line 351 | skipping to change at line 317 | |||
# check option value is coherent with current sub-command | # check option value is coherent with current sub-command | |||
if {[isDiffBetweenList [split $asked_output :] [lindex\ | if {[isDiffBetweenList [split $asked_output :] [lindex\ | |||
$::g_config_defs($outputconf) 3]]} { | $::g_config_defs($outputconf) 3]]} { | |||
if {!$ignerr} { | if {!$ignerr} { | |||
knerror "Invalid element in value list for '$output_arg'\ | knerror "Invalid element in value list for '$output_arg'\ | |||
option on $cmd sub-command\nAllowed elements are: [lindex\ | option on $cmd sub-command\nAllowed elements are: [lindex\ | |||
$::g_config_defs($outputconf) 3] (separated by ':')" | $::g_config_defs($outputconf) 3] (separated by ':')" | |||
} | } | |||
} else { | } else { | |||
##nagelfar ignore Suspicious variable name | ||||
set ::asked_$outputconf $asked_output | set ::asked_$outputconf $asked_output | |||
} | } | |||
} | } | |||
} | } | |||
reportDebug "(show_oneperline=$show_oneperline, show_mtime=$show_mtime,\ | reportDebug "(show_oneperline=$show_oneperline, show_mtime=$show_mtime,\ | |||
show_filter=$show_filter, search_filter=$search_filter,\ | show_filter=$show_filter, search_filter=$search_filter,\ | |||
search_match=$search_match, dump_state=$dump_state,\ | search_match=$search_match, dump_state=$dump_state,\ | |||
addpath_pos=$addpath_pos, not_req=$not_req, tag_list=$tag_list,\ | addpath_pos=$addpath_pos, not_req=$not_req, tag_list=$tag_list,\ | |||
otherargs=$otherargs)" | otherargs=$otherargs)" | |||
skipping to change at line 399 | skipping to change at line 366 | |||
# parse options, do that globally to ignore options not related to a given | # parse options, do that globally to ignore options not related to a given | |||
# module sub-command (exclude them from arg list) | # module sub-command (exclude them from arg list) | |||
lassign [parseModuleCommandArgs $topcall $command 0 {*}$args]\ | lassign [parseModuleCommandArgs $topcall $command 0 {*}$args]\ | |||
show_oneperline show_mtime show_filter search_filter search_match\ | show_oneperline show_mtime show_filter search_filter search_match\ | |||
dump_state addpath_pos not_req tag_list args | dump_state addpath_pos not_req tag_list args | |||
# parse module version specification | # parse module version specification | |||
defineParseModuleSpecificationProc [getConf advanced_version_spec] | defineParseModuleSpecificationProc [getConf advanced_version_spec] | |||
if {$command in [list avail paths whatis load unload switch help test\ | if {$command in [list avail paths whatis load unload switch help test\ | |||
display path is-avail edit try-load load-any list]} { | display path is-avail edit try-load load-any list lint mod-to-sh\ | |||
source]} { | ||||
set args [parseModuleSpecification 0 {*}$args] | set args [parseModuleSpecification 0 {*}$args] | |||
} | } | |||
if {!$topcall} { | if {!$topcall} { | |||
# some commands can only be called from top level, not within modulefile | # some commands can only be called from top level, not within modulefile | |||
switch -- $command { | switch -- $command { | |||
path - paths - autoinit - help - prepend-path - append-path -\ | path - paths - autoinit - help - prepend-path - append-path -\ | |||
remove-path - is-loaded - is-saved - is-used - is-avail -\ | remove-path - is-loaded - is-saved - is-used - is-avail -\ | |||
info-loaded - clear - sh-to-mod - edit - refresh - source - state { | info-loaded - clear - sh-to-mod - edit - refresh - source - state -\ | |||
lint - mod-to-sh - reset - stash - stashpop - stashrm - stashshow -\ | ||||
stashclear - stashlist { | ||||
knerror "${msgprefix}Command '$command' not supported$tryhelpmsg" | knerror "${msgprefix}Command '$command' not supported$tryhelpmsg" | |||
} | } | |||
} | } | |||
# other commands can only be called from modulefile evaluated from | # other commands can only be called from modulefile evaluated from | |||
# command acting as top-level context (source and autoinit) | # command acting as top-level context (source and autoinit) | |||
if {([depthState modulename] > 1 || [currentState commandname] ni [list\ | if {([depthState modulename] > 1 || [currentState commandname] ni [list\ | |||
source autoinit]) && $command eq {config}} { | source autoinit]) && $command eq {config}} { | |||
knerror "${msgprefix}Command '$command' not supported$tryhelpmsg" | knerror "${msgprefix}Command '$command' not supported$tryhelpmsg" | |||
} | } | |||
# no requirement should be recorded this module load/unload/switch cmd | # no requirement should be recorded this module load/unload/switch cmd | |||
skipping to change at line 432 | skipping to change at line 402 | |||
} | } | |||
# argument number check | # argument number check | |||
switch -- $command { | switch -- $command { | |||
unload - source - display - initadd - initprepend - initrm - test -\ | unload - source - display - initadd - initprepend - initrm - test -\ | |||
is-avail - try-load - load-any { | is-avail - try-load - load-any { | |||
if {[llength $args] == 0} { | if {[llength $args] == 0} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
refresh - reload - aliases - purge - savelist - initlist - initclear -\ | refresh - reload - aliases - purge - initlist - initclear - autoinit -\ | |||
autoinit { | reset - stash - stashclear - stashlist { | |||
if {[llength $args] != 0} { | if {[llength $args] != 0} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
switch { | switch { | |||
if {[llength $args] == 0 || [llength $args] > 2} { | if {[llength $args] == 0 || [llength $args] > 2} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
path - paths - info-loaded - edit { | path - paths - info-loaded - edit { | |||
if {[llength $args] != 1} { | if {[llength $args] != 1} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
search - save - restore - saverm - saveshow - clear - state { | search - save - restore - saverm - saveshow - clear - state - stashpop\ | |||
- stashrm - stashshow { | ||||
if {[llength $args] > 1} { | if {[llength $args] > 1} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
initswitch { | initswitch { | |||
if {[llength $args] != 2} { | if {[llength $args] != 2} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
prepend-path - append-path - remove-path - sh-to-mod { | prepend-path - append-path - remove-path - sh-to-mod - mod-to-sh { | |||
if {[llength $args] < 2} { | if {[llength $args] < 2} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
config { | config { | |||
if {[llength $args] > 2} { | if {[llength $args] > 2} { | |||
set argnberr 1 | set argnberr 1 | |||
} | } | |||
} | } | |||
} | } | |||
if {[info exists argnberr]} { | if {[info exists argnberr]} { | |||
knerror "Unexpected number of args for '$command' command$tryhelpmsg" | knerror "Unexpected number of args for '$command' command$tryhelpmsg" | |||
} | } | |||
# define if modfile should always be fully read even for validity check | # define if modfile should always be fully read even for validity check | |||
lappendState always_read_full_file [expr {$command ni [list path paths\ | lappendState always_read_full_file [expr {$command ni [list path paths\ | |||
list avail aliases edit]}] | list avail aliases edit]}] | |||
lappendState commandname $command | lappendState commandname $command | |||
# is evaluation a regular attempt or a try (silence not found error) | ||||
lappendState try_modulefile [expr {$command in {try-load load-any}}] | ||||
# stop evaluation after first successful load | ||||
lappendState any_modulefile [expr {$command eq {load-any}}] | ||||
if {$topcall} { | if {$topcall} { | |||
# Find and execute any global rc file found | # Find and execute any global rc file found | |||
runModulerc | runModulerc | |||
} | } | |||
switch -- $command { | switch -- $command { | |||
load - try-load - load-any { | load - try-load - load-any { | |||
# ignore flag used in collection to track non-user asked state | # ignore flag used in collection to track non-user asked state | |||
set args [replaceFromList $args --notuasked] | set args [replaceFromList $args --notuasked] | |||
# no error raised on empty argument list to cope with | # no error raised on empty argument list to cope with | |||
# initadd command that may expect this behavior | # initadd command that may expect this behavior | |||
if {[llength $args] > 0} { | if {[llength $args] > 0} { | |||
set ret 0 | set ret 0 | |||
# if top command is source, consider module load commands made | # if top command is source, consider module load commands made | |||
# within sourced file evaluation as top load command | # within sourced file evaluation as top load command | |||
if {[isTopEvaluation]} { | if {[isTopEvaluation]} { | |||
set ret [cmdModuleLoad load 1 $tag_list {*}$args] | # is eval a regular attempt or a try (silence not found error) | |||
set tryload [expr {$command in {try-load load-any}}] | ||||
set loadany [expr {$command eq {load-any}}] | ||||
set ret [cmdModuleLoad load 1 $tryload $loadany $tag_list\ | ||||
{*}$args] | ||||
} elseif {$mode eq {load}} { | } elseif {$mode eq {load}} { | |||
# load here if try-load or no auto mode (done through prereq | # auto load is inhibited if currently in DepRe context only | |||
# elsewhere, inhibited if currently in DepRe context) | # register requirement | |||
if {$command eq {try-load} || (![getConf auto_handling] &&\ | set subauto [expr {[currentModuleEvalContext] eq {depre} ? {0}\ | |||
[currentModuleEvalContext] ne {depre})} { | : {1}}] | |||
# load requirement in a OR-operation like done through | if {$command eq {try-load}} { | |||
# prereq cmd when auto_handling is enabled | # attempt load of not already loaded modules | |||
if {$command eq {load-any}} { | if {$subauto} { | |||
loadRequirementModuleList $tag_list {*}$args | ||||
} else { | ||||
# attempt load of not already loaded modules | ||||
foreach arg $args { | foreach arg $args { | |||
lassign [loadRequirementModuleList $tag_list $arg]\ | lassign [loadRequirementModuleList 1 0 $tag_list\ | |||
retlo | $arg] retlo | |||
# update return value if an issue occurred unless | # update return value if an issue occurred unless | |||
# force mode is enabled | # force mode is enabled | |||
if {$retlo != 0 && ![getState force]} { | if {$retlo != 0 && ![getState force]} { | |||
set ret $retlo | set ret $retlo | |||
} | } | |||
} | } | |||
} | } | |||
} | # record requirement as optional: no error if not loaded | |||
# register modulefiles to load as individual prereqs or all at | # but reload will be triggered if loaded later on | |||
# once for load-any sub-command | prereqAllModfileCmd 1 0 --optional --tag [join $tag_list :]\ | |||
if {$command eq {load-any}} { | {*}$args | |||
prereq --tag [join $tag_list :] {*}$args | } elseif {$command eq {load-any}} { | |||
# load and register requirement in a OR-operation | ||||
prereqAnyModfileCmd 1 $subauto --tag [join $tag_list :]\ | ||||
{*}$args | ||||
} else { | } else { | |||
foreach arg $args { | # load and register requirement in a AND-operation | |||
# no prereq record if try-load did not succeed | prereqAllModfileCmd 0 $subauto --tag [join $tag_list :]\ | |||
if {$command ne {try-load} || [is-loaded $arg]} { | {*}$args | |||
prereq --tag [join $tag_list :] $arg | ||||
} | ||||
} | ||||
} | } | |||
# mods unload is handled via UReqUn mechanism when auto enabled | # mods unload is handled via UReqUn mechanism when auto enabled | |||
# (unless if implicit_requirement has been inhibited) also unloads | # (unless if implicit_requirement has been inhibited) also unloads | |||
# are triggered by ongoing reload, purge or restore commands | # are triggered by ongoing reload, purge, restore, reset, stash or | |||
# stashpop cmds | ||||
} elseif {(![getConf auto_handling] || [getState\ | } elseif {(![getConf auto_handling] || [getState\ | |||
inhibit_req_record] eq [currentState evalid]) &&\ | inhibit_req_record] eq [currentState evalid]) &&\ | |||
[aboveCommandName] ni [list purge reload restore]} { | [aboveCommandName] ni [list purge reload restore reset stash\ | |||
stashpop]} { | ||||
# on unload mode, unload mods in reverse order, if loaded | # on unload mode, unload mods in reverse order, if loaded | |||
# prior this mod, if not user asked and not required by | # prior this mod, if not user asked and not required by | |||
# other loaded mods | # other loaded mods | |||
set modlist [getLoadedModuleList] | set modlist [getLoadedModulePropertyList name] | |||
set modidx [lsearch -exact $modlist [currentState modulename]] | set modidx [lsearch -exact $modlist [currentState modulename]] | |||
if {$modidx != 0} { | if {$modidx != 0} { | |||
set priormodlist [lrange $modlist 0 $modidx] | set priormodlist [lrange $modlist 0 $modidx] | |||
foreach arg [lreverse $args] { | foreach arg [lreverse $args] { | |||
if {[set unmod [getLoadedMatchingName $arg {} 0\ | if {[set unmod [getLoadedMatchingName $arg {} 0\ | |||
$priormodlist]] ne {}} { | $priormodlist]] ne {}} { | |||
if {[cmdModuleUnload urequn match 1 0 1 1 $unmod]} { | if {[cmdModuleUnload urequn match 1 0 1 1 $unmod]} { | |||
reportWarning "Unload of useless requirement\ | reportWarning "Unload of useless requirement\ | |||
[getModuleDesignation loaded $unmod] failed" 1 | [getModuleDesignation loaded $unmod] failed" 1 | |||
} | } | |||
skipping to change at line 631 | skipping to change at line 601 | |||
if {$swlomod eq {} && $swunmod ne {}} { | if {$swlomod eq {} && $swunmod ne {}} { | |||
set swlomod $swunmod | set swlomod $swunmod | |||
} | } | |||
# apply same mechanisms than for 'module load' and | # apply same mechanisms than for 'module load' and | |||
# 'module unload' for an unload evaluation: nothing done | # 'module unload' for an unload evaluation: nothing done | |||
# for switched-off module and unload of switched-on | # for switched-off module and unload of switched-on | |||
# module. If auto handling is enabled switched-on module | # module. If auto handling is enabled switched-on module | |||
# is handled via UReqUn mechanism (unless if | # is handled via UReqUn mechanism (unless if | |||
# implicit_requirement has been inhibited). Also unloads are | # implicit_requirement has been inhibited). Also unloads are | |||
# triggered by ongoing reload, purge or restore commands | # triggered by ongoing reload, purge, restore, reset, stash | |||
# or stashpop cmds | ||||
if {(![getConf auto_handling] || [getState\ | if {(![getConf auto_handling] || [getState\ | |||
inhibit_req_record] eq [currentState evalid]) &&\ | inhibit_req_record] eq [currentState evalid]) &&\ | |||
$swlomod ne {} && [aboveCommandName] ni [list purge\ | $swlomod ne {} && [aboveCommandName] ni [list purge\ | |||
reload restore]} { | reload restore reset stash stashpop]} { | |||
# unload mod if it was loaded prior this mod, not user | # unload mod if it was loaded prior this mod, not user | |||
# asked and not required by another loaded module | # asked and not required by another loaded module | |||
set modlist [getLoadedModuleList] | set modlist [getLoadedModulePropertyList name] | |||
set modidx [lsearch -exact $modlist [currentState\ | set modidx [lsearch -exact $modlist [currentState\ | |||
modulename]] | modulename]] | |||
if {$modidx != 0} { | if {$modidx != 0} { | |||
set priormodlist [lrange $modlist 0 $modidx] | set priormodlist [lrange $modlist 0 $modidx] | |||
if {[set unmod [getLoadedMatchingName $swlomod {} 0\ | if {[set unmod [getLoadedMatchingName $swlomod {} 0\ | |||
$priormodlist]] ne {}} { | $priormodlist]] ne {}} { | |||
if {[cmdModuleUnload urequn match 1 0 1 1 $unmod]} { | if {[cmdModuleUnload urequn match 1 0 1 1\ | |||
$unmod]} { | ||||
reportWarning "Unload of useless requirement\ | reportWarning "Unload of useless requirement\ | |||
[getModuleDesignation loaded $unmod] failed"\ | [getModuleDesignation loaded $unmod] failed"\ | |||
1 | 1 | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 704 | skipping to change at line 676 | |||
restore { | restore { | |||
cmdModuleRestore {*}$args | cmdModuleRestore {*}$args | |||
} | } | |||
saverm { | saverm { | |||
cmdModuleSaverm {*}$args | cmdModuleSaverm {*}$args | |||
} | } | |||
saveshow { | saveshow { | |||
cmdModuleSaveshow {*}$args | cmdModuleSaveshow {*}$args | |||
} | } | |||
savelist { | savelist { | |||
cmdModuleSavelist $show_oneperline $show_mtime | cmdModuleSavelist $show_oneperline $show_mtime $search_match {*}$args | |||
} | } | |||
initadd { | initadd { | |||
cmdModuleInit add {*}$args | cmdModuleInit add {*}$args | |||
} | } | |||
initprepend { | initprepend { | |||
cmdModuleInit prepend {*}$args | cmdModuleInit prepend {*}$args | |||
} | } | |||
initswitch { | initswitch { | |||
cmdModuleInit switch {*}$args | cmdModuleInit switch {*}$args | |||
} | } | |||
skipping to change at line 743 | skipping to change at line 715 | |||
} | } | |||
state { | state { | |||
cmdModuleState {*}$args | cmdModuleState {*}$args | |||
} | } | |||
sh-to-mod { | sh-to-mod { | |||
cmdModuleShToMod {*}$args | cmdModuleShToMod {*}$args | |||
} | } | |||
edit { | edit { | |||
cmdModuleEdit {*}$args | cmdModuleEdit {*}$args | |||
} | } | |||
lint { | ||||
cmdModuleLint {*}$args | ||||
} | ||||
mod-to-sh { | ||||
cmdModuleModToSh {*}$args | ||||
} | ||||
reset { | ||||
cmdModuleReset | ||||
} | ||||
stash { | ||||
cmdModuleStash | ||||
} | ||||
stashpop { | ||||
cmdModuleStashpop {*}$args | ||||
} | ||||
stashrm { | ||||
cmdModuleStashrm {*}$args | ||||
} | ||||
stashshow { | ||||
cmdModuleStashshow {*}$args | ||||
} | ||||
stashclear { | ||||
cmdModuleStashclear | ||||
} | ||||
stashlist { | ||||
cmdModuleStashlist $show_oneperline $show_mtime | ||||
} | ||||
help { | help { | |||
cmdModuleHelp {*}$args | cmdModuleHelp {*}$args | |||
} | } | |||
test { | test { | |||
cmdModuleTest {*}$args | cmdModuleTest {*}$args | |||
} | } | |||
prepend-path - append-path - remove-path - is-loaded - is-saved -\ | prepend-path - append-path - remove-path - is-loaded - is-saved -\ | |||
is-used - is-avail { | is-used - is-avail { | |||
cmdModuleResurface $command {*}$args | cmdModuleResurface $command {*}$args | |||
} | } | |||
info-loaded { | info-loaded { | |||
cmdModuleResurface module-info loaded {*}$args | cmdModuleResurface module-info loaded {*}$args | |||
} | } | |||
} | } | |||
lpopState any_modulefile | ||||
lpopState try_modulefile | ||||
lpopState commandname | lpopState commandname | |||
lpopState always_read_full_file | lpopState always_read_full_file | |||
if {!$topcall && ($not_req || ![getConf implicit_requirement])} { | if {!$topcall && ($not_req || ![getConf implicit_requirement])} { | |||
lpopState inhibit_req_record | lpopState inhibit_req_record | |||
} | } | |||
# if called from top level render settings if any | # if called from top level render settings if any | |||
if {$topcall} { | if {$topcall} { | |||
renderSettings | renderSettings | |||
skipping to change at line 816 | skipping to change at line 813 | |||
# like '-' or '--', but we need here to replay module-specific argument | # like '-' or '--', but we need here to replay module-specific argument | |||
# parsing to raise error if some arg are not allowed on unload/load cmd | # parsing to raise error if some arg are not allowed on unload/load cmd | |||
set mlcmd [expr {[llength $modunlist] > 0 ? {unload} : {load}}] | set mlcmd [expr {[llength $modunlist] > 0 ? {unload} : {load}}] | |||
lassign [parseModuleCommandArgs 1 $mlcmd 0 {*}$args] show_oneperline\ | lassign [parseModuleCommandArgs 1 $mlcmd 0 {*}$args] show_oneperline\ | |||
show_mtime show_filter search_filter search_match dump_state\ | show_mtime show_filter search_filter search_match dump_state\ | |||
addpath_pos not_req tag_list fargs | addpath_pos not_req tag_list fargs | |||
# define if modfile should always be fully read even for validity check | # define if modfile should always be fully read even for validity check | |||
lappendState always_read_full_file 1 | lappendState always_read_full_file 1 | |||
lappendState commandname ml | lappendState commandname ml | |||
# initialize try and any load states: as the load/unload shortcut is | ||||
# analyzed in this branch, no try-load/load-any command can occur | ||||
lappendState try_modulefile 0 | ||||
lappendState any_modulefile 0 | ||||
# Find and execute any global rc file found | # Find and execute any global rc file found | |||
runModulerc | runModulerc | |||
set ret 0 | set ret 0 | |||
pushSettings | pushSettings | |||
# first unload specified modules | # first unload specified modules | |||
if {[llength $modunlist] > 0} { | if {[llength $modunlist] > 0} { | |||
set ret [cmdModuleUnload unload match 1 0 0 0 {*}$modunlist] | set ret [cmdModuleUnload unload match 1 0 0 0 {*}$modunlist] | |||
} | } | |||
# then load other modules unless unload phase failed | # then load other modules unless unload phase failed | |||
if {!$ret && [llength $modlolist] > 0} { | if {!$ret && [llength $modlolist] > 0} { | |||
set ret [cmdModuleLoad load 1 $tag_list {*}$modlolist] | set ret [cmdModuleLoad load 1 0 0 $tag_list {*}$modlolist] | |||
} | } | |||
# rollback changes if any load or unload failed | # rollback changes if any load or unload failed | |||
if {$ret} { | if {$ret} { | |||
restoreSettings | restoreSettings | |||
} | } | |||
popSettings | popSettings | |||
lpopState any_modulefile | ||||
lpopState try_modulefile | ||||
lpopState commandname | lpopState commandname | |||
lpopState always_read_full_file | lpopState always_read_full_file | |||
renderSettings | renderSettings | |||
} | } | |||
return {} | return {} | |||
} | } | |||
# | # | |||
skipping to change at line 869 | skipping to change at line 860 | |||
fconfigure stderr -translation auto | fconfigure stderr -translation auto | |||
if {[catch { | if {[catch { | |||
# parse all command-line arguments before doing any action, no output is | # parse all command-line arguments before doing any action, no output is | |||
# made during argument parse to wait for potential paging to be setup | # made during argument parse to wait for potential paging to be setup | |||
set show_help 0 | set show_help 0 | |||
set show_version 0 | set show_version 0 | |||
setState cmdline "$argv0 $argv" | setState cmdline "$argv0 $argv" | |||
# Load extension library if enabled | # Load extension library if enabled | |||
##nagelfar ignore +2 Too long line | ||||
@libtclenvmodules@if {[file readable [getConf tcl_ext_lib]]} { | @libtclenvmodules@if {[file readable [getConf tcl_ext_lib]]} { | |||
@libtclenvmodules@ reportDebug "Load Tcl extension library ([getConf tcl_ex t_lib])" | @libtclenvmodules@ reportDebug "Load Tcl extension library ([getConf tcl_ex t_lib])" | |||
@libtclenvmodules@ load [file normalize [getConf tcl_ext_lib]] Envmodules | @libtclenvmodules@ load [file normalize [getConf tcl_ext_lib]] Envmodules | |||
@libtclenvmodules@ setState tcl_ext_lib_loaded 1 | @libtclenvmodules@ setState tcl_ext_lib_loaded 1 | |||
@libtclenvmodules@} | @libtclenvmodules@} | |||
# use fallback procs if extension library is not loaded | # use fallback procs if extension library is not loaded | |||
if {[info commands readFile] eq {}} { | if {[info commands readFile] eq {}} { | |||
rename ::__readFile ::readFile | rename ::__readFile ::readFile | |||
rename ::__getFilesInDirectory ::getFilesInDirectory | rename ::__getFilesInDirectory ::getFilesInDirectory | |||
rename ::__initStateUsergroups ::initStateUsergroups | rename ::__initStateUsergroups ::initStateUsergroups | |||
rename ::__initStateUsername ::initStateUsername | rename ::__initStateUsername ::initStateUsername | |||
rename ::__initStateClockSeconds ::initStateClockSeconds | rename ::__initStateClockSeconds ::initStateClockSeconds | |||
rename ::__parseDateTimeArg ::parseDateTimeArg | rename ::__parseDateTimeArg ::parseDateTimeArg | |||
} | } | |||
##nagelfar syntax readFile x x? x? | ||||
##nagelfar syntax getFilesInDirectory x x | ||||
##nagelfar syntax initStateUsergroups | ||||
##nagelfar syntax initStateUsername | ||||
##nagelfar syntax initStateClockSeconds | ||||
##nagelfar syntax parseDateTimeArg x x | ||||
# source site configuration script if any | # source site configuration script if any | |||
sourceSiteConfig | sourceSiteConfig | |||
setState supported_shells {sh bash ksh zsh csh tcsh fish cmd tcl perl\ | setState supported_shells {sh bash ksh zsh csh tcsh fish cmd tcl perl\ | |||
python ruby lisp cmake r} | python ruby lisp cmake r} | |||
# Parse shell | # Parse shell | |||
setState shell [lindex $argv 0] | setState shell [lindex $argv 0] | |||
if {[getState shell] ni [getState supported_shells]} { | if {[getState shell] ni [getState supported_shells]} { | |||
reportErrorAndExit "Unknown shell type \'([getState shell])\'" | reportErrorAndExit "Unknown shell type \'([getState shell])\'" | |||
} | } | |||
switch -- [getState shell] { | ||||
sh - bash - ksh - zsh { | ||||
setState shelltype sh | ||||
} | ||||
csh - tcsh { | ||||
setState shelltype csh | ||||
} | ||||
default { | ||||
setState shelltype [getState shell] | ||||
} | ||||
} | ||||
# extract options and command switches from other args | # extract options and command switches from other args | |||
set otherargv {} | set otherargv {} | |||
set extraargv {} | set extraargv {} | |||
set ddelimarg 0 | set ddelimarg 0 | |||
# split first arg if multi-word string detected for compat with previous | # split first arg if multi-word string detected for compat with previous | |||
# doc on module usage with scripting language: module('load mod1 mod2') | # doc on module usage with scripting language: module('load mod1 mod2') | |||
##nagelfar ignore #2 Badly formed if statement | ||||
set argtoparse [if {[llength [lindex $argv 1]] > 1} {list {*}[split\ | set argtoparse [if {[llength [lindex $argv 1]] > 1} {list {*}[split\ | |||
[lindex $argv 1]] {*}[lrange $argv 2 end]} {lrange $argv 1 end}] | [lindex $argv 1]] {*}[lrange $argv 2 end]} {lrange $argv 1 end}] | |||
foreach arg $argtoparse { | foreach arg $argtoparse { | |||
if {[info exists ignore_next_arg]} { | if {[info exists ignore_next_arg]} { | |||
unset ignore_next_arg | unset ignore_next_arg | |||
} elseif {[info exists nextargisextraargv]} { | } elseif {[info exists nextargisextraargv]} { | |||
lappend extraargv $arg | lappend extraargv $arg | |||
unset nextargisextraargv | unset nextargisextraargv | |||
} elseif {[info exists nextargisval]} { | } elseif {[info exists nextargisval]} { | |||
##nagelfar vartype nextargisval varName | ||||
set $nextargisval $arg | set $nextargisval $arg | |||
unset nextargisval | unset nextargisval | |||
} else { | } else { | |||
switch -glob -- $arg { | switch -glob -- $arg { | |||
-T - --trace { | -T - --trace { | |||
set asked_verbosity trace | set asked_verbosity trace | |||
} | } | |||
-D - -DD - --debug { | -D - -DD - --debug { | |||
set asked_verbosity [expr {$arg eq {-DD} || ([info exists\ | set asked_verbosity [expr {$arg eq {-DD} || ([info exists\ | |||
asked_verbosity] && $asked_verbosity in {debug debug2}) ?\ | asked_verbosity] && $asked_verbosity in {debug debug2}) ?\ | |||
skipping to change at line 995 | skipping to change at line 984 | |||
set nextargisextraargv 1 | set nextargisextraargv 1 | |||
} | } | |||
--width* { | --width* { | |||
set asked_term_width [string range $arg 8 end] | set asked_term_width [string range $arg 8 end] | |||
set term_width_arg --width | set term_width_arg --width | |||
if {$asked_term_width eq {}} { | if {$asked_term_width eq {}} { | |||
set asked_term_width 0 | set asked_term_width 0 | |||
} | } | |||
} | } | |||
-w { | -w { | |||
##nagelfar ignore Found constant | ||||
set nextargisval asked_term_width | set nextargisval asked_term_width | |||
set term_width_arg -w | set term_width_arg -w | |||
} | } | |||
-t - --terse - -l - --long - --default - -L - --latest - -S -\ | -t - --terse - -l - --long - --default - -L - --latest - -S -\ | |||
--starts-with - -C - --contains - -j - --json - --output=* { | --starts-with - -C - --contains - -j - --json - --output=* { | |||
# command-specific switches that can for compatibility be | # command-specific switches that can for compatibility be | |||
# passed before the command name, so add them to a specific | # passed before the command name, so add them to a specific | |||
# arg list to ensure command name as first position argument | # arg list to ensure command name as first position argument | |||
lappend extraargv $arg | lappend extraargv $arg | |||
} | } | |||
skipping to change at line 1028 | skipping to change at line 1018 | |||
lappend otherargv $arg | lappend otherargv $arg | |||
} | } | |||
append-path - prepend-path - remove-path { | append-path - prepend-path - remove-path { | |||
# detect *-path commands to say -d means --delim, not --default | # detect *-path commands to say -d means --delim, not --default | |||
set ddelimarg 1 | set ddelimarg 1 | |||
lappend otherargv $arg | lappend otherargv $arg | |||
} | } | |||
-i - --icase { | -i - --icase { | |||
set asked_icase always | set asked_icase always | |||
} | } | |||
--timer { | ||||
setState timer 1 | ||||
set timer_start [clock microseconds] | ||||
} | ||||
--human - -c - --create - --userlvl=* { | --human - -c - --create - --userlvl=* { | |||
# ignore C-version specific option, no error only warning | # ignore C-version specific option, no error only warning | |||
reportWarning "Unsupported option '$arg'" | reportWarning "Unsupported option '$arg'" | |||
} | } | |||
-u - --userlvl { | -u - --userlvl { | |||
reportWarning "Unsupported option '$arg'" | reportWarning "Unsupported option '$arg'" | |||
# also ignore argument value | # also ignore argument value | |||
set ignore_next_arg 1 | set ignore_next_arg 1 | |||
} | } | |||
--output { | --output { | |||
skipping to change at line 1062 | skipping to change at line 1056 | |||
set subcmdtest [lindex $otherargv 0] | set subcmdtest [lindex $otherargv 0] | |||
if {$subcmdtest ne {ml}} { | if {$subcmdtest ne {ml}} { | |||
lassign [parseModuleCommandName $subcmdtest {}]\ | lassign [parseModuleCommandName $subcmdtest {}]\ | |||
subcmdtest | subcmdtest | |||
} | } | |||
# accepted if command is ml or if adv vers spec is enabled | # accepted if command is ml or if adv vers spec is enabled | |||
# and command can receive boolean variant specification | # and command can receive boolean variant specification | |||
set accept_minus_arg [expr {$subcmdtest eq {ml} ||\ | set accept_minus_arg [expr {$subcmdtest eq {ml} ||\ | |||
([getConf advanced_version_spec] && $subcmdtest in\ | ([getConf advanced_version_spec] && $subcmdtest in\ | |||
{avail list display help is-avail is-loaded load path\ | {avail list display help is-avail is-loaded load path\ | |||
paths switch test unload whatis})}] | paths switch test unload whatis mod-to-sh source})}] | |||
} | } | |||
# spare argument if minus arg is accepted | # spare argument if minus arg is accepted | |||
if {[info exists accept_minus_arg] && $accept_minus_arg} { | if {[info exists accept_minus_arg] && $accept_minus_arg} { | |||
lappend otherargv $arg | lappend otherargv $arg | |||
} else { | } else { | |||
reportErrorAndExit "Invalid option '$arg'\nTry 'module\ | reportErrorAndExit "Invalid option '$arg'\nTry 'module\ | |||
--help' for more information." | --help' for more information." | |||
} | } | |||
} | } | |||
default { | default { | |||
skipping to change at line 1142 | skipping to change at line 1136 | |||
} | } | |||
} | } | |||
} | } | |||
if {$show_help} { | if {$show_help} { | |||
if {[getState subcmd] eq {ml}} { | if {[getState subcmd] eq {ml}} { | |||
reportMlUsage | reportMlUsage | |||
} else { | } else { | |||
reportUsage | reportUsage | |||
} | } | |||
cleanupAndExit 0 | flushAndExit 0 | |||
} | } | |||
if {$show_version} { | if {$show_version} { | |||
reportVersion | reportVersion | |||
cleanupAndExit 0 | flushAndExit 0 | |||
} | } | |||
# no modulefile is currently being interpreted | # no modulefile is currently being interpreted | |||
lappendState modulefile {} | lappendState modulefile {} | |||
# eval needed to pass otherargv as list to module proc | # eval needed to pass otherargv as list to module proc | |||
{*}$execcmdlist | {*}$execcmdlist | |||
} errMsg ]} { | } errMsg ]} { | |||
# re-enable error report in case it was previously inhibited | # re-enable error report in case it was previously inhibited | |||
setState inhibit_errreport 0 | setState inhibit_errreport 0 | |||
skipping to change at line 1172 | skipping to change at line 1166 | |||
renderFalse | renderFalse | |||
} | } | |||
# report stack trace in addition to the error message if error is unknown | # report stack trace in addition to the error message if error is unknown | |||
if {$errorCode ni [list MODULES_ERR_RENDERED MODULES_ERR_KNOWN]} { | if {$errorCode ni [list MODULES_ERR_RENDERED MODULES_ERR_KNOWN]} { | |||
set errMsg "$errorInfo\n[sgr hi {Please report this issue at\ | set errMsg "$errorInfo\n[sgr hi {Please report this issue at\ | |||
https://github.com/cea-hpc/modules/issues}]" | https://github.com/cea-hpc/modules/issues}]" | |||
} | } | |||
reportError $errMsg | reportError $errMsg | |||
# init error report here in case the error raised before the regular init | # init error report here in case the error raised before the regular init | |||
initErrorReport | initErrorReport | |||
cleanupAndExit 1 | flushAndExit 1 | |||
} | } | |||
cleanupAndExit 0 | flushAndExit 0 | |||
# ;;; Local Variables: *** | # ;;; Local Variables: *** | |||
# ;;; mode:tcl *** | # ;;; mode:tcl *** | |||
# ;;; End: *** | # ;;; End: *** | |||
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: | # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: | |||
End of changes. 47 change blocks. | ||||
123 lines changed or deleted | 117 lines changed or added |