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/lang/tcl/scripts/task.tcl

    r4135 r4970  
    3232    public method reset {}
    3333    public method xml {args}
     34    public method save {xmlobj {name ""}}
    3435
    3536    protected method _mkdir {dir}
     
    3940    private variable _xmlobj ""      ;# XML object with inputs/outputs
    4041    private variable _origxml ""     ;# copy of original XML (for reset)
     42    private variable _lastrun ""     ;# name of last run file
    4143    private variable _installdir ""  ;# installation directory for this tool
    4244    private variable _outputcb ""    ;# callback for tool output
     
    215217
    216218        # starting job...
     219        set _lastrun ""
    217220        _log run started
    218221        Rappture::rusage mark
     
    353356        set result [string trim $job(output)]
    354357        if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
     358            set _lastrun $file
     359
    355360            set status [catch {Rappture::library $file} result]
    356361            if {$status == 0} {
     
    366371            }
    367372
    368             # if there's a results_directory defined in the resources
    369             # file, then move the run.xml file there for storage
    370             set rdir ""
    371             if {$resultdir eq "@default"} {
    372                 if {[info exists _resources(-resultdir)]} {
    373                     set rdir $_resources(-resultdir)
    374                 } else {
    375                     set rdir "."
    376                 }
    377             } elseif {$resultdir ne ""} {
    378                 set rdir $resultdir
    379             }
    380 
    381             if {$status == 0 && $rdir ne ""} {
    382                 catch {
    383                     file delete -force -- $file
    384                     if {![file exists $rdir]} {
    385                         _mkdir $rdir
    386                     }
    387                     set tail [file tail $file]
    388                     set fid [open [file join $rdir $tail] w]
    389                     puts $fid "<?xml version=\"1.0\"?>"
    390                     puts $fid [$result xml]
    391                     close $fid
    392                 }
    393             } else {
    394                 # don't keep the file
    395                 file delete -force -- $file
    396             }
     373            file delete -force -- $file
    397374        } else {
    398375            set status 1
     
    475452
    476453# ----------------------------------------------------------------------
     454# USAGE: save <xmlobj> ?<filename>?
     455#
     456# Used by clients to save the contents of an <xmlobj> representing
     457# a run out to the given file.  If <filename> is not specified, then
     458# it uses the -resultsdir and other settings to do what Rappture
     459# would normally do with the output.
     460# ----------------------------------------------------------------------
     461itcl::body Rappture::Task::save {xmlobj {filename ""}} {
     462    if {$filename eq ""} {
     463        # if there's a results_directory defined in the resources
     464        # file, then move the run.xml file there for storage
     465        set rdir ""
     466        if {$resultdir eq "@default"} {
     467            if {[info exists _resources(-resultdir)]} {
     468                set rdir $_resources(-resultdir)
     469            } else {
     470                set rdir "."
     471            }
     472        } elseif {$resultdir ne ""} {
     473            set rdir $resultdir
     474        }
     475
     476        # use the runfile name generated by the last run
     477        if {$_lastrun ne ""} {
     478            set filename [file join $rdir $_lastrun]
     479        } else {
     480            set filename [file join $rdir run.xml]
     481        }
     482    }
     483
     484    # add any last-minute metadata
     485    $xmlobj put output.time [clock format [clock seconds]]
     486
     487    $xmlobj put tool.version.rappture.version $::Rappture::version
     488    $xmlobj put tool.version.rappture.revision $::Rappture::build
     489
     490    if {[info exists ::tcl_platform(user)]} {
     491        $xmlobj put output.user $::tcl_platform(user)
     492    }
     493
     494    # save the output
     495    set rdir [file dirname $filename]
     496    if {![file exists $rdir]} {
     497        _mkdir $rdir
     498    }
     499
     500    set fid [open $filename w]
     501    puts $fid "<?xml version=\"1.0\"?>"
     502    puts $fid [$xmlobj xml]
     503    close $fid
     504
     505    _log output saved in $filename
     506}
     507
     508# ----------------------------------------------------------------------
    477509# USAGE: _output <data>
    478510#
Note: See TracChangeset for help on using the changeset viewer.