Changeset 466


Ignore:
Timestamp:
Dec 4, 2009 5:06:38 PM (14 years ago)
Author:
toby
Message:

# on 2001/10/18 23:22:57, toby did:
update archiving

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expgui

    • Property rcs:date changed from 2001/10/14 05:34:23 to 2001/10/18 23:22:57
    • Property rcs:lines changed from +8 -6 to +40 -127
    • Property rcs:rev changed from 1.48 to 1.49
    r457 r466  
    242242    global expgui expmap entryvar entrycmd tcl_platform
    243243    # is this a compressed archive file?
    244     if {[string match {*.EXP.[0-9][0-9][0-9].gz} $expfile] && \
    245             $tcl_platform(platform) == "unix"} {
    246         regexp {.*.EXP} $expfile rootname
    247         if {[auto_execok gunzip] == ""} {
    248             # tno gunzip -- bail out
    249             MyMessageBox -parent . -title "Cannot Load Archived File" \
    250                 -message "Unable to find the gunzip program in your path. Loading this archived version of [file tail $rootname] requires the gzip program. Load gunzip or fix your path and then restart EXPGUI" \
    251                 -icon error
    252             return
    253         }
     244    if {[string match {*.O[0-9A-F][0-9A-F]} $expfile]} {
     245        set expgui(expfile) {}
     246        set expnam [file rootname $expfile]
    254247        set ans [MyMessageBox -parent . -title "Load Archived File" \
    255                 -message "Loading archived version of [file tail $rootname]. Do you want to overwrite $rootname or save the archived version under a new name?" \
    256                 -icon question -type "{Use New Name} Overwrite"\
     248                -message "Loading archived version of $expnam. Do you want to continue using the same experiment name or work with the archived version under a new name?" \
     249                -icon question -type "{Use New Name} {Continue with current}" \
    257250                -default {Use New Name} \
    258251                -helplink "expguierr.html LoadArchived"
    259252        ]
     253        # archive the current .EXP file
     254        if {$ans != "use new name" && [file exists $expfile]} {
     255            # get the last archived version
     256            set lastf [lindex [lsort [glob $expnam.{O\[0-9A-F\]\[0-9A-F\]}]] end]
     257            if {$lastf == ""} {
     258                set num 01
     259            } else {
     260                regexp {.*\.O([0-9A-F][0-9A-F])$} $lastf a num
     261                scan $num %x num
     262                if {$num >= 255} {
     263                    set num FF
     264                } else {
     265                    set num [string toupper [format %.2x [incr num]]]
     266                }
     267            }
     268            catch {
     269                set newfile $expnam.O$num
     270                file rename -force $expnam.EXP $newfile
     271                exec echo "\n----------------------------------------------" >> $expnam.LST
     272                exec echo "     Regressing to archive file [file tail $expfile]" >> $expnam.LST
     273                exec echo "     but first archiving [file tail $expnam.EXP] as [file tail $newfile]" >> $expnam.LST
     274                exec echo "----------------------------------------------\n" >> $expnam.LST
     275            }
     276        }
     277        file copy -force $expfile $expnam.EXP
    260278        set fmt [expload $expfile]
     279        # if the file was not in the correct format, force a rewrite before use
    261280        if {$fmt < 0} {
    262281            # read error
    263282            return
    264         }
    265         set expgui(changed) 1
    266         set expfile $rootname
    267         if {$ans == "use new name"} {
    268             SaveAsFile
    269             set expfile $expgui(expfile)
    270         }
    271     # is this an uncompressed archive file?
    272     } elseif {[string match {*.EXP.[0-9][0-9][0-9]} $expfile] && \
    273             $tcl_platform(platform) == "unix"} {
    274         regexp {.*.EXP} $expfile rootname
    275         set ans [MyMessageBox -parent . -title "Load Archived File" \
    276                 -message "Loading archived version of [file tail $rootname]. Do you want to overwrite $rootname or save the archived version under a new name?" \
    277                 -icon question -type "{Use New Name} Overwrite"\
    278                 -default {Use New Name} \
    279                 -helplink "expguierr.html LoadArchived"
    280         ]
    281         set fmt [expload $expfile]
    282         if {$fmt < 0} {
    283             # read error
    284             return
    285         }
    286         set expgui(changed) 1
    287         set expfile $rootname
     283        } elseif {$fmt == 1} {
     284            set expgui(changed) 0
     285        } else {
     286            set expgui(changed) 1
     287        }
     288        set expfile $expnam.EXP
    288289        if {$ans == "use new name"} {
    289290            SaveAsFile
     
    426427    if $expgui(changed) {
    427428        set decision [tk_dialog .instrSaveData {Save .EXP changes} \
    428                 {You have made changes to the Experiment. Reading a different file will cause the changes to be lost. Select an option:} \
     429                {You have made changes to the Experiment. Reading a different file without first saving will cause the changes to be lost. Select an option:} \
    429430                {} 0 "Save and read" "Read without Save" "Cancel read command"]
    430431        switch $decision {
     
    570571        return
    571572    }
     573    if {![file exists $expgui(expfile)]} {
     574        after 2000 afterawhile
     575        return
     576    }
    572577    if {[file mtime $expgui(expfile)] != $expgui(expModifiedLast)} {
    573578        # we are "locked". Note that whenidle loop will be restarted later
     
    710715        2 {                  return "Cancel"   }
    711716    }
    712 }
    713 
    714 proc archiveexp {} {
    715     global expgui tcl_platform
    716     # is there a file to archive
    717     if {![file exists $expgui(expfile)]} return
    718     catch {
    719         set expnam [file rootname $expgui(expfile)]
    720         if {$tcl_platform(platform) == "windows"} {
    721             set version -1
    722             catch {source $expnam.version}
    723             incr version
    724             if ![file executable [file join $expgui(scriptdir) pkzip.exe]] {
    725                 # archive w/o pkzip
    726                 set file $expnam![format "%3.3d" $version].EXP
    727                 file copy -force $expnam.EXP $file
    728                 set fp [open $expnam.lst a]
    729                 puts $fp "\n--------------------------------------------------------------"
    730                 puts $fp "Archiving $expnam.EXP as $file"
    731                 puts $fp "--------------------------------------------------------------\n"
    732                 close $fp
    733             } else {
    734                 # archive with PKZIP           
    735                 # need to limit expnam to 8 characters
    736                 set sexp [string toupper [string range [file root [file tail $expnam] ] 0 7]]
    737                 # PKZIP can't handle long dir names either
    738                 cd [set dir [file dirname $expnam]]
    739                 set file $sexp.[format "%3.3d" $version]
    740                 file copy -force $expnam.EXP $file
    741                 exec [file join $expgui(scriptdir) pkzip.exe] -m $sexp $file > zip.out &
    742                 set fp [open $expnam.lst a]
    743                 puts $fp "\n--------------------------------------------------------------"
    744                 puts $fp "Archiving $expnam.EXP as $file in [file join $dir $sexp.ZIP]"
    745                 puts $fp "--------------------------------------------------------------\n"
    746                 close $fp
    747             }
    748             set fp [open $expnam.version w]
    749             puts $fp "set version $version"
    750             close $fp
    751         } else {
    752             set files [glob -nocomplain $expnam.EXP.*]
    753             if {$files == ""} {
    754                 set file $expnam.EXP.000
    755             } else {
    756                 set number {}
    757                 foreach file [lsort -decreasing $files] {
    758                     if [catch {
    759                         regexp {.*\.EXP\.([0-9][0-9][0-9]).*} $file junk number
    760                         regexp {0?0?([0-9]*)} $number junk number
    761                         incr number
    762                     }] {
    763                         continue
    764                     } else {
    765                         break
    766                     }
    767                 }
    768                 if {$number == ""} {set number 0}
    769                 set file $expnam.EXP.[format "%3.3d" $number]
    770             }
    771             file copy $expgui(expfile) $file
    772             if [catch {exec gzip $file}] {
    773                 exec echo "\n----------------------------------------------" >> $expnam.LST
    774                 exec echo "     Archiving $expnam.EXP as $file " >> $expnam.LST
    775                 exec echo "----------------------------------------------\n" >> $expnam.LST
    776             } else {
    777                 exec echo "\n----------------------------------------------" >> $expnam.LST
    778                 exec echo "     Archiving $expnam.EXP as $file.gz " >> $expnam.LST
    779                 exec echo "----------------------------------------------\n" >> $expnam.LST
    780             }
    781         }
    782     } errmsg
    783     if {$errmsg != ""} {
    784         tk_dialog .warn Confirm "Error archiving the current .EXP file: $errmsg" warning 0 OK
    785     }
    786 }
    787 
    788 # save and optionally archive the expfile
    789 proc savearchiveexp {} {
    790     global expgui expmap
    791     if !$expgui(changed) return
    792     if $expgui(archive) archiveexp
    793     # add a history record
    794     exphistory add " EXPGUI [lindex $expgui(Revision) 1] [lindex $expmap(Revision) 1] ($expgui(changed) changes) -- [clock format [clock seconds]]"
    795     # now save the file
    796     expwrite $expgui(expfile)
    797     set expgui(changed) 0
    798     set expgui(expModifiedLast) [file mtime $expgui(expfile)]
    799     set expgui(last_History) [string range [string trim [lindex [exphistory last] 1]] 0 50 ]
    800     wm title . $expgui(expfile)
    801     set expgui(titleunchanged) 1
    802     # set convergence criterion
    803     InitLSvars
    804717}
    805718
Note: See TracChangeset for help on using the changeset viewer.