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