Changeset 4971
- Timestamp:
- Jan 30, 2015, 12:21:28 PM (10 years ago)
- Location:
- branches/1.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/apps/execute.tcl
r4857 r4971 67 67 set toolobj [Rappture::library $toolxml] 68 68 set TaskObj [Rappture::Task ::#auto $toolobj $installdir] 69 set LogFid "" 69 70 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 # ---------------------------------------------------------------------- 73 proc 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 102 proc 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 114 proc 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 # ---------------------------------------------------------------------- 124 Rappture::getopts argv params { 125 value -status "" 126 value -output "" 127 value -cleanup no 128 } 129 130 if {$params(-status) ne ""} { 131 set LogFid [open $params(-status) w] 132 $TaskObj configure -logger {log_append status} -jobstats log_stats 133 } 134 135 if {$params(-output) eq ""} { 136 # no output? then run quietly and don't try to save results 137 $TaskObj configure -jobstats "" -resultdir "" 138 } 72 139 73 140 # Transfer input values from driver to TaskObj, and then run. … … 80 147 lappend args $path [$driverobj get $path.current] 81 148 } 149 } 150 151 if {$params(-status) ne ""} { 152 # recording status? then look through output for progress messages 153 lappend args -output log_output 82 154 } 83 155 … … 95 167 $runxml put output.status failed 96 168 } 97 $runxml put output.time [clock format [clock seconds]]98 169 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 # ---------------------------------------------------------------------- 172 switch -- $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 } 104 186 } 105 187 106 puts "<?xml version=\"1.0\"?>\n[$runxml xml]" 188 if {$params(-cleanup)} { 189 file delete -force -- $driverxml 190 } 191 192 log_append status "exit $status" 107 193 exit $status -
branches/1.3/gui/apps/launcher.tcl
r4962 r4971 213 213 set mainscript [file join $dir execute.tcl] 214 214 set reqpkgs "" 215 216 # When executing from TOOL_PARAMETERS file directives, 217 # report status, clean up, and save output to data/results. 218 # This helps the web services interface do its thing. 219 set alist [list \ 220 -output @default \ 221 -status rappture.status \ 222 -cleanup yes] 215 223 } 216 224 "" - "-input" { -
branches/1.3/gui/scripts/tool.tcl
r4531 r4971 31 31 public method run {args} { 32 32 sync ;# sync all widget values to XML 33 eval $_task run $args 33 34 foreach {status result} [eval $_task run $args] break 35 if {$status == 0} { 36 # move good results to the data/results directory 37 $_task save $result 38 } 39 40 return [list $status $result] 34 41 } 35 42 public method abort {} { -
branches/1.3/lang/tcl/scripts/task.tcl
r4514 r4971 32 32 public method reset {} 33 33 public method xml {args} 34 public method save {xmlobj {name ""}} 34 35 35 36 protected method _mkdir {dir} … … 39 40 private variable _xmlobj "" ;# XML object with inputs/outputs 40 41 private variable _origxml "" ;# copy of original XML (for reset) 42 private variable _lastrun "" ;# name of last run file 41 43 private variable _installdir "" ;# installation directory for this tool 42 44 private variable _outputcb "" ;# callback for tool output … … 215 217 216 218 # starting job... 219 set _lastrun "" 217 220 _log run started 218 221 Rappture::rusage mark … … 353 356 set result [string trim $job(output)] 354 357 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 358 set _lastrun $file 359 355 360 set status [catch {Rappture::library $file} result] 356 361 if {$status == 0} { … … 366 371 } 367 372 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 397 374 } else { 398 375 set status 1 … … 475 452 476 453 # ---------------------------------------------------------------------- 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 # ---------------------------------------------------------------------- 461 itcl::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 # ---------------------------------------------------------------------- 477 509 # USAGE: _output <data> 478 510 #
Note: See TracChangeset
for help on using the changeset viewer.