source: trunk/gui/apps/launcher.tcl @ 4834

Last change on this file since 4834 was 4834, checked in by mmc, 7 years ago

Added support for "rappture -execute" option, so that we can execute
the run for a given driver file without involving the GUI. This is
useful for the instant-on caching function, and also for a web services
interface that could be used to launch runs without the GUI.

  • Property svn:executable set to *
File size: 5.0 KB
Line 
1#!/bin/sh
2# -*- mode: Tcl -*-
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 toolxml ""
30
31# scan through the arguments and look for the function
32while {[llength $argv] > 0} {
33    set opt [lindex $argv 0]
34    set argv [lrange $argv 1 end]
35
36    if {[string index $opt 0] == "-"} {
37        switch -- $opt {
38            -run {
39                package require RapptureGUI
40                set guidir $RapptureGUI::library
41                set mainscript [file join $guidir scripts main.tcl]
42                set reqpkgs Tk
43            }
44            -builder {
45                package require RapptureBuilder
46                set blddir $RapptureBuilder::library
47                set mainscript [file join $blddir scripts main.tcl]
48                set reqpkgs Tk
49            }
50            -tester {
51                package require RapptureTester
52                set testdir $RapptureTester::library
53                set mainscript [file join $testdir scripts main.tcl]
54                set reqpkgs Tk
55            }
56            -execute {
57                # for web services and simulation cache -- don't load Tk
58                set reqpkgs ""
59                if {[llength $argv] < 1} {
60                    puts stderr "error: missing driver.xml file for -execute option"
61                    exit 1
62                }
63                set driverxml [lindex $argv 0]
64                set argv [lrange $argv 1 end]
65
66                if {![file readable $driverxml]} {
67                    puts stderr "error: driver file \"$driverxml\" not found"
68                    exit 1
69                }
70
71                set dir [file dirname [info script]]
72                set mainscript [file join $dir execute.tcl]
73            }
74            -tool {
75                set toolxml [lindex $argv 0]
76                set argv [lrange $argv 1 end]
77                if {![file exists $toolxml]} {
78                    puts stderr "file not found: $toolxml"
79                    exit 1
80                }
81                lappend alist -tool $toolxml
82            }
83            -tool - -testdir - -nosim {
84                lappend alist $opt [lindex $argv 0]
85                set argv [lrange $argv 1 end]
86            }
87            -auto {
88                # for the tester in automatic mode -- don't load Tk
89                package require RapptureTester
90                set testdir $RapptureTester::library
91                set mainscript [file join $testdir scripts auto.tcl]
92                set reqpkgs ""
93            }
94            -load {
95                lappend alist $opt
96                while { [llength $argv] > 0 } {
97                    set val [lindex $argv 0]
98                    if { [string index $val 0] == "-" } {
99                        break
100                    }
101                    lappend alist $val
102                    set argv [lrange $argv 1 end]
103                }
104            }
105            default {
106                puts stderr "usage:"
107                puts stderr "  rappture ?-run? ?-tool toolFile? ?-nosim 0/1? ?-load file file ...?"
108                puts stderr "  rappture -builder ?-tool toolFile?"
109                puts stderr "  rappture -tester ?-auto? ?-tool toolFile? ?-testdir directory?"
110                puts stderr "  rappture -execute driver.xml ?-tool toolFile?"
111                exit 1
112            }
113        }
114    }
115}
116
117# If no arguments, assume that it's the -run option
118if {$mainscript eq ""} {
119    package require RapptureGUI
120    set guidir $RapptureGUI::library
121    set mainscript [file join $guidir scripts main.tcl]
122    set reqpkgs Tk
123}
124
125# Invoke the main program with the args
126
127# Note: We're sourcing the driver file "main.tcl" rather than exec-ing
128#       wish because we want to see stderr and stdout messages when they
129#       are written, rather than when the program completes.  It also
130#       eliminates one process waiting for the other to complete. If
131#       "exec" is needed, then the following could be replaced with
132#       blt::bgexec.  It doesn't try to redirect stderr into a file.
133set argv $alist
134foreach name $reqpkgs {
135    package require $name
136}
137source  $mainscript
Note: See TracBrowser for help on using the repository browser.