Changeset 892
- Timestamp:
- Feb 16, 2008, 1:27:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/apps/rerun
r626 r892 10 10 # 11 11 # RUN AS FOLLOWS: 12 # rerun [-h | -d driver_path] <run.xml-file>12 # rerun [-h | -d rappture_path] <runFile> 13 13 # 14 14 # -h | --help - print the help menu 15 # -d | --driver driver_path - specify the path to the driver16 # program. You will need to specify17 # the path if the driver programis15 # -d | --driver rappture_path - specify the path to the rappture 16 # command. You will need to specify 17 # the path if the rappture command is 18 18 # not in your PATH environment 19 19 # variable. 20 20 # 21 # <run .xml-file> - the run.xml file youcontaining an output21 # <runFile> - the run.xml file containing an output 22 22 # section you would like to re-generate. 23 23 # 24 24 # ====================================================================== 25 25 # AUTHOR: Derrick Kearney, Purdue University 26 # Copyright (c) 2004-200 5Purdue Research Foundation26 # Copyright (c) 2004-2008 Purdue Research Foundation 27 27 # 28 28 # See the file "license.terms" for information on usage and … … 34 34 import getopt, shutil, re, os, sys, tempfile 35 35 36 def printHelp(): 37 print """rerun [-h | -d driver_path] runFile 36 def help(): 37 return """rerun [-h | -d rappture_path] runFile 38 Visualize the output from a run.xml. This tool does not resimulate. 38 39 39 40 -h | --help - print the help menu 40 -d | --driver driver_path - specify the path to the driver41 program. You will need to specify42 the path if the driver programis41 -d | --driver rappture_path - specify the path to the rappture 42 command. You will need to specify 43 the path if the rappture command is 43 44 not in your PATH environment 44 45 variable. 45 46 46 <run .xml-file> - the run.xml file youcontaining an output47 <runFile> - the run.xml file containing an output 47 48 section you would like to re-generate. 48 49 """ 49 sys.exit()50 50 51 def main(argv=None): 51 52 52 if __name__ == '__main__' : 53 if argv is None: 54 argv = sys.argv 53 55 54 if len(sys.argv) < 2: 55 printHelp() 56 57 if sys.argv[1] in ("-h", "--help"): 58 printHelp() 56 if len(argv) < 2: 57 print >>sys.stderr, "%s requires at least 2 arguments" % (argv[0]) 58 print >>sys.stderr, help() 59 return 2 59 60 60 61 longOpts = ["driver=","help"] 61 62 shortOpts = "d:h" 62 opts, args = getopt.getopt(sys.argv[1:], shortOpts, longOpts) 63 try: 64 opts, args = getopt.getopt(argv[1:], shortOpts, longOpts) 65 except getopt.GetoptError, msg: 66 print >>sys.stderr, msg 67 print >>sys.stderr, help() 68 return 2 63 69 64 70 driverPath = 'rappture' 65 runFile = args[0]66 71 67 72 # match options … … 70 75 driverPath = v 71 76 elif o in ("-h", "--help"): 72 printHelp() 77 print >>sys.stderr, help() 78 return 2 79 80 runFile = args[0] 73 81 74 82 # look for the text <command> (any characters) </command> 75 83 re_command = re.compile(r'<command>.*</command>', re.I|re.DOTALL) 76 84 77 # prepare text variables 85 try: 86 xmlfile = open(runFile, "rb").read() 87 except IOError, msg: 88 print >>sys.stderr, msg 89 return 2 90 78 91 myTmpFilefd, myTmpFileName = tempfile.mkstemp() 79 92 myTmpFile = os.fdopen(myTmpFilefd,'w+b') 80 outCmd = '<command>echo =RAPPTURE-RUN=>' + myTmpFileName.encode('string_escape') + '</command>' 93 94 outCmd = '<command>echo =RAPPTURE-RUN=>' \ 95 + myTmpFileName.encode('string_escape') \ 96 + '</command>' 97 98 81 99 # do the file <command> switheroo! 82 xmlfile = open(runFile, "rb").read()83 100 outText = re_command.sub(outCmd,xmlfile) 101 102 # This should be fixed in rappture, 103 # until it is fixed there, we do it here 104 # look for the pesty self terminating current tags <current/> 105 # do the file <current/> switheroo! 106 re_current = re.compile(r'<current/>',re.I|re.DOTALL) 107 outText = re_current.sub('',outText) 108 84 109 myTmpFile.write(outText) 85 110 myTmpFile.flush() 86 111 87 112 # run driver on the temporary run file 88 print "myTmpFileName = %s" % (myTmpFileName)89 113 systemCmd = '%s -tool %s' % (driverPath, myTmpFileName) 114 #FIXME: do we really need to shell out? Rappture.tools.getCommandOutput()? 90 115 os.system(systemCmd) 91 116 92 117 # presto-change-o 93 118 94 119 # clean up our tmp file 95 120 # tempfile module does not auto delete files created by mkstemp on close … … 100 125 os.remove(myTmpFileName) 101 126 102 # exit gracefully 103 sys.exit() 127 return 0 128 129 if __name__ == '__main__' : 130 # call main and exit gracefully 131 sys.exit(main())
Note: See TracChangeset
for help on using the changeset viewer.