Package PyFoam :: Package LogAnalysis :: Module ContextLineAnalyzer
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.LogAnalysis.ContextLineAnalyzer

 1  """Line analyzer that finds data n lines after a matching line""" 
 2   
 3  import re 
 4   
 5  from LogLineAnalyzer import LogLineAnalyzer 
 6   
7 -class ContextLineAnalyzer(LogLineAnalyzer):
8 """Base class for analyzers that work with a context""" 9
10 - def __init__(self,trigger,nr=1):
11 """ 12 @param trigger: The regular expression that has to match before data is collected 13 @param nr: The number of lines after the match that data is collected 14 """ 15 LogLineAnalyzer.__init__(self) 16 17 self.trigger=re.compile(trigger) 18 self.nr=nr 19 20 self.cnt=0
21
22 - def doAnalysis(self,line):
23 if self.cnt>0: 24 self.cnt-=1 25 if self.cnt==0: 26 self.doActualAnalysis(line) 27 else: 28 m=self.trigger.match(line) 29 if m!=None: 30 self.cnt=self.nr 31 self.callOnMatch(m)
32
33 - def doActualAnalysis(self,line):
34 """ 35 Called nr lines after the match 36 37 @param line: The line that should be analyzed 38 """ 39 pass
40
41 - def callOnMatch(self,m):
42 """ 43 Called if the line matches 44 45 @param m: The match-object 46 """ 47 pass
48