Вынесены функции работы сконфигом в отдельный файл.

This commit is contained in:
Sergey Kalinin 2019-08-26 17:30:34 +03:00
parent 216f54874b
commit b0709d9d95
4 changed files with 128 additions and 73 deletions

47
1c_srv_new.cfg Normal file
View File

@ -0,0 +1,47 @@
localhost:1545 {
name "Локальный сервер"
rac_cmd /opt/1C/v8.3/x86_64/rac
agent_user ""
agent_pwd ""
clusters {
3ed9081a-c5b0-11e9-cf8a-1c1b0d94027e {
cluster_name "eeee"
cluster_user ""
cluster_pwd ""
}
4581a966-a6bf-11e9-3c95-1c1b0d94027e {
cluster_name "Локальный кластер"
cluster_user ""
cluster_pwd ""
infobases {
1e1d1cea-b856-11e9-748a-1c1b0d94027e {
infobase_name "wewe"
infobase_user "ibuser"
infobase_pwd "ibpwd"
}
0129b2b2-b8d6-11e9-748a-1c1b0d94027e {
infobase_name "testdb"
infobase_user "testdb2-user"
infobase_pwd "testdb2-pwd"
}
cac80302-b855-11e9-748a-1c1b0d94027e {
infobase_name "testdb"
}
}
}
}
}
192.168.5.145:1545 {
name "1C test"
path_to_rac /opt/1C/v8.3/x86_64/rac
clusters {
}
}
1csrv:1545 {
name "1C SRV"
path_to_rac /opt/1C/v8.3.13_1644/x86_64/rac
clusters {
}
}

54
lib/config.tcl Normal file
View File

@ -0,0 +1,54 @@
#############################################
# Rac GUI
# Distributed under GNU Public License
# Author: Sergey Kalinin svk@nuk-svk.ru
# Copyright (c) "http://nuk-svk.ru", 2018
# https://bitbucket.org/svk28/rac-gui
#############################################
# Config file and dictionary working functions
# global dict - $servers_list
##############################################
# Получаем юзера и пароль из конфига
proc GetInfobaseUser {host cluster infobase} {
global servers_list
if [dict exists $servers_list servers $host clusters $cluster infobases $infobase infobase_user] {
return [dict get $servers_list servers $host clusters $cluster infobases $infobase infobase_user]
}
}
proc GetInfobasePassword {host cluster infobase} {
global servers_list
if [dict exists $servers_list servers $host clusters $cluster infobases $infobase infobase_pwd] {
return [dict get $servers_list servers $host clusters $cluster infobases $infobase infobase_pwd]
}
}
# Конвертация словаря в удобочитаемый формат
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]
}
append result $indent$str\n
if {[regexp {\{} $str]} {
append indent " "
}
return $result
}
# Сохраянем конфиг
proc SaveConfig {} {
global dir servers_list
set file [open [file join $dir(work) 1c_srv_new.cfg] "w"]
puts $file [dict2file [dict get $servers_list servers]]
close $file
}

View File

