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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

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