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

Source Code for Module PyFoam.LogAnalysis.FoamLogAnalyzer

  1  #  ICE Revision: $Id: FoamLogAnalyzer.py 7832 2007-08-28 13:07:26Z bgschaid $  
  2  """Analyze OpenFOAM logs""" 
  3   
  4  from TimeLineAnalyzer import TimeLineAnalyzer 
  5  from PyFoam.Basics.LineReader import LineReader 
  6  from PyFoam.Error import error 
  7   
8 -class FoamLogAnalyzer(object):
9 """Base class for all analyzers 10 11 Administrates and calls a number of LogLineAnlayzers for each 12 line""" 13
14 - def __init__(self,progress=False):
15 """ 16 @param progress: Print time progress on console? 17 """ 18 self.analyzers={} 19 self.time="" 20 self.oDir="" 21 self.line=LineReader() 22 self.timeListeners=[] 23 24 self.addAnalyzer("Time",TimeLineAnalyzer(progress=progress))
25
26 - def tearDown(self):
27 """Remove reference to self in children (hoping to remove 28 circular dependencies)""" 29 30 for a in self.analyzers.values(): 31 a.setParent(None)
32
33 - def setTime(self,time):
34 """Sets the time and alert all the LineAnalyzers that the time has changed 35 @param time: the new value of the time 36 """ 37 if time!=self.time: 38 self.time=time 39 for listener in self.timeListeners: 40 listener.timeChanged() 41 for nm in self.analyzers: 42 self.analyzers[nm].timeChanged()
43
44 - def addTimeListener(self,listener):
45 """@param listener: An object that is notified when the time changes. Has to 46 implement a timeChanged method""" 47 if not 'timeChanged' in dir(listener): 48 error("Error. Object has no timeChanged-method:"+str(listener)) 49 else: 50 self.timeListeners.append(listener)
51
52 - def listAnalyzers(self):
53 """@returns: A list with the names of the Analyzers""" 54 return self.analyzers.keys()
55
56 - def getAnalyzer(self,name):
57 """Get the LogLineAnalyzer name""" 58 if self.analyzers.has_key(name): 59 return self.analyzers[name] 60 else: 61 return None
62
63 - def addAnalyzer(self,name,obj):
64 """Adds an analyzer 65 66 obj - A LogLineAnalyzer 67 name - the name of the analyzer""" 68 69 obj.setParent(self) 70 self.analyzers[name]=obj
71
72 - def analyzeLine(self,line):
73 """Calls all the anlyzers for a line""" 74 for nm in self.analyzers: 75 self.analyzers[nm].doAnalysis(line)
76
77 - def analyze(self,fh):
78 """Analyzes a file (one line at a time) 79 80 fh - handle of the file""" 81 while(self.line.read(fh)): 82 self.analyzeLine(self.line.line)
83
84 - def goOn(self):
85 """Checks with all the analyzers 86 87 If one analyzer returns False it returns False""" 88 result=True 89 90 for nm in self.analyzers: 91 # print nm,self.analyzers[nm].goOn() 92 result=result and self.analyzers[nm].goOn() 93 94 return result
95
96 - def getTime(self):
97 """Gets the current time""" 98 return str(self.time)
99
100 - def setDirectory(self,d):
101 """Sets the output directory for all the analyzers""" 102 self.oDir=d 103 for nm in self.analyzers: 104 self.analyzers[nm].setDirectory(self.oDir)
105
106 - def getDirectory(self):
107 """Gets the output directory""" 108 return self.oDir
109