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

Source Code for Module PyFoam.LogAnalysis.SimpleLineAnalyzer

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