Ignore:
Timestamp:
Jan 30, 2015 11:44:56 AM (6 years ago)
Author:
mmc
Message:

Fixed auto-execution via TOOL_PARAMETERS to produce status output in a
file called rappture.status. This makes it easier for the web service
to monitor progress and know when everything is finished. Also, fixed
auto-execution to move the run file to the data/results directory and
clean up the original driver file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/execute.tcl

    r4856 r4970  
    6767set toolobj [Rappture::library $toolxml]
    6868set TaskObj [Rappture::Task ::#auto $toolobj $installdir]
     69set LogFid ""
    6970
    70 # tasks in execute mode run quietly and don't try to save results
    71 $TaskObj configure -jobstats "" -resultdir ""
     71# Define some things that we need for logging status...
     72# ----------------------------------------------------------------------
     73proc log_output {message} {
     74    global LogFid
     75
     76    if {$LogFid ne ""} {
     77        #
     78        # Scan through and pick out any =RAPPTURE-PROGRESS=> messages.
     79        #
     80        set percent ""
     81        while {[regexp -indices \
     82                {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \
     83                 match percent mesg]} {
     84
     85            foreach {i0 i1} $percent break
     86            set percent [string range $message $i0 $i1]
     87
     88            foreach {i0 i1} $mesg break
     89            set mesg [string range $message $i0 $i1]
     90
     91            foreach {i0 i1} $match break
     92            set message [string replace $message $i0 $i1]
     93        }
     94        if {$percent ne ""} {
     95            # report the last percent progress found
     96            log_append progress "$percent% - $mesg"
     97        }
     98    }
     99}
     100
     101# Actually write to the log file
     102proc log_append {level message} {
     103    global LogFid
     104
     105    if {$LogFid ne ""} {
     106        set date [clock format [clock seconds] -format {%Y-%m-%dT%H:%M:%S%z}]
     107        set host [info hostname]
     108        puts $LogFid "$date $host rappture [pid] \[$level\] $message"
     109        flush $LogFid
     110    }
     111}
     112
     113# Actually write to the log file
     114proc log_stats {args} {
     115    set line ""
     116    foreach {key val} $args {
     117        append line "$key=$val "
     118    }
     119    log_append usage $line
     120}
     121
     122# Parse command line options to see
     123# ----------------------------------------------------------------------
     124Rappture::getopts argv params {
     125    value -status ""
     126    value -output ""
     127    value -cleanup no
     128}
     129
     130if {$params(-status) ne ""} {
     131    set LogFid [open $params(-status) w]
     132    $TaskObj configure -logger {log_append status} -jobstats log_stats
     133}
     134
     135if {$params(-output) eq ""} {
     136    # no output? then run quietly and don't try to save results
     137    $TaskObj configure -jobstats "" -resultdir ""
     138}
    72139
    73140# Transfer input values from driver to TaskObj, and then run.
     
    80147        lappend args $path [$driverobj get $path.current]
    81148    }
     149}
     150
     151if {$params(-status) ne ""} {
     152    # recording status? then look through output for progress messages
     153    lappend args -output log_output
    82154}
    83155
     
    95167    $runxml put output.status failed
    96168}
    97 $runxml put output.time [clock format [clock seconds]]
    98169
    99 $runxml put tool.version.rappture.version $::Rappture::version
    100 $runxml put tool.version.rappture.revision $::Rappture::build
    101 
    102 if {[info exists tcl_platform(user)]} {
    103     $runxml put output.user $::tcl_platform(user)
     170# Handle output
     171# ----------------------------------------------------------------------
     172switch -- $params(-output) {
     173    "" {
     174        # no output file -- write to stdout
     175        puts "<?xml version=\"1.0\"?>\n[$runxml xml]"
     176    }
     177    "@default" {
     178        # do the usual Rappture thing -- move to results dir
     179        # but ignore any errors if it fails
     180        catch {$TaskObj save $runxml}
     181    }
     182    default {
     183        # save to the specified file
     184        $TaskObj save $runxml $params(-output)
     185    }
    104186}
    105187
    106 puts "<?xml version=\"1.0\"?>\n[$runxml xml]"
     188if {$params(-cleanup)} {
     189    file delete -force -- $driverxml
     190}
     191
     192log_append status "exit $status"
    107193exit $status
Note: See TracChangeset for help on using the changeset viewer.