rac-gui/rac_gui.tcl
2019-08-23 17:31:13 +03:00

107 lines
3.7 KiB
Tcl
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Tcl ignores the next line -*- tcl -*- \
exec wish "$0" -- "$@"
######################################################
# Rac GUI
# 1C RAC (tm) grafical user interface
# Distributed under GNU Public License
# Author: Sergey Kalinin svk@nuk-svk.ru
# Home page: https://nuk-svk.ru
# Git repos: https://bitbucket.org/svk28/rac-gui
#
# version: 1.1.0
# release: 1
#
######################################################
package require msgcat
package require json
package require json::write
# Устанавливаем текущий каталог
set dir(root) [pwd]
# Устанавливаем рабочий каталог, если его нет то создаём
set dir(work) [file join $env(HOME) .rac_gui]
if {[file exists $dir(work)] == 0 } {
file mkdir $dir(work)
}
# каталог с модулями
set dir(lib) "[file join $dir(root) lib]"
# загружаем пользовательский конфиг, если он отсутствует, то копируем дефолтный
if {[file exists [file join $dir(work) rac_gui.cfg]] ==0} {
file copy [file join [pwd] rac_gui.cfg] [file join $dir(work) rac_gui.cfg]
}
source [file join $dir(work) rac_gui.cfg]
::msgcat::mclocale $default(locale)
::msgcat::mcload [file join $dir(lib) msg]
# Код проверки наличия rac и правильности указания пути в конфиге
# если программа не найдена то будет выведен диалог для указанием корректного пути
# и этот путь будет записан в пользовательский конфиг
if {[file exists $rac_cmd] == 0} {
set rac_cmd "[tk_getOpenFile -initialdir $env(HOME) -parent . \
-title [::msgcat::mc "Show where is a RAC command"] -initialfile rac]"
if {$rac_cmd eq ""} {exit}
file copy [file join $dir(work) rac_gui.cfg] [file join $dir(work) rac_gui.cfg.bak]
set orig_file [open [file join $dir(work) rac_gui.cfg.bak] "r"]
set file [open [file join $dir(work) rac_gui.cfg] "w"]
while {[gets $orig_file line] >=0 } {
if {[string match "set rac_cmd*" $line]} {
puts $file "set rac_cmd \"$rac_cmd\""
} else {
puts $file $line
}
}
#puts $rac_cmd
close $file
close $orig_file
#return "$host:$port"
file delete [file join $dir(work) rac_gui.cfg.bak]
if {$tcl_platform(platform) == "windows"} {
tk_messageBox -message "[::msgcat::mc "Reexecute the programm"]!" \
-icon info -type ok
exit
}
} else {
puts "Found $rac_cmd"
}
set cluster_user ""
set cluster_pwd ""
set agent_user ""
set agent_pwd ""
## LOAD FILE ##
# Загружаем модули кроме gui.tcl так как его надо загрузить последним
foreach modFile [lsort [glob -nocomplain [file join $dir(lib) *.tcl]]] {
if {[file tail $modFile] ne "gui.tcl"} {
source $modFile
puts "Loaded module $modFile"
}
}
source [file join $dir(lib) gui.tcl]
source [file join $dir(work) rac_gui.cfg]
# Читаем файл со списком серверов 1С
#set serversList [dict create servers]
if [file exists [file join $dir(work) 1c_srv.cfg]] {
set f [open [file join $dir(work) 1c_srv.cfg] "RDONLY"]
while {[gets $f line] >=0} {
set l [split $line ","]
set host [lindex $l 0]
if {[lindex $l 1] ne ""} {
set rac_cmd_for_host($host) [lindex $l 1]
}
.frm_tree.tree insert {} end -id "server::$host" -text "$host" -values "$host"
# готовим конфиг
dict set servers_list $host clusters {}
}
}
CreateInfoBasesJSONfile $servers_list