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.
This commit is contained in:
Xavier Delaruelle
2022-08-12 14:48:24 +02:00
parent 085f874277
commit f638f9e895
4 changed files with 31 additions and 16 deletions

View File

@@ -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

View File

@@ -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} {

View File

@@ -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 {

View File

@@ -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: ***