📄 tclu.tcl
字号:
# Get 3rd word of line set HOSTWORD [lindex $HOSTLINE 2] # Get 6 digits (every 2 are separated by dot) set HOSTID [string range $HOSTWORD 9 10] append HOSTID [string range $HOSTWORD 12 13] append HOSTID [string range $HOSTWORD 15 16] set HOSTID [string toupper $HOSTID] } hp10 { if { [catch {exec /etc/lanscan | grep 0x} HOSTLINE] } { tku_popup_message error ok \ "/etc/lanscan | grep 0x :\n$HOSTLINE" return "" } # Get 2nd word of line set HOSTWORD [lindex $HOSTLINE 1] # Get 6 digits set HOSTID [string toupper [string range $HOSTWORD 8 13]] } nt { set EXEC [file join $TCLU_G(TOOLS) nodeid] if { [catch {exec $EXEC } HOSTLINE] } { tku_popup_message error ok \ "$EXEC :\n$HOSTLINE" return "" } set HOSTID [string toupper [lindex $HOSTLINE 3]] } solaris { if { [catch {exec /usr/ucb/hostid} HOSTLINE] } { tku_popup_message error ok \ "/usr/ucb/hostid :\n$HOSTLINE" return "" } # Get 1st word of line set HOSTWORD $HOSTLINE # Get 6 digits set HOSTID [string toupper [string range $HOSTWORD 2 7]] } linux { set HOSTID "XXXXXX" } default { set HOSTID "" } } return $HOSTID }#*******************************************************## Name : tclu_get_dongle## Description : # Returns the 16 digits dongle id of the system, by reading the# information from the dongle.## Input : TOOLS - Path of proper TOOLS directory where dongle_info# can be found# Output : None# Return Value: 16 digit dongle id xxxx-xxxx-xxxx-xxxx#*******************************************************#proc tclu_get_dongle {} { global TCLU_G set DONGLE_ID "" set DONGLE_INFO [file join $TCLU_G(TOOLS) dongle_info.exe] set TMP_PATH [tclu_get_tmp_name vpi_dongle] set TITLE "Searching for hardware key (dongle)..." set COMMAND [format "%s |& %s bs=1000000 of=%s" \ $DONGLE_INFO \ $TCLU_G(DD) \ $TMP_PATH] set STATUS [tku_long_command $COMMAND $TITLE "" \ ignore ""] if { $STATUS != "ok" } { tku_popup_message error ok \ [format "%s/n%s" \ "Failed to retrieve the dongle id." \ "Check log file for errors"] return "" } if { [catch {open $TMP_PATH RDONLY} FP] } { tku_popup_message error ok \ "The command $DONGLE_INFO\ \nproduced no output" } else { set DONGLE_DATA [read $FP] close $FP foreach WORD $DONGLE_DATA { if [string match ????-????-????-???? $WORD] { set DONGLE_ID $WORD break } } } if { [string length $DONGLE_ID] == 0 } { tku_popup_message error ok \ "The command $DONGLE_INFO\ \nproduced the following errors :" $TMP_PATH } catch { file delete $TMP_PATH } return $DONGLE_ID}#*******************************************************## Name : tclu_get_gz_size## Description : # Returns the size of a gzipped file## Input : PATH - Path of the file to calculate# Output : None# Return Value: File size (or 0 if failed)#*******************************************************#proc tclu_get_gz_size { PATH } { set SIZE 0 if { ! [ catch {exec gunzip -l $PATH } RESULT ] } { set LIST [split $RESULT] set FNUM 0 foreach FIELD $LIST { if { [string length $FIELD] == 0 } continue incr FNUM if { $FNUM == 6 } { set SIZE $FIELD } } } return $SIZE}################ LOG UTILITIES ########################### The LOG utilities routines provide an easy mechanism to add lines# or full files to a log file.# Lines can be tagged in various ways to provide emphasis to some# parts of the log file.###################################set TCLU_G(LOG_FP) 0#*******************************************************## Name : tclu_log_set_path## Description : # Called once, by the main part of the application, setting the path# of the log file to be used.## Input : PATH - Path of the log file to be used# Output : None# Return Value: None#*******************************************************#proc tclu_log_set_path {PATH} { global TCLU_G set TCLU_G(LOG_PATH) $PATH return}proc tclu_log_get_path {} { global TCLU_G return $TCLU_G(LOG_PATH)}#*******************************************************## Name : tclu_log_newline## Description : # Adds a newline character to the log file (Opens it if necessary)## Input : None# Output : None# Return Value: None#*******************************************************#proc tclu_log_newline {} { global TCLU_G if [tclu.log_open] {return 1} puts $TCLU_G(LOG_FP) "" return} #*******************************************************## Name : tclu_log_message## Description : # Adds a text message to the log file. The message can be multi line.# although the tag will only be active for the first line. The tag can be:# normal (default) - font: cbr14 color: black# error - font: cbr14 color: red# underline - font: cbr14 color: black underline# title - font: cbr18 color: black underline# A new line is added by default after the last character.# Input : MESSAGE - text message# TAG - One of the tags above (default = normal)# Output : None# Return Value: None#*******************************************************#proc tclu_log_message {MESSAGE {TAG normal}} { global TCLU_G global env if [tclu.log_open] {return 1} set DATE [clock format [clock seconds] -format "%d %b %Y %H:%M:%S"] if [string length $TAG] { puts -nonewline $TCLU_G(LOG_FP) "()$TAG " } puts $TCLU_G(LOG_FP) "$DATE [tclu_get_user]@[info hostname]: $MESSAGE" flush $TCLU_G(LOG_FP) return}#*******************************************************## Name : tclu_log_file## Description : # Adds a full file to the log file. Much faster then adding it line # by line. No new line is added at the end of the file.## Input : PATH - path to the file to add. # Output : None# Return Value: None#*******************************************************#proc tclu_log_file {PATH} { global TCLU_G if [tclu.log_open] {return 1} if {! [catch {open $PATH RDONLY} FP] } { set DATA [read $FP] close $FP puts -nonewline $TCLU_G(LOG_FP) \n$DATA flush $TCLU_G(LOG_FP) } else { tclu_log_message "Failed to add file $PATH" error } return}#*******************************************************## Name : tclu_create_lst_file## Description : # The routine gets a PATH, and creates an "lst" file in it.# as "lst file" is a text file that containes onr line for# each file in the input directory.# each line looks like this :# FNAME SIZE SUM# where FNAME is the file name# SIZE is number of bytes in file# SUM is md5sum of that file.# Note : If there was an "lst file" in the input directory,# it is deleted before processing.## Input : PATH - files path# LST_NAME - name of lst file to create inside# the input path.# Output : None #*******************************************************#proc tclu_create_lst_file { LST_NAME PATH {PATH1 ""} } { global TCLU_G if { ! [tclu_is_path_dir $PATH] } { tku_popup_message error ok \ "Directory $PATH does not exist, could not produce LST file" return } if { [string length $PATH1] > 0 } { if { ! [tclu_is_path_dir $PATH] } { tku_popup_message error ok \ "Directory $PATH does not exist, could not produce LST file" return } } set FULL_LST_NAME $LST_NAME.lst # just to be sure, delete the destination file first ... set LST_FILE_NAME [file join $PATH $FULL_LST_NAME] file delete $LST_FILE_NAME if { [string length $PATH1] == 0 } { set FLIST [glob [file join $PATH *]] } else { set FLIST [glob [file join $PATH *] [file join $PATH1 *] ] } if {[catch {open $LST_FILE_NAME w} FP]} { puts "Can't open $LST_FILE_NAME to produce LST file" return } foreach FILE $FLIST { set SUM [tclu_get_checksum $FILE] set NAME [file tail $FILE] set SIZE [file size $FILE] set SUM_LINE [concat $NAME $SIZE $SUM] puts $FP $SUM_LINE } close $FP}#*******************************************************## Name : tclu_check_lst_file## Description : # The routine gets an lst file name and a directory# path. it then searches for the files inside the input# path, for matching parameters : name, size and sum.# The result is returned in a list, that each "element"# in it stands for: Name match (existance)# Summatch (by md5sum)# Size (in bytes)# a "Should copy" flag# Input : PATH - files path# LST_NAME - name of lst file to create inside# the input path.# Output : LST_RESULT : a list, containing the result# of lst matching.# # Return Value : If all files match, returns 0, otherwise returns -1#*****************************************************************#proc tclu_check_lst_file { PATH LST_FILE IGNORE_FILES LST {QUIET 0} } { global TCLU_G upvar $LST LST_RESULT set STATUS 0 if { ! [tclu_is_path_dir $PATH] } { if { !$QUIET } { tku_popup_message error ok \ "Directory $PATH does not exist, could not check LST file" } set STATUS -1 return $STATUS } if { ! [tclu_file_exists $LST_FILE] } { if { !$QUIET } { tku_popup_message error ok \ "Input LST file ($LST_FILE) does not exist, could not check..." } set STATUS -2 return $STATUS } if { [catch {open $LST_FILE r} TFP]} { if { !$QUIET } { tku_popup_message error ok \ "Error opening LST file ($LST_FILE), could not check..." } set STATUS -3 return $STATUS } set FILE_COUNT 0 while {! [eof $TFP]} { gets $TFP LINE set LSIZE [string length $LINE] if {$LSIZE == 0} break scan $LINE "%s%s%s" FILE_NAME FILE_SIZE FILE_SUM set CUR_CHECK_FILE [file join $PATH $FILE_NAME] set FILE_NAMES($FILE_COUNT) $FILE_NAME set FILE_SIZES($FILE_COUNT) $FILE_SIZE set FILE_SUMS($FILE_COUNT) $FILE_SUM set FILE_COPY($FILE_COUNT) 1 set NMATCH "yes" set SUMATCH "yes" set COPYF "no " if {[string match $IGNORE_FILES $FILE_NAME]} { continue } # if the current checked file exists, we make sure its # checksum is the same as we expect if { [tclu_file_exists $CUR_CHECK_FILE] } { set CUR_SUM [tclu_get_checksum $CUR_CHECK_FILE] if {[string compare $CUR_SUM $FILE_SUM] == 0} { set FILE_COPY($FILE_COUNT) 0 } else { set STATUS -4 set SUMATCH "no " set COPYF "yes" } } else { set STATUS -4 set NMATCH "no " set SUMATCH "no " set COPYF "yes" } lappend LST_RESULT $FILE_NAME $NMATCH $FILE_SIZE $SUMATCH $FILE_SUM $COPYF incr FILE_COUNT } close $TFP return $STATUS}#*******************************************************## Name : tclu_check_sum_file## Description : # The routine receives a data file and a sum file (in the standard# (name size md5sum) format and verifies that the md5sum of the # file matches the sum file.# Input : DATA_PATH - Path of the data file# SUM_PATH - Path of the sum file# Output : None# # Return Value : If file match, returns 0, otherwise returns -1#*****************************************************************#proc tclu_check_sum_file { DATA_PATH SUM_PATH } { global TCLU_G set SUM_IS_OK 0 if {! [catch {open $SUM_PATH r} TFP]} { gets $TFP LINE close $TFP set NUM_FIELDS [scan $LINE "%s %s %s" FILE_NAME SIZE SUM] if {$NUM_FIELDS != 3} { return -1 } if { [tclu_file_exists $DATA_PATH] } { set CUR_SUM [tclu_get_checksum $DATA_PATH] set CUR_SIZE [file size $DATA_PATH] if {($CUR_SUM == $SUM) && ($CUR_SIZE == $SIZE)} { set SUM_IS_OK 1 } } } if { ! $SUM_IS_OK } { return -1 } return 0}proc tclu_get_checksum { IN_FILE } { global TCLU_G set SUM_PATH [tclu_get_tmp_name "tmpsum"] set SUMPROG [file join $TCLU_G(TOOLS) "md5sum.exe"] set SUM 0 if { ! [tclu_file_exists $IN_FILE] } { tku_popup_message error ok \ "$IN_FILE not found - checksum set to 0" return $SUM } set PIPE_IN [file join $TCLU_G(TOOLS) pipe_in.exe] set PROGRESS_PATH [tclu_get_tmp_name "progress"] set COMMAND [format "%s %s %s | %s -b | %s bs=1000000 of=%s" \ $PIPE_IN $IN_FILE $PROGRESS_PATH \ $SUMPROG \ $TCLU_G(DD) \ $SUM_PATH]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -