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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

 1  #  ICE Revision: $Id: UtilityRunnerApp.py 9161 2008-08-04 08:01:05Z 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 run=UtilityRunner(argv=self.parser.getArgs(),silent=self.opts.silent,server=True) 61 62 run.add(self.opts.name,self.opts.regexp) 63 64 run.start() 65 66 fn=path.join(run.getDirname(),self.opts.name) 67 68 data=run.analyzer.getData(self.opts.name) 69 70 if data==None: 71 print sys.argv[0]+": No data found" 72 else: 73 if self.opts.echo: 74 fh=open(fn) 75 print fh.read() 76 fh.close() 77 else: 78 print sys.argv[0]+": Output written to file "+fn
79