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

Source Code for Module PyFoam.Applications.UtilityRunnerApp

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Applications/UtilityRunnerApp.py 7873 2012-02-21T17:58:56.249464Z 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 action="append", 34 dest="regexp", 35 help="The regular expression to look for. With more than one the expresions get appended") 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 cName=self.parser.casePath() 61 62 run=UtilityRunner(argv=self.parser.getArgs(), 63 silent=self.opts.silent, 64 server=True) 65 66 for i,r in enumerate(self.opts.regexp): 67 name=self.opts.name 68 if len(self.opts.regexp)>1: 69 name="%s_%d" % (name,i) 70 run.add(name,r) 71 72 self.addToCaseLog(cName,"Starting") 73 74 run.start() 75 76 self.addToCaseLog(cName,"Ending") 77 78 allData=run.data 79 80 for i,r in enumerate(self.opts.regexp): 81 name=self.opts.name 82 if len(self.opts.regexp)>1: 83 name="%s_%d" % (name,i) 84 85 fn=path.join(run.getDirname(),name) 86 87 data=run.analyzer.getData(name) 88 allData["analyzed"][name]=data 89 90 if data==None: 91 print sys.argv[0]+": No data found for expression",r 92 else: 93 if self.opts.echo: 94 fh=open(fn) 95 print fh.read() 96 fh.close() 97 else: 98 print sys.argv[0]+": Output written to file "+fn 99 100 self.setData(allData)
101