1
2 """Analyze OpenFOAM logs"""
3
4 from TimeLineAnalyzer import TimeLineAnalyzer
5 from PyFoam.Basics.LineReader import LineReader
6 from PyFoam.Error import error
7
9 """Base class for all analyzers
10
11 Administrates and calls a number of LogLineAnlayzers for each
12 line"""
13
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
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
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
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
53 """@returns: A list with the names of the Analyzers"""
54 return self.analyzers.keys()
55
57 """Get the LogLineAnalyzer name"""
58 if self.analyzers.has_key(name):
59 return self.analyzers[name]
60 else:
61 return None
62
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
73 """Calls all the anlyzers for a line"""
74 for nm in self.analyzers:
75 self.analyzers[nm].doAnalysis(line)
76
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
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
92 result=result and self.analyzers[nm].goOn()
93
94 return result
95
97 """Gets the current time"""
98 return str(self.time)
99
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
107 """Gets the output directory"""
108 return self.oDir
109