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

Source Code for Module PyFoam.LogAnalysis.SimpleLineAnalyzer

  1  #  ICE Revision: $Id: SimpleLineAnalyzer.py 7581 2007-06-27 15:29:14Z bgschaid $  
  2  """Do analysis for simple expressions""" 
  3   
  4  import re 
  5   
  6  # from FileLineAnalyzer import FileLineAnalyzer 
  7  # from TimeLineLineAnalyzer import TimeLineLineAnalyzer 
  8   
  9  from GeneralLineAnalyzer import GeneralLineAnalyzer 
 10   
11 -class GeneralSimpleLineAnalyzer(GeneralLineAnalyzer):
12 """Parses lines for an arbitrary regular expression 13 14 Differs from RegExpLineAnalyzer because it doesn't store its data""" 15
16 - def __init__(self,name,exp,idNr=None,idList=None,titles=[],doTimelines=True,doFiles=True):
17 """ 18 @param name: name of the expression (needed for output) 19 @param exp: the regular expression 20 @param idNr: number of the pattern group that is used as an identifier 21 @param idList: numbers of the pattern group that are used from the expression 22 @param titles: titles for the data items""" 23 GeneralLineAnalyzer.__init__(self,titles=titles,doTimelines=doTimelines,doFiles=doFiles) 24 25 self.name=name 26 self.idNr=idNr 27 self.idList=idList 28 self.strExp=exp 29 self.exp=re.compile(self.strExp)
30
31 - def addToFiles(self,match):
32 tm=self.parent.getTime() 33 if tm=="": 34 return 35 36 name=self.name 37 fdata=match.groups() 38 if self.idNr!=None: 39 ID=match.group(self.idNr) 40 name+="_"+ID 41 fdata=fdata[:self.idNr-1]+fdata[self.idNr:] 42 43 self.files.write(name,tm,fdata)
44
45 - def addToTimelines(self,match):
46 tm=self.parent.getTime() 47 if tm=="": 48 return 49 50 mLen=len(match.groups()) 51 ids=self.idList 52 if ids==None: 53 ids=range(mLen) 54 for i in range(len(ids)): 55 ID=ids[i] 56 if ID>=mLen: 57 continue 58 name="%s_%d" % (self.name,ID) 59 if i<len(self.titles): 60 name=self.titles[i] 61 data=match.groups()[ID] 62 self.lines.setValue(name,data)
63
64 -class SimpleLineAnalyzer(GeneralSimpleLineAnalyzer):
65 """Parses lines for an arbitrary regular expression 66 67 Differs from RegExpLineAnalyzer because it doesn't store its data""" 68
69 - def __init__(self,name,exp,idNr=None,titles=[]):
70 """ 71 @param name: name of the expression (needed for output) 72 @param exp: the regular expression 73 @param idNr: number of the pattern group that is used as an identifier 74 @param titles: titles for the data items""" 75 GeneralSimpleLineAnalyzer.__init__(self,name,exp,idNr=idNr,titles=titles,doTimelines=False)
76 77 ## self.name=name 78 ## self.idNr=idNr 79 80 ## self.strExp=exp 81 ## self.exp=re.compile(self.strExp) 82 83 ## def doAnalysis(self,line): 84 ## """Analyzes line and writes the data""" 85 ## tm=self.parent.getTime() 86 ## if tm=="": 87 ## return 88 ## m=self.exp.match(line) 89 ## if m!=None: 90 ## name=self.name 91 ## fdata=m.groups() 92 ## if self.idNr!=None: 93 ## ID=m.group(self.idNr) 94 ## name+="_"+ID 95 ## fdata=fdata[:self.idNr-1]+fdata[self.idNr:] 96 97 ## self.files.write(name,tm,fdata) 98
99 -class TimeLineSimpleLineAnalyzer(GeneralSimpleLineAnalyzer):
100 """Parses lines for an arbitrary regular expression""" 101
102 - def __init__(self,name,exp,idList=None,titles=[]):
103 """@param name: name of the expression (needed for output) 104 @param exp: the regular expression 105 @param idList: numbers of the pattern group that are used from the expression 106 @param titles: titles for the data items""" 107 108 GeneralSimpleLineAnalyzer.__init__(self,name,exp,idNr=idList,titles=titles,doFiles=False)
109 110 ## TimeLineLineAnalyzer.__init__(self) 111 112 ## self.name=name 113 ## self.idList=idList 114 ## self.titles=titles 115 ## if len(self.titles)>0 and self.idList==None: 116 ## self.idList=range(len(self.titles)) 117 118 ## self.strExp=exp 119 ## self.exp=re.compile(self.strExp) 120 121 ## def doAnalysis(self,line): 122 ## """Analyzes line and writes the data""" 123 ## tm=self.parent.getTime() 124 ## if tm=="": 125 ## return 126 ## m=self.exp.match(line) 127 ## if m!=None: 128 ## mLen=len(m.groups()) 129 ## ids=self.idList 130 ## if ids==None: 131 ## ids=range(mLen) 132 ## for i in range(len(ids)): 133 ## ID=ids[i] 134 ## if ID>=mLen: 135 ## continue 136 ## name="%s_%d" % (self.name,ID) 137 ## if i<len(self.titles): 138 ## name=self.titles[i] 139 ## data=m.groups()[ID] 140 ## self.lines.setValue(name,data) 141