@ -7,7 +7,8 @@
########################################### ###########################################
proc Quit {} { proc Quit {} {
global servers_list # Сохраняем конфиг
SaveConfig
exit exit
} }
@ -31,7 +32,7 @@ proc TreePress {tree} {
} }
proc SetGlobalVarFromTreeItems {tree id} { proc SetGlobalVarFromTreeItems {tree id} {
global host server active_cluster infobase profile_name dir rac_cmd_for_host rac_cmd servers_list global host server active_cluster infobase profile_name dir rac_cmd_for_host rac_cmd
set parent [$tree parent $id] set parent [$tree parent $id]
set values [$tree item $id -values] set values [$tree item $id -values]
set key [lindex [split $id "::"] 0] set key [lindex [split $id "::"] 0]
@ -310,39 +311,6 @@ proc SaveMainServer {host port path_to_rac} {
return "$host:$port" return "$host:$port"
} }
proc SaveConfig {} {
global host server active_cluster infobase profile_name dir rac_cmd_for_host rac_cmd servers_list
set file [open [file join $dir(work) 1c_srv_new.cfg] "a+"]
puts "$host:$port $rac_cmd"
puts $file "$host:$port,$rac_cmd"
close $file
return "$host:$port"
}
set servers_list {
server_id {
command rac_cmd
cluster_id {
cluster_name ""
infobase-id1 {
infobase_name ""
infobase_user ""
infobase_pwd ""
}
infobase-id2 {
infobase_name ""
infobase_user ""
infobase_pwd ""
}
}
}
}
proc GetWorkTreeItems {par} { proc GetWorkTreeItems {par} {
set work_tree_id [.frm_work.tree_work selection] set work_tree_id [.frm_work.tree_work selection]
set work_tree_values [.frm_work.tree_work item $work_tree_id -values] set work_tree_values [.frm_work.tree_work item $work_tree_id -values]
@ -382,35 +350,6 @@ proc GetWorkTreeRow {} {
return $lst return $lst
} }
proc CreateInfoBasesJSONfile {serversList} {
global default dir
puts $serversList
puts [tcl2json $serversList]
set info_base_json_file [file join $dir(work) infobases.lst]
set jsonStr {
{
"servers":[
{ "server-id": "server_id1",
"clusters": [
{"cluster-id": "cluster_id_1", "infobases": [
{"infobase-uid": "infobase_uid_1", "infobase-user":"infobase_user", "infobase-pwd":"infobase_pwd"},
{"infobase-uid": "infobase_uid_2", "infobase-user":"infobase_user", "infobase-pwd":"infobase_pwd"}]
}
]
},
{ "server-id": "server_id2",
"clusters": [
{"cluster-id": "cluster_id_1", "infobases": [
{"infobase-uid": "infobase_uid_1", "infobase-user":"infobase_user", "infobase-pwd":"infobase_pwd"},
{"infobase-uid": "infobase_uid_2", "infobase-user":"infobase_user", "infobase-pwd":"infobase_pwd"}]
}
]}
]}
}
}
namespace eval Run {} {} namespace eval Run {} {}
# Получение данных по кластерам # Получение данных по кластерам
@ -468,7 +407,7 @@ proc Run::services {tree host values} {
} }
proc Run::infobases {tree host values} { proc Run::infobases {tree host values} {
global active_cluster cluster_user cluster_pwd global active_cluster cluster_user cluster_pwd
.frm_work.tree_work delete [ .frm_work.tree_work children {}] .frm_work.tree_work delete [ .frm_work.tree_work children {}]
if {$cluster_user ne "" && $cluster_pwd ne ""} { if {$cluster_user ne "" && $cluster_pwd ne ""} {
set auth "--cluster-user=$cluster_user --cluster-pwd=$cluster_pwd" set auth "--cluster-user=$cluster_user --cluster-pwd=$cluster_pwd"
@ -501,15 +440,18 @@ proc Run::infobases {tree host values} {
} }
proc Run::infobase {tree host values} { proc Run::infobase {tree host values} {
global active_cluster cluster_user cluster_pwd default global active_cluster cluster_user cluster_pwd default servers_list
if {$cluster_user ne "" && $cluster_pwd ne ""} { if {$cluster_user ne "" && $cluster_pwd ne ""} {
set auth "--cluster-user=$cluster_user --cluster-pwd=$cluster_pwd" set auth "--cluster-user=$cluster_user --cluster-pwd=$cluster_pwd"
} else { } else {
set auth "" set auth ""
} }
#### Временный костыль #### #### Проверяем наличие юзера и пароля в конфиге и если есть то используем ####
if {[info exists default(infobase_user)] == 1 && [info exists default(infobase_pwd)] == 1} { set infobase_user [GetInfobaseUser $host $active_cluster $values]
set ib_auth "--infobase-user=$default(infobase_user) --infobase-pwd=$default(infobase_pwd)" set infobase_pwd [GetInfobasePassword $host $active_cluster $values]
if {$infobase_user ne "" && $infobase_pwd ne ""} {
set ib_auth "--infobase-user=$infobase_user --infobase-pwd=$infobase_pwd"
} else { } else {
set ib_auth "" set ib_auth ""
} }
@ -529,7 +471,6 @@ proc Run::List:Base {tree host values par} {
} else { } else {
set auth "" set auth ""
} }
.frm_work.tree_work delete [ .frm_work.tree_work children {}] .frm_work.tree_work delete [ .frm_work.tree_work children {}]
set lst [RunCommand "$par list --cluster=$active_cluster $auth --infobase=$values $host"] set lst [RunCommand "$par list --cluster=$active_cluster $auth --infobase=$values $host"]
@ -2511,3 +2452,5 @@ proc Del::inet {tree host profile_name} {

View File

@ -95,7 +95,18 @@ if [file exists [file join $dir(work) 1c_srv.cfg]] {
set rac_cmd_for_host($host) [lindex $l 1] set rac_cmd_for_host($host) [lindex $l 1]
} }
.frm_tree.tree insert {} end -id "server::$host" -text "$host" -values "$host" .frm_tree.tree insert {} end -id "server::$host" -text "$host" -values "$host"
# готовим конфиг }
dict set servers_list $host clusters {} close $f
}
} }
if [file exists [file join $dir(work) 1c_srv_new.cfg]] {
set f_new [open [file join $dir(work) 1c_srv_new.cfg] "RDONLY"]
while {[gets $f_new line] >=0} {
append str " [string trim $line]"
}
set str [string map {"\{ " "\{" " \}" "\}"} $str]
close $f
dict set servers_list servers $str
puts $servers_list
}