Package PyFoam :: Package Applications :: Module UtilityRunnerApp
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.UtilityRunnerApp

 1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Applications/UtilityRunnerApp.py 5103 2009-05-21T13:38:11.860189Z bgschaid  $  
 2  """ 
 3  Application class that implements pyFoamUtilityRunner 
 4  """ 
 5   
 6  from PyFoamApplication import PyFoamApplication 
 7   
 8  from PyFoam.Execution.UtilityRunner import UtilityRunner 
 9   
10  import sys 
11  from os import path 
12   
13 -class UtilityRunnerApp(PyFoamApplication):
14 - def __init__(self,args=None):
15 description=""" 16 Runs a OpenFoam Utility and analyzes the output. Needs a regular 17 expression to look for. The next 3 arguments are the usual OpenFoam 18 argumens (<solver> <directory> <case>) and passes them on (plus 19 additional arguments). Output is sent to stdout and a logfile inside 20 the case directory (PyFoamUtility.logfile). The Directory 21 PyFoamUtility.analyzed contains a file test with the information of 22 the regexp (the pattern groups). 23 """ 24 25 PyFoamApplication.__init__(self, 26 exactNr=False, 27 args=args, 28 description=description)
29
30 - def addOptions(self):
31 self.parser.add_option("-r", 32 "--regexp", 33 type="string", 34 dest="regexp", 35 help="The regular expression to look for") 36 37 self.parser.add_option("-n", 38 "--name", 39 type="string", 40 dest="name", 41 default="test", 42 help="The name for the resulting file") 43 44 self.parser.add_option("--echo", 45 action="store_true", 46 dest="echo", 47 default=False, 48 help="Echo the result file after the run") 49 50 self.parser.add_option("--silent", 51 action="store_true", 52 dest="silent", 53 default=False, 54 help="Don't print the output of the utility to the console")
55
56 - def run(self):
57 if self.opts.regexp==None: 58 self.parser.error("Regular expression needed") 59 60 cName=self.parser.casePath() 61 62 run=UtilityRunner(argv=self.parser.getArgs(), 63 silent=self.opts.silent, 64 server=True) 65 66 run.add(self.opts.name,self.opts.regexp) 67 68 self.addToCaseLog(cName,"Starting") 69 70 run.start() 71 72 self.addToCaseLog(cName,"Ending") 73 74 fn=path.join(run.getDirname(),self.opts.name) 75 76 data=run.analyzer.getData(self.opts.name) 77 78 if data==None: 79 print sys.argv[0]+": No data found" 80 else: 81 if self.opts.echo: 82 fh=open(fn) 83 print fh.read() 84 fh.close() 85 else: 86 print sys.argv[0]+": Output written to file "+fn
87