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

Source Code for Module PyFoam.Applications.CommonStandardOutput

 1  """ 
 2  Class that implements the common functionality for treatment of the standard output 
 3  """ 
 4   
 5  from optparse import OptionGroup 
 6  from os import path 
 7   
8 -class CommonStandardOutput(object):
9 """ The class that defines options for standard output 10 """ 11
12 - def addOptions(self,logname=None):
13 grp=OptionGroup(self.parser, 14 "Standard Output", 15 "Treatment of the standard output that is captured from the OpenFOAM-application") 16 grp.add_option("--progress", 17 action="store_true", 18 default=False, 19 dest="progress", 20 help="Only prints the progress of the simulation, but swallows all the other output") 21 grp.add_option("--silent", 22 action="store_true", 23 default=False, 24 dest="silent", 25 help="Do not print any output") 26 grp.add_option("--logname", 27 dest="logname", 28 default=logname, 29 help="Name of the logfile") 30 grp.add_option("--compress", 31 action="store_true", 32 dest="compress", 33 default=False, 34 help="Compress the logfile into a gzip file. Possible loss of data if the run fails") 35 grp.add_option("--no-log", 36 action="store_true", 37 dest="noLog", 38 default=False, 39 help="Do not output a log-file") 40 grp.add_option("--log-tail", 41 action="store", 42 dest="logTail", 43 default=None, 44 type="int", 45 help="Only write the last N lines to the logfile. Too small values might cause performance problems") 46 47 self.parser.add_option_group(grp) 48 49 inf=OptionGroup(self.parser, 50 "Run Info", 51 "Additional information about the run") 52 inf.add_option("--remark", 53 dest="remark", 54 default=None, 55 help="Text string with a remark about the run") 56 inf.add_option("--job-id", 57 dest="jobId", 58 default=None, 59 help="Text string with the job-ID of the queuing system (usually unused)") 60 inf.add_option("--parameter", 61 dest="runParameters", 62 default=[], 63 action="append", 64 help="Parameter that is being added to the runInfo. Of the form <key>:<value>. Can be specified more than once") 65 self.parser.add_option_group(inf)
66
67 - def getRunParameters(self):
68 """Return a dictionary with the parameters""" 69 parameters={} 70 for p in self.opts.runParameters: 71 try: 72 k,v=p.split(":",1) 73 try: 74 v=int(v) 75 except ValueError: 76 try: 77 v=float(v) 78 except ValueError: 79 pass 80 # keep as a string 81 parameters[k]=v 82 except ValueError: 83 parameters[k]=p 84 return parameters
85
86 - def setLogname(self, 87 default="PyFoamRunner", 88 useApplication=True):
89 """Builds a logfile-name 90 @param default: Default value if no prefix for the logfile-has been defined 91 @param useApplication: append the name of the application to the prefix""" 92 93 if self.opts.logname==None: 94 self.opts.logname=default 95 if useApplication: 96 self.opts.logname+="."+path.basename(self.parser.getArgs()[0])
97