Добавлена работа сновым конфиг файлом
This commit is contained in:
parent
b3e890ed14
commit
6fc029c32e
113
lib/config.tcl
113
lib/config.tcl
|
@ -25,30 +25,115 @@ proc GetInfobasePassword {host cluster infobase} {
|
|||
|
||||
|
||||
# Конвертация словаря в удобочитаемый формат
|
||||
proc dict2file {dictionary} {
|
||||
#regexp -nocase -indices -all -- {\{} $dictionary list
|
||||
#set str [string map {"\{" "\{\r\n" "\}" "\r\n\}\r\n"} $dictionary]
|
||||
set str $dictionary
|
||||
# Pretty indenting...
|
||||
set indent ""
|
||||
if {[regexp {\}} $str]} {
|
||||
set indent [string range $indent 0 end-4]
|
||||
|
||||
proc DictFormatter {dict {indent}} {
|
||||
set str ""
|
||||
set i 0
|
||||
foreach {k v} $dict {
|
||||
#if {$v eq ""} {set v "NULL"}
|
||||
#puts "\nkey - $k value - [string trim $v]"
|
||||
|
||||
if [regexp {\{} $v] {
|
||||
append indent "-"
|
||||
DictFormatter $v $indent
|
||||
} elseif [regexp {\}} $v] {
|
||||
set indent [string trimright $indent "-"]
|
||||
DictFormatter $v $indent
|
||||
} else {
|
||||
set str "$k $v"
|
||||
}
|
||||
append result $indent$str\n
|
||||
if {[regexp {\{} $str]} {
|
||||
append indent " "
|
||||
}
|
||||
puts "$indent$str"
|
||||
}
|
||||
proc dict2json {dictionary} {
|
||||
dict for {key value} $dictionary {
|
||||
puts "$key $value"
|
||||
if {[string match {\{*\}} $value]} {
|
||||
lappend Result "\"$key\":$value"
|
||||
} elseif {![catch {dict size $value}]} {
|
||||
lappend Result "\"$key\":\"[dict2json $value]\""
|
||||
} else {
|
||||
lappend Result "\"$key\":\"$value\""
|
||||
}
|
||||
puts $Result
|
||||
}
|
||||
return "\{[join $Result ",\n"]\}"
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
# Сохраянем конфиг
|
||||
proc SaveConfig {} {
|
||||
global dir servers_list
|
||||
set file [open [file join $dir(work) 1c_srv_new.cfg] "w"]
|
||||
set f [open [file join $dir(work) 1c_srv_new_.cfg] "w"]
|
||||
set dict [dict get $servers_list servers]
|
||||
#puts "\n\n[split $dict " "]\n\n"
|
||||
set dict [string map {"\{" "\{\n" "\}" "\n\}"} $dict]
|
||||
regsub -- {(\} )} $dict "\}\n" dict
|
||||
|
||||
puts $file [dict2file [dict get $servers_list servers]]
|
||||
#puts $dict
|
||||
#DictFormatter [dict get $servers_list servers] "-"
|
||||
#DictFormatter $dict "-"
|
||||
#regexp -all -indices -line -- {\}(.+?)\{} $dict m
|
||||
#puts " \n $m"
|
||||
puts $file $dict
|
||||
close $file
|
||||
#return
|
||||
set file [open [file join $dir(work) 1c_srv_new.cfg] "r"]
|
||||
|
||||
set str ""
|
||||
seek $file 0
|
||||
set close_brace 0
|
||||
set open_brace 0
|
||||
while {[gets $file line] >=0} {
|
||||
if [regexp -- {\{} $line] {
|
||||
if {$open_brace == 0} {
|
||||
append indent ""
|
||||
} else {
|
||||
append indent " "
|
||||
}
|
||||
incr open_brace
|
||||
}
|
||||
if [regexp -- {\}} $line] {
|
||||
#incr open_brace -1
|
||||
set indent [string range $indent 0 end-2]
|
||||
incr close_brace
|
||||
}
|
||||
if [regexp -nocase -all -- {(\})(.+?\{)} $line match brace phrase] {
|
||||
# puts "> $v1 >>$v2"
|
||||
#append indent " "
|
||||
set line "$brace\n$indent$phrase"
|
||||
#set line [string map {"\}" "\}\n"} $line]
|
||||
#regsub -- {\} } $line "\}\n$indent" line
|
||||
}
|
||||
if {$open_brace > $close_brace} {
|
||||
#set line "$indent$line"
|
||||
}
|
||||
if [regexp -nocase -indices -all -- {((.*?)\s(".*?"))} $line match v1 v2 v3] {
|
||||
puts "> $v1 >>$v2 >>> $v3"
|
||||
set index [lindex [split $v3 " "] 1]
|
||||
puts $index
|
||||
set last_pair [string trim [string range $line $index+1 end]]
|
||||
set line [GetDictFromString $line $indent]
|
||||
puts ">$last_pair<"
|
||||
if {$last_pair ne ""} {
|
||||
append line "$indent[string trim $last_pair]"
|
||||
}
|
||||
}
|
||||
append str $indent [string trim $line] "\n"
|
||||
}
|
||||
puts $f $str
|
||||
}
|
||||
|
||||
proc GetDictFromString {str indent} {
|
||||
puts $str
|
||||
if [regexp -nocase -indices -- {((.*?)\s(".*?"))} $str match v1 v2 v3] {
|
||||
set index [lindex [split $v3 " "] 1]
|
||||
set first_pair [string range $str 0 $index]
|
||||
append res $indent $first_pair "\n"
|
||||
append res [GetDictFromString [string range $str $index+1 end] $indent] "\n"
|
||||
#append res [string range $str $index+1 end] "\n"
|
||||
return $res
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,3 +110,4 @@ if [file exists [file join $dir(work) 1c_srv_new.cfg]] {
|
|||
puts $servers_list
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user