Version 20 of Robert Hicks

Updated 2005-04-03 16:46:42

Also known as RLH

Email: robert.hicks AT gmail.com


Things that I will find myself doing with Tcl/Tk:

  • Building a recipe application for my wife (using either SQLite or Metakit)
  • Helping out the Tcl community in any way I can
  • Evangelizing Tcl at work. -- I already have permission to put it everywhere.
  • Creating frontends to a lot of the stuff I do for admin work on (HP and Windows)
  • Creating some Vim plugins...?

Standing offer

If you need something tested on Windows 2000 or Windows XP shoot me an email. I would be glad to help as much as I am able. I am not a -programmer- but I can run anything with instructions. I can go through your docs, I can run test scripts, and stuff like that, so if you need help let me know.

I also run OSX at home now and use the Tcl/Tk Aqua BI distro [L1 ]. So if you need any testing done I can help there as well.


Why did I choose Tcl?

A couple reasons. One reason was that Tcl is easy to learn. I picked up Welch's book [L2 ] a week ago and with help from the c.l.tcl newsgroup [L3 ] I have already created a small tracking application using Metakit. The biggest reason is the people I have exchanged information with in the newsgroup. They were encouraging and super helpful.

Kudos to the those who use Tcl...


Code I would like critiqued

 puts ""
 puts "The POPUPS script is running"
 puts ""

 # If the day is Sunday, get rid of log files
 set theDay [clock format [clock scan now] -format %u]
 set logDir [file join {M:\Program Files\Mincom\ParadoxMaster}]

 if {$theDay == 7} {
     foreach log [glob -nocomplain $logDir/msqupd.log*] {
         puts "Deleting: $log\n"
         file delete -force $log
     }
 }

 # Remove all the users cache directories
 set mimsCache "MIMS Cache"

 foreach cacheDir [glob -nocomplain M:/users/*/Ellipse/temp/$mimsCache] {
     puts "Deleting: $cacheDir\n"
     file delete -force $cacheDir
 } 

 # Run MSQUPD.EXE on all viable districts
 set msqupd [file join {M:\Program Files\Mincom\MIMS Open Enterprise\5.2.3.2\bin\msqupd.exe}]

 foreach district {elldev elldev2 icedev prodev} {
     puts "Now refreshing: $district\n"
     exec $msqupd $district
 }

 proc sendMessage {recipient email_server subject body} {
     package require smtp
     package require mime

     set ::smtp::trf 0 ;# this causes an error, supposedly a fix to Trf is in the works

     set token [mime::initialize -canonical text/plain -string $body]

     mime::setheader $token Subject $subject
     smtp::sendmessage $token -recipients $recipient -servers $email_server
     mime::finalize $token
 }

 set logFile [file join {M:\Program Files\Mincom\ParadoxMaster\msqupd.log}]

 if {[catch {open $logFile r} fileID]} {
     puts "ERROR: $fileID"
     exit
 } else {
     set msgBody [read $fileID]
     close $fileID

     set uname $::env(COMPUTERNAME)
     set subText "Popup Refresh Report"
     set textDate [clock format [clock scan now] -format %Y%m%d]
     set msgSubj "$uname: $subText $textDate"

     sendMessage [email protected] 0.0.0.0 $msgSubj $msgBody ;# this was changed for obvious reasons

     # archive the file
     set suffix [clock format [clock scan now] -format %Y%m%d%H%M%S]
     file rename $logFile $logFile.$suffix

     exit
 }

 # vim: ft=tcl et sw=4 ts=4

Here are my (subjective) comments on the ""POPUPS" code above:

1. Biggest improvement would be a comment block at the top explaining the purpose of the code and the general steps the code uses to achieve that result. Any "tricky" parts, special cases, or vulnerabilities should also be mentioned. Nice also to know where/how/if it's been tested on a variety of inputs. RLH - I actually do have one in the original, I just stripped it out for posting sake.

2. Consider wrapping more of the code in proc as this generally adds flexibility for future enhancement.

3. The coding looks clean and readable to me overall.

4. The file join command at "set msqupd" is superflous and I think should be dropped. Also I suggest switching from \ to / for the file path. The backslashes are never necessary and are an accident waiting to happen. This also occurs at "set logDir".

5. Since this script is destructive, I would consider having a user confirmation prompt. You could provide an over-ride flag for automatic use.

6. Consider moving all your static sets of global variables to the top of the script. Also consider using any array to hold all the globals.

7. The comment about "set ::smtp::trf 0" needs date and more detail along with a mention of what future steps should be considered.

8. Depending on your environment/preferences, you may want to write the i/o error report to stderr instead of stdout.

Hope that helps. Roy Terry, 3April2005 RT


[ Category Person ]