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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

 1  #  ICE Revision: $Id: UtilityRunnerApp.py 7960 2007-09-20 08:33:17Z 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,args=None):
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,args=args,description=description)
28
29 - def addOptions(self):
30 self.parser.add_option("-r", 31 "--regexp", 32 type="string", 33 dest="regexp", 34 help="The regular expression to look for") 35 36 self.parser.add_option("-n", 37 "--name", 38 type="string", 39 dest="name", 40 default="test", 41 help="The name for the resulting file") 42 43 self.parser.add_option("--echo", 44 action="store_true", 45 dest="echo", 46 default=False, 47 help="Echo the result file after the run") 48 49 self.parser.add_option("--silent", 50 action="store_true", 51 dest="silent", 52 default=False, 53 help="Don't print the output of the utility to the console") 54 55 self.parser.add_option("--foamVersion", 56 dest="foamVersion", 57 default=None, 58 help="Change the OpenFOAM-version that is to be used")
59
60 - def run(self):
61 if self.opts.foamVersion!=None: 62 changeFoamVersion(self.opts.foamVersion) 63 64 if self.opts.regexp==None: 65 self.parser.error("Regular expression needed") 66 67 run=UtilityRunner(argv=self.parser.getArgs(),silent=self.opts.silent,server=True) 68 69 run.add(self.opts.name,self.opts.regexp) 70 71 run.start() 72 73 fn=path.join(run.getDirname(),self.opts.name) 74 75 data=run.analyzer.getData(self.opts.name) 76 77 if data==None: 78 print sys.argv[0]+": No data found" 79 else: 80 if self.opts.echo: 81 fh=open(fn) 82 print fh.read() 83 fh.close() 84 else: 85 print sys.argv[0]+": Output written to file "+fn
86