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

Source Code for Module PyFoam.Applications.CommonPlotLines

  1  """ 
  2  Class that implements common functionality for collecting plot-lines 
  3  """ 
  4   
  5  from os import path 
  6  from optparse import OptionGroup 
  7   
  8  from PyFoam.Error import error,warning 
  9  from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer 
 10   
11 -class CommonPlotLines(object):
12 """ This class collects the lines that should be plotted 13 """ 14
15 - def __init__(self):
16 self.lines_=None
17
18 - def plotLines(self):
19 return self.lines_
20
21 - def addPlotLine(self,line):
22 """Add a single line""" 23 24 if self.lines_==None: 25 self.lines_=[line] 26 else: 27 if type(line)==str: 28 self.lines_.append(line) 29 else: 30 error(line,"is not a string, but",type(line))
31
32 - def addPlotLines(self,lines):
33 """Adds a list of lines""" 34 35 if type(lines)!=list: 36 if type(lines==None): 37 return 38 else: 39 error(lines,"is not a list, but",type(lines)) 40 for l in lines: 41 self.addPlotLine(l)
42
43 - def addFileRegexps(self,fName):
44 """Adds the lines from a file to the custom regular expressions 45 @param fName: The name of the file""" 46 f=open(fName) 47 48 for l in f.readlines(): 49 l=l.strip() 50 if len(l)==0: 51 continue 52 if l[0]=='"' and l[-1]=='"': 53 l=l[1:-1] 54 if len(l)>0: 55 self.addPlotLine(l) 56 57 f.close()
58
59 - def addOptions(self):
60 grp=OptionGroup(self.parser, 61 "Regular expression", 62 "Where regular expressions for custom plots are found") 63 64 grp.add_option("--custom-regexp", 65 action="append", 66 default=None, 67 dest="customRegex", 68 help="Add a custom regular expression to be plotted (can be used more than once)") 69 70 grp.add_option("--regexp-file", 71 action="append", 72 default=None, 73 dest="regexpFile", 74 help="A file with regulare expressions that are treated like the expressions given with --custom-regexp") 75 76 grp.add_option("--no-auto-customRegexp", 77 action="store_false", 78 default=True, 79 dest="autoCustom", 80 help="Do not automatically load the expressions from the file customRegexp") 81 self.parser.add_option_group(grp)
82
83 - def processPlotLineOptions(self,autoPath=None):
84 """Process the options that have to do with plot-lines""" 85 86 self.addPlotLines(self.opts.customRegex) 87 88 if self.opts.regexpFile!=None: 89 for f in self.opts.regexpFile: 90 print " Reading regular expressions from",f 91 self.addFileRegexps(f) 92 93 94 if autoPath!=None and self.opts.autoCustom: 95 autoFile=path.join(autoPath,"customRegexp") 96 if path.exists(autoFile): 97 print " Reading regular expressions from",autoFile 98 self.addFileRegexps(autoFile)
99
100 - def addPlotLineAnalyzers(self,runner):
101 if self.lines_!=None: 102 for i in range(len(self.lines_)): 103 name="Custom%02d" % i 104 runner.addAnalyzer(name,RegExpLineAnalyzer(name.lower(),self.lines_[i],doTimelines=False,doFiles=True))
105