From f638f9e8954ea2805df4988ff81862ed2d71b8d5 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Fri, 12 Aug 2022 14:48:24 +0200 Subject: [PATCH] Core code for cmdModuleReset Implement reset sub-command as a 'module restore __init__'. Where __init__ designates the virtual init collection made of the initial environment state described in __MODULES_LMINIT. readCollectionContent has been split to create parseCollectionContent procedure which analyzes collection content passed as argument. When __init__ collection is designated, cmdModuleRestore do not check collection files but parseCollectionContent based on value fetched from __MODULES_LMINIT environment variable. --- .aspell.en.pws | 5 ++++- tcl/coll.tcl.in | 16 ++++++++++------ tcl/modfind.tcl.in | 4 ++-- tcl/subcmd.tcl.in | 22 +++++++++++++++------- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.aspell.en.pws b/.aspell.en.pws index 2fc03ef4..dcd5f656 100644 --- a/.aspell.en.pws +++ b/.aspell.en.pws @@ -1,4 +1,4 @@ -personal_ws-1.1 en 829 +personal_ws-1.1 en 832 ABBRVLIST ActiveTcl Adrien @@ -284,6 +284,7 @@ cmdModuleLoad cmdModulePath cmdModulePaths cmdModuleReset +cmdModuleRestore cmdModuleSearch cmdModuleSwitch cmdModuleTest @@ -594,6 +595,7 @@ othertag oxymoronic packagename parsable +parseCollectionContent parseDateTimeArg parseModuleCommandName pathDefault @@ -629,6 +631,7 @@ rcexpandparam rcfile rcp reStructuredText +readCollectionContent readModuleContent readlink repo diff --git a/tcl/coll.tcl.in b/tcl/coll.tcl.in index b3d7bbd5..70cf9d45 100644 --- a/tcl/coll.tcl.in +++ b/tcl/coll.tcl.in @@ -231,12 +231,6 @@ proc formatCollectionContent {path_list mod_list tag_arrser header {sgr 0}} { # read given collection file and return the path and module lists it defines proc readCollectionContent {collfile colldesc} { - # init lists (maybe coll does not set mod to load) - set path_list {} - set mod_list {} - set nuasked_list {} - array set tag_arr {} - # read file if {[catch { set fdata [split [readFile $collfile] \n] @@ -244,6 +238,16 @@ proc readCollectionContent {collfile colldesc} { reportErrorAndExit "Collection $colldesc cannot be read.\n$errMsg" } + return [parseCollectionContent $fdata] +} + +proc parseCollectionContent {fdata} { + # init lists (maybe coll does not set mod to load) + set path_list {} + set mod_list {} + set nuasked_list {} + array set tag_arr {} + # analyze collection content foreach fline $fdata { if {[regexp {module use (.*)$} $fline match patharg] == 1} { diff --git a/tcl/modfind.tcl.in b/tcl/modfind.tcl.in index 526293a0..5a08abff 100644 --- a/tcl/modfind.tcl.in +++ b/tcl/modfind.tcl.in @@ -434,14 +434,14 @@ proc getLoadedModulePropertyList {prop {filter_empty 1}} { } default { set envvar __MODULES_LM[string toupper $prop] - set subsplit 1 + set subsplit [expr {$prop ni {init}}] if {$prop in {altname conflict}} { set nosubsubsplit 1 } } } switch -- $prop { - conflict - prereq { + conflict - prereq - init { set unserialize_map {< :} } sourcesh { diff --git a/tcl/subcmd.tcl.in b/tcl/subcmd.tcl.in index facee308..4d9c3fcf 100644 --- a/tcl/subcmd.tcl.in +++ b/tcl/subcmd.tcl.in @@ -566,12 +566,17 @@ proc cmdModuleSave {{coll default}} { } proc cmdModuleRestore {{coll default}} { - # get corresponding collection, raise error if it does not exist - lassign [findCollections $coll exact 1] collfile colldesc + # read specific __init__ collection from __MODULES_LMINIT env var + if {$coll eq {__init__}} { + lassign [parseCollectionContent [getLoadedModulePropertyList init]]\ + coll_path_list coll_mod_list coll_tag_arrser + } else { + # get corresponding collection, raise error if it does not exist + lassign [findCollections $coll exact 1] collfile colldesc - # read collection - lassign [readCollectionContent $collfile $colldesc] coll_path_list\ - coll_mod_list coll_tag_arrser + lassign [readCollectionContent $collfile $colldesc] coll_path_list\ + coll_mod_list coll_tag_arrser + } # build list of module tagged auto-loaded in collection array set coll_tag_arr $coll_tag_arrser @@ -582,8 +587,10 @@ proc cmdModuleRestore {{coll default}} { } } - # collection should at least define a path or a mod - if {[llength $coll_path_list] == 0 && [llength $coll_mod_list] == 0} { + # collection should at least define a path or a mod, but initial env may be + # totally empty + if {$coll ne {__init__} && [llength $coll_path_list] == 0 && [llength\ + $coll_mod_list] == 0} { reportErrorAndExit "$colldesc is not a valid collection" } @@ -2714,6 +2721,7 @@ proc cmdModuleModToSh {shell args} { } proc cmdModuleReset {} { + cmdModuleRestore __init__ } # ;;; Local Variables: ***