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