1 | #! /bin/sh |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # rerun |
---|
4 | # |
---|
5 | # script to view the output of a previously created run.xml file |
---|
6 | # rerunning the simulation with new data is outside of the scope |
---|
7 | # of this script. it is currently only for viewing the output |
---|
8 | # of a previously created run.xml file. |
---|
9 | # |
---|
10 | # |
---|
11 | # RUN AS FOLLOWS: |
---|
12 | # rerun [-h | -d driver_path] <run.xml-file> |
---|
13 | # |
---|
14 | # -h | --help - print the help menu |
---|
15 | # -d | --driver driver_path - specify the path to the driver |
---|
16 | # program. You will need to specify |
---|
17 | # the path if the driver program is |
---|
18 | # not in your PATH environment |
---|
19 | # variable. |
---|
20 | # |
---|
21 | # <run.xml-file> - the run.xml file you containing an output |
---|
22 | # section you would like to re-generate. |
---|
23 | # |
---|
24 | # ====================================================================== |
---|
25 | # AUTHOR: Derrick Kearney, Purdue University |
---|
26 | # Copyright (c) 2005 Purdue Research Foundation, West Lafayette, IN |
---|
27 | # ====================================================================== |
---|
28 | # |
---|
29 | # |
---|
30 | """:" |
---|
31 | exec python $0 ${1+"$@"} |
---|
32 | """ |
---|
33 | |
---|
34 | import getopt, shutil, re, os, sys |
---|
35 | |
---|
36 | def printHelp(): |
---|
37 | print """rerun [-h | -d driver_path] runFile |
---|
38 | |
---|
39 | -h | --help - print the help menu |
---|
40 | -d | --driver driver_path - specify the path to the driver |
---|
41 | program. You will need to specify |
---|
42 | the path if the driver program is |
---|
43 | not in your PATH environment |
---|
44 | variable. |
---|
45 | |
---|
46 | <run.xml-file> - the run.xml file you containing an output |
---|
47 | section you would like to re-generate. |
---|
48 | """ |
---|
49 | sys.exit() |
---|
50 | |
---|
51 | |
---|
52 | if __name__ == '__main__' : |
---|
53 | |
---|
54 | longOpts = ["driver=","help"] |
---|
55 | shortOpts = "d:h" |
---|
56 | opts, args = getopt.getopt(sys.argv[1:], shortOpts, longOpts) |
---|
57 | |
---|
58 | driverPath = 'driver' |
---|
59 | runFile = args[0] |
---|
60 | |
---|
61 | # match options |
---|
62 | for o, v in opts: |
---|
63 | if o in ("-d", "--driver"): |
---|
64 | driverPath = v |
---|
65 | elif o in ("-h", "--help"): |
---|
66 | printHelp() |
---|
67 | |
---|
68 | # look for the text <command> (any characters) </command> |
---|
69 | re_command = re.compile(r'<command>.*</command>', re.I|re.DOTALL) |
---|
70 | |
---|
71 | # prepare text variables |
---|
72 | outTmpFileName = '/tmp/rerun_' + os.path.basename(runFile) |
---|
73 | outCmd = '<command>echo =RAPPTURE-RUN=>%s</command>' % outTmpFileName |
---|
74 | |
---|
75 | # do the file <command> switheroo! |
---|
76 | xmlfile = open(runFile, "rb").read() |
---|
77 | tmpfile = open(outTmpFileName, "wb") |
---|
78 | outText = re_command.sub(outCmd,xmlfile) |
---|
79 | tmpfile.write(outText) |
---|
80 | tmpfile.close() |
---|
81 | |
---|
82 | # run driver on the temporary run file |
---|
83 | systemCmd = '%s -tool %s' % (driverPath, outTmpFileName) |
---|
84 | os.system(systemCmd) |
---|
85 | |
---|
86 | # presto-change-o |
---|
87 | |
---|
88 | # clean up our tmp file |
---|
89 | os.remove(outTmpFileName) |
---|
90 | sys.exit() |
---|