home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
upgrade_menus.tcl
< prev
next >
Wrap
Text File
|
1996-08-27
|
9KB
|
341 lines
OTShRegister::repository
source [m4_path_name tcl libocl.tcl]
require procs.tcl
require messagehdl.tcl
set CC [ClientContext::global]
global diffDict
global adjustedFid
global adjusted
global menuList
set menuList {desk diagram cad ccd dfd etd mgd std ucd}
proc makeTclName {displayName} {
regsub -all "\\\.| |\t" $displayName "" strippedString
return [string tolower $strippedString]
}
proc registerObject {specification} {
set spec $specification
set objSpec ""
set name ""
set type ""
while {![lempty $specification]} {
set key [lvarpop specification]
if {$key == "name"} {
set name [lvarpop specification]
} elseif {$key == "objSpec"} {
set objSpec [lvarpop specification]
} elseif {$key == "type"} {
set type [lvarpop specification]
}
}
# determine right name
set index [lsearch -exact $objSpec "label"]
if {$index != -1} {
incr index
set displayName [lindex $objSpec $index]
set newName [makeTclName $displayName]
} else {
# no label found, take old name
set newName [getName $name]
}
# determine right path
set pathList [path2List [getParent $name]]
set newPath ""
set orgPath ""
foreach pathElm $pathList {
set newPath $newPath.$pathElm
set orgPath $orgPath.$pathElm
set diffPath [$diffDict set $orgPath]
if {$diffPath != ""} {
set newPath $diffPath
}
}
# build new name
set newName $newPath.$newName
if {$name == $newName} {
puts $adjustedFid "registerObject \{$spec\}\n"
return
} else {
$diffDict set $name $newName
}
regsub -all {[]|*+?\().-^$[]} $name {\\&} name
if [catch {set cnt [regsub "$name" "$spec" "$newName" newSpec]} rs] {
puts "Renaming failed for '$name': $rs"
} else {
set spec $newSpec
}
# write the the changes file
puts $adjustedFid "registerObject \{$spec\}\n"
if {$cnt > 0} {
global adjusted
set adjusted 1
}
}
proc loadDiff {diffFile} {
global diffDict
set diffFile [path_name concat [path_name concat \
[m4_var get M4_home] etc] $diffFile ""]
set diffDict [Dictionary new]
if [file exists $diffFile] {
set fid [open $diffFile r]
$diffDict contents [read -nonewline $fid]
close $fid
return ""
} else {
return "'$diffFile' not found."
}
}
proc performUpgrade { custLevelObj } {
set count 0
set reFreeze 0
foreach name $menuList {
set custF [$custLevelObj findCustomFileVersion $name mnu]
if [$custF isNil] {
continue
}
if { [$custF status] == "frozen" } {
if [catch {$custF unfreeze} err] {
puts "Could not unfreeze '[$custF text]' for update"
puts "Error was:"
puts $err
puts "File was not upgraded"
continue
} elseif { $err != "0" } {
puts "Could not unfreeze '[$custF text]' for update"
puts "[unkown reason]"
puts "File was not upgraded"
continue
}
set reFreeze 1
}
if {$name == "desk"} {
set error [loadDiff diffdesk.mnu]
} else {
set error [loadDiff diffdiag.mnu]
}
if {$error != ""} {
puts $error
}
set adjustedFile [args_file {}]
global adjustedFid
set adjustedFid [open $adjustedFile w]
global adjusted
set adjusted 0
set origFile [args_file {}]
$custF downLoad $origFile
sourceFile $origFile
unlink $origFile
close $adjustedFid
if {$adjusted == 1} {
$custF edit
$custF upLoad $adjustedFile
$custF quit
incr count
}
unlink $adjustedFile
if {$reFreeze} {
if [catch {$custF freeze "after upgrade"} err] {
puts "Could not freeze '[$custF text]' after update"
puts "Error was:"
puts $err
} elseif { $err != "0" } {
puts "Could not freeze '[$custF text]' after update"
puts "[unkown reason]
puts "File was not upgraded"
}
}
}
return $count
}
proc path2List { path } {
set list {}
set start [string first "." $path]
if {$start == -1} {
return ""
}
incr start
set path "[string range $path $start end]"
while {$path != ""} {
set end [string first "." $path]
if {$end != -1} {
incr end -1
set list "$list [string range $path 0 $end]"
incr end
incr end
set path "[string range $path $end end]"
} else {
set list "$list $path"
set path ""
}
}
return $list
}
proc upgradeRepMenus {} {
set corp [$CC currentCorporate]
set corpId [$corp identity]
puts "Upgrading menu customization files in the repository '[$corp name]'"
puts ""
foreach proj [$corp projects] {
$CC setLevelIds /$corpId/[$proj identity]
puts "Checking project '[$proj name]'"
set count [performUpgrade $proj]
if {$count > 0} {
puts "$count file(s) adjusted."
}
foreach cv [$proj configVersions] {
puts " Checking config '[[$cv config] name]'"
$CC setLevelIds /$corpId/[$proj identity]/[$cv identity]
set count [performUpgrade $cv]
if {$count > 0} {
puts " $count file(s) adjusted."
}
foreach pv [$cv phaseVersions] {
puts " Checking phase '[[$pv phase ] name]'"
$CC setLevelIds /$corpId/[$proj identity]/[$cv identity]/[$pv \
identity]
set count [performUpgrade $pv]
if {$count > 0} {
puts " $count file(s) adjusted."
}
foreach sv [$pv systemVersions] {
puts " Checking systemVersion '[[$sv system] name]'"
$CC setLevelIds /$corpId/[$proj identity]/[$cv \
identity]/[$pv identity]/[$sv identity]
set count [performUpgrade $sv]
if {$count > 0} {
puts " $count file(s) adjusted."
}
}
}
}
}
puts ""
puts "Upgrading menu customization files finished."
}
proc upgradeUserMenus {} {
set icaseDir [path_name concat ~ icase]
puts "Upgrading menu user customization files"
puts ""
if {![file exists $icaseDir]} {
# no icaseDir == no user cust files
puts "No user menu customization files found."
return
}
set orgDir [pwd]
cd $icaseDir
# save the original user customization files
foreach file $menuList {
if [file exists $icaseDir] {
cd $icaseDir
if [file exists $file.mnu] {
puts "save $file.mnu in ${file}_4000.mnu"
if {![file exists ${file}_4000.mnu]} {
copy_text_file $file.mnu ${file}_4000.mnu
}
}
}
}
# adjust the user customization files
foreach file $menuList {
if {![file exists $file.mnu]} {
continue
}
puts "check file '$file.mnu'"
if {$file == "desk"} {
set error [loadDiff diffdesk.mnu]
} else {
set error [loadDiff diffdiag.mnu]
}
if {$error != ""} {
puts $error
}
set adjustedFile ${file}_4001.mnu
global adjustedFid
set adjustedFid [open $adjustedFile w]
sourceFile $file.mnu
close $adjustedFid
# copy changed file to original
copy_text_file $adjustedFile $file.mnu
unlink $adjustedFile
}
# back to original dir
cd $orgDir
puts ""
puts "Upgrading menu customization files finished."
}
proc getName {path} {
regsub {.*\.} $path "" type
return $type
}
proc sourceFile {file} {
if [catch {
set fid [open $file]
set l [List new -contents [read $fid]]
close $fid
set end [$l length]
for {set i 1} {$i <= $end} {incr i 2} {
registerObject [$l index $i]
}
} rsn] {
wmtkerror $rsn
}
}