source: trunk/gui/apps/launcher.tcl

Last change on this file was 6473, checked in by ldelgass, 8 years ago

Merge simsets, result cache (instant-on) from release branches.

  • Property svn:executable set to *
File size: 10.9 KB
Line 
1#!/bin/sh
2# -*- mode: tcl; indent-tabs-mode: nil -*-
3# ----------------------------------------------------------------------
4#  RAPPTURE LAUNCHER
5#
6#  This script is invoked by the "rappture" command.  It parses
7#  various input options and selects the proper main program to
8#  run depending on the function (build tool, run tool, tester, etc.).
9#
10#  RUN AS FOLLOWS:
11#    rappture ?-run? ?-tool <toolfile>?
12#    rappture -builder ?-tool <toolfile>?
13#    rappture -tester ?-tool <toolfile>? ?-testdir <directory>?
14#    rappture -execute driver.xml ?-tool <toolfile>?
15#
16#  The default option is "-run", which brings up the GUI used to
17#  run the tool.  If the <toolfile> is not specified, it defaults
18#  to "tool.xml" in the current working directory.
19#
20# ======================================================================
21#  AUTHOR:  Michael McLennan, Purdue University
22#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
23#
24#  See the file "license.terms" for information on usage and
25#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
26# ======================================================================
27set mainscript ""
28set alist ""
29set loadlist ""
30set toolxml ""
31
32# ----------------------------------------------------------------------
33#  Look for parameters passed into the tool session.  If there are
34#  any "file" parameters, they indicate files that should be loaded
35#  for browsing or executed to get results:
36#
37#    file(load):/path/to/run.xml
38#    file(execute):/path/to/driver.xml
39# ----------------------------------------------------------------------
40set params(opt) ""
41set params(load) ""
42set params(execute) ""
43set params(input) ""
44
45set rapptureInfo(cwd) [pwd]
46set rapptureInfo(appName) ""
47
48if {[info exists env(TOOL_PARAMETERS)]} {
49    # if we can't find the file, wait a little
50    set ntries 25
51    while {$ntries > 0 && ![file exists $env(TOOL_PARAMETERS)]} {
52        after 200
53        incr ntries -1
54    }
55
56    if {![file exists $env(TOOL_PARAMETERS)]} {
57        # still no file after all that? then skip parameters
58        puts stderr "WARNING: can't read tool parameters in file \"$env(TOOL_PARAMETERS)\"\nFile not found."
59
60    } elseif {[catch {
61        # read the file and parse the contents
62        set fid [open $env(TOOL_PARAMETERS) r]
63        set info [read $fid]
64        close $fid
65    } result] != 0} {
66        puts stderr "WARNING: can't read tool parameters in file \"$env(TOOL_PARAMETERS)\"\n$result"
67
68    } else {
69        # parse the contents of the tool parameter file
70        foreach line [split $info \n] {
71            set line [string trim $line]
72            if {$line eq "" || [regexp {^#} $line]} {
73                continue
74            }
75
76            if {[regexp {^([a-zA-Z]+)(\(into\:)(.+)\)\:(.+)$} $line match type name path value]
77                || [regexp {^([a-zA-Z]+)(\([^)]+\))?\:(.+)} $line match type name value]} {
78                if {$type eq "file"} {
79                    switch -exact -- $name {
80                        "(load)" - "" {
81                            lappend params(load) $value
82                            set params(opt) "-load"
83                        }
84                        "(simset)" - "" {
85                            lappend params(simset) $value
86                            set params(opt) "-simset"
87                        }
88                        "(execute)" {
89                            set params(execute) $value
90                            set params(opt) "-execute"
91                        }
92                        "(input)" {
93                            set params(input) $value
94                            set params(opt) "-input"
95                        }
96                        "(into:" {
97                            namespace eval ::Rappture { # forward decl }
98                            set ::Rappture::parameters($path) $value
99                        }
100                        default {
101                            puts stderr "WARNING: directive $name not recognized for file parameter \"$value\""
102                        }
103                    }
104                }
105            }
106        }
107    }
108}
109
110# scan through the arguments and look for the function
111while {[llength $argv] > 0} {
112    set opt [lindex $argv 0]
113    set argv [lrange $argv 1 end]
114
115    if {[string index $opt 0] == "-"} {
116        switch -- $opt {
117            -run {
118                package require RapptureGUI
119                set guidir $RapptureGUI::library
120                set mainscript [file join $guidir scripts main.tcl]
121                set reqpkgs Tk
122            }
123            -builder {
124                package require RapptureBuilder
125                set blddir $RapptureBuilder::library
126                set mainscript [file join $blddir scripts main.tcl]
127                set reqpkgs Tk
128            }
129            -tester {
130                package require RapptureTester
131                set testdir $RapptureTester::library
132                set mainscript [file join $testdir scripts main.tcl]
133                set reqpkgs Tk
134            }
135            -execute {
136                # for web services and simulation cache -- don't load Tk
137                set reqpkgs ""
138                if {[llength $argv] < 1} {
139                    puts stderr "error: missing driver.xml file for -execute option"
140                    exit 1
141                }
142                set driverxml [lindex $argv 0]
143                set argv [lrange $argv 1 end]
144
145                if {![file readable $driverxml]} {
146                    puts stderr "error: driver file \"$driverxml\" not found"
147                    exit 1
148                }
149
150                set dir [file dirname [info script]]
151                set mainscript [file join $dir execute.tcl]
152            }
153            -tool {
154                set toolxml [lindex $argv 0]
155                set argv [lrange $argv 1 end]
156                if {![file exists $toolxml]} {
157                    puts stderr "file not found: $toolxml"
158                    exit 1
159                }
160                lappend alist -tool $toolxml
161            }
162            -testdir - -nosim {
163                lappend alist $opt [lindex $argv 0]
164                set argv [lrange $argv 1 end]
165            }
166            -auto {
167                # for the tester in automatic mode -- don't load Tk
168                package require RapptureTester
169                set testdir $RapptureTester::library
170                set mainscript [file join $testdir scripts auto.tcl]
171                set reqpkgs ""
172            }
173            -load {
174                while { [llength $argv] > 0 } {
175                    set val [lindex $argv 0]
176                    if { [string index $val 0] == "-" } {
177                        break
178                    }
179                    lappend loadlist $val
180                    set argv [lrange $argv 1 end]
181                }
182            }
183            -simset {
184                lappend alist $opt [lindex $argv 0]
185                set argv [lrange $argv 1 end]
186            }
187            -appname {
188                global rapptureInfo
189                set rapptureInfo(appName) [lindex $argv 0]
190                set argv [lrange $argv 1 end]
191            }
192            default {
193                puts stderr "usage:"
194                puts stderr "  rappture ?-run? ?-tool toolFile? ?-nosim 0/1? ?-load file file ...?"
195                puts stderr "  rappture -builder ?-tool toolFile?"
196                puts stderr "  rappture -tester ?-auto? ?-tool toolFile? ?-testdir directory?"
197                puts stderr "  rappture -execute driver.xml ?-tool toolFile?"
198                exit 1
199            }
200        }
201    }
202}
203
204# If no arguments, check to see if there are any tool parameters.
205# If not, then assume that it's the -run option.
206if {$mainscript eq ""} {
207    switch -- $params(opt) {
208        -load {
209            # add tool parameters to the end of any files given on cmd line
210            set loadlist [concat $loadlist $params(load)]
211            set alist [concat $alist -load $loadlist]
212
213            package require RapptureGUI
214            set guidir $RapptureGUI::library
215            set mainscript [file join $guidir scripts main.tcl]
216            set reqpkgs Tk
217        }
218        -simset {
219            # add tool parameters to the end of any files given on cmd line
220            set loadlist [concat $loadlist $params(simset)]
221            set alist [concat $alist -simset $loadlist]
222
223            package require RapptureGUI
224            set guidir $RapptureGUI::library
225            set mainscript [file join $guidir scripts main.tcl]
226            set reqpkgs Tk
227        }
228        -execute {
229            if {[llength $params(execute)] != 1} {
230                puts stderr "ERROR: wrong number of (execute) files in TOOL_PARAMETERS (should be only 1)"
231                exit 1
232            }
233            set driverxml [lindex $params(execute) 0]
234            if {![file readable $driverxml]} {
235                puts stderr "error: driver file \"$driverxml\" not found"
236                exit 1
237            }
238            set dir [file dirname [info script]]
239            set mainscript [file join $dir execute.tcl]
240            set reqpkgs ""
241
242            # When executing from TOOL_PARAMETERS file directives,
243            # report status, clean up, and save output to data/results.
244            # This helps the web services interface do its thing.
245            set alist [list \
246                -output @default \
247                -status rappture.status \
248                -cleanup yes]
249        }
250        "" - "-input" {
251            package require RapptureGUI
252            set guidir $RapptureGUI::library
253            set mainscript [file join $guidir scripts main.tcl]
254            set reqpkgs Tk
255
256            # finalize the -input argument for "rappture -run"
257            if {$params(input) ne ""} {
258                if {![file readable $params(input)]} {
259                    puts stderr "error: driver file \"$params(input)\" not found"
260                    exit 1
261                }
262                set alist [concat $alist -input $params(input)]
263            }
264
265            # finalize any pending -load arguments for "rappture -run"
266            if {[llength $loadlist] > 0} {
267                set alist [concat $alist -load $loadlist]
268            }
269        }
270        default {
271            puts stderr "internal error: funny action \"$params(opt)\" inferred from TOOL_PARAMETERS"
272            exit 1
273        }
274    }
275} else {
276    # finalize any pending -load arguments for "rappture -run"
277    if {[llength $loadlist] > 0} {
278        set alist [concat $alist -load $loadlist]
279    }
280}
281
282# Invoke the main program with the args
283
284# Note: We're sourcing the driver file "main.tcl" rather than exec-ing
285#       wish because we want to see stderr and stdout messages when they
286#       are written, rather than when the program completes.  It also
287#       eliminates one process waiting for the other to complete. If
288#       "exec" is needed, then the following could be replaced with
289#       blt::bgexec.  It doesn't try to redirect stderr into a file.
290set argv $alist
291foreach name $reqpkgs {
292    package require $name
293}
294source  $mainscript
Note: See TracBrowser for help on using the repository browser.