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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

 1  #  ICE Revision: $Id: UtilityRunnerApp.py 7832 2007-08-28 13:07:26Z bgschaid $  
 2  """ 
 3  Application class that implements pyFoamUtilityRunner 
 4  """ 
 5   
 6  from PyFoamApplication import PyFoamApplication 
 7   
 8  from PyFoam.FoamInformation import changeFoamVersion 
 9   
10  from PyFoam.Execution.UtilityRunner import UtilityRunner 
11   
12  import sys 
13  from os import path 
14   
15 -class UtilityRunnerApp(PyFoamApplication):
16 - def __init__(self):
17 description=""" 18 Runs a OpenFoam Utility and analyzes the output. Needs a regular 19 expression to look for. The next 3 arguments are the usual OpenFoam 20 argumens (<solver> <directory> <case>) and passes them on (plus 21 additional arguments). Output is sent to stdout and a logfile inside 22 the case directory (PyFoamUtility.logfile). The Directory 23 PyFoamUtility.analyzed contains a file test with the information of 24 the regexp (the pattern groups). 25 """ 26 27 PyFoamApplication.__init__(self,description=description)
28
29 - def addOptions(self):
30 self.parser.add_option("-r","--regexp",type="string",dest="regexp",help="The regular expression to look for") 31 self.parser.add_option("-n","--name",type="string",dest="name",default="test",help="The name for the resulting file") 32 self.parser.add_option("--echo",action="store_true",dest="echo",default=False,help="Echo the result file after the run") 33 self.parser.add_option("--silent",action="store_true",dest="silent",default=False,help="Don't print the output of the utility to the console") 34 self.parser.add_option("--foamVersion",dest="foamVersion",default=None,help="Change the OpenFOAM-version that is to be used")
35
36 - def run(self):
37 if self.opts.foamVersion!=None: 38 changeFoamVersion(self.opts.foamVersion) 39 40 if self.opts.regexp==None: 41 self.parser.error("Regular expression needed") 42 43 run=UtilityRunner(argv=self.parser.getArgs(),silent=self.opts.silent,server=True) 44 45 run.add(self.opts.name,self.opts.regexp) 46 47 run.start() 48 49 fn=path.join(run.getDirname(),self.opts.name) 50 51 data=run.analyzer.getData(self.opts.name) 52 53 if data==None: 54 print sys.argv[0]+": No data found" 55 else: 56 if self.opts.echo: 57 fh=open(fn) 58 print fh.read() 59 fh.close() 60 else: 61 print sys.argv[0]+": Output written to file "+fn
62