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

Source Code for Module PyFoam.LogAnalysis.ContextLineAnalyzer

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