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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

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