9 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
10 from FreeFOAM
.compat
import *
11 import FreeFOAM
.tutorial
14 class LogParserError(Exception):
15 """Thrown when parsing of the log file failed."""
16 def __init__(self
, msg
):
17 Exception.__init
__(self
, msg
)
22 class AllTutorialsRunner(FreeFOAM
.tutorial
.TutorialRunner
):
24 FreeFOAM
.tutorial
.TutorialRunner
.__init
__(self
)
25 self
.tutorials_dir
= os
.path
.abspath(os
.path
.dirname(sys
.argv
[0]))
28 # prevent python from creating byte-compiled files (python >= 2.6)
30 sys
.dont_write_bytecode
= True
33 # Recursively run all tutorials
36 for parent
, dirs
, files
in os
.walk(self
.tutorials_dir
):
37 if parent
== self
.tutorials_dir
:
44 f
= open('Allrun', 'rt')
46 m
= imp
.load_module('Allrun'+str(i
), f
, f
.name
,
47 (os
.path
.splitext(f
.name
)[1], 'r', imp
.PY_SOURCE
))
48 if hasattr(m
, 'register_cases') and inspect
.isfunction(
50 m
.register_cases(self
)
54 if inspect
.isclass(a
) and (
55 FreeFOAM
.tutorial
.CaseRunner
in inspect
.getmro(a
)):
59 '${RED}*** Error ***${NORMAL} In '+os
.path
.abspath(f
.name
))
63 ret
= FreeFOAM
.tutorial
.TutorialRunner
.main(self
)
68 # Analyse all log files
70 os
.path
.join(self
.tutorials_dir
, 'testLoopReport'), 'wt')
71 logs
= open(os
.path
.join(self
.tutorials_dir
, 'logs'), 'wt')
72 for parent
, dirs
, files
in os
.walk(self
.tutorials_dir
):
75 # skip test directories if not in test_mode and vice versa
76 if bool(parent
[-5:] == '-test') ^
bool(self
.test_mode
):
78 l
= os
.path
.join(parent
, f
)
79 logs
.writelines(open(l
, 'rt').readlines())
81 self
._logReport
(l
, testReport
)
88 def _logReport(self
, logName
, reportFile
):
89 """Extracts useful info from log file `logName` and writes it to file
90 object `reportFile`."""
98 for l
in open(logName
, 'rt'):
100 r
'(?:APPLICATION:\s+(?P<app>\S+)|CASE:\s+(?P<case>\S+))', l
)
107 if re
.search('FOAM FATAL', l
):
109 elif re
.search(r
'U[xyz](:|\s)*solution singularity', l
):
111 elif re
.match(r
'^\s*[Ee]nd\s*\.?\s*$', l
):
113 elif re
.match(r
'^REPORT:\s+SUCCESS', l
):
116 m
= re
.search(r
'Execution\S+\s+=\s+(?P<time>\S+\s+\S+)', l
)
118 time
= m
.group('time')
120 if bool(case
) != bool(app
):
121 raise LogParserError('Failed to parse "%s"'%logName
)
122 elif not case
and not app
:
126 appAndCase
= "Application %s - case %s"%(app
,
127 os
.path
.relpath(case
, self
.tutorials_dir
))
130 reportFile
.write('%s: ** FOAM FATAL ERROR **\n'%appAndCase
)
132 reportFile
.write('%s: ** Solution singularity **\n'%appAndCase
)
133 elif completed
and success
:
134 reportFile
.write('%s: completed'%appAndCase
)
136 reportFile
.write(' in %s\n'%time
)
138 reportFile
.write('\n')
140 reportFile
.write('%s: unconfirmed completion\n'%appAndCase
)
142 def _testReport(self
):
147 'interpolationScheme',
154 for parent
, dirs
, files
in os
.walk(self
.tutorials_dir
):
155 # skip test directories if not in test_mode and vice versa
156 if bool(parent
[-5:] == '-test') ^
bool(self
.test_mode
):
161 # scan log for APPLICATION and then for schemes and solver
163 log
= open(os
.path
.join(parent
, f
), 'rt')
167 m
= re
.match(r
'APPLICATION:\s*(?P<app>\S+)', l
)
169 app
= os
.path
.basename(m
.group('app'))
170 if app
not in solvers_tmp
:
171 solvers_tmp
[app
] = set()
172 schemes_tmp
[app
] = {}
174 for st
in fv_schemes
:
176 if st
not in schemes_tmp
[app
]:
177 schemes_tmp
[app
][st
] = set()
178 schemes_tmp
[app
][st
].add(l
.split()[-1])
179 m
= re
.match(r
'(\S+):\s+Solving for', l
)
181 solvers_tmp
[app
].add(m
.group(1))
182 # write schemes and solvers information per application
183 SC
= open(os
.path
.join(self
.tutorials_dir
, 'FvSchemes'), 'wt')
184 SO
= open(os
.path
.join(self
.tutorials_dir
, 'FvSolution'), 'wt')
185 applications
= solvers_tmp
.keys()
187 for app
in applications
:
190 for st
in fv_schemes
:
192 if st
in schemes_tmp
[app
] and len(schemes_tmp
[app
][st
]) > 0:
193 tmp
= list(schemes_tmp
[app
][st
])
195 SC
.write(' '+'\n '.join(tmp
)+'\n')
196 if len(solvers_tmp
[app
]) > 0:
197 tmp
= list(solvers_tmp
[app
])
199 SO
.write(' '+'\n '.join(tmp
)+'\n')
203 if __name__
== '__main__':
204 os
.chdir(os
.path
.abspath(os
.path
.dirname(sys
.argv
[0])))
205 sys
.argv
[0] = os
.path
.basename(sys
.argv
[0])
206 sys
.exit(AllTutorialsRunner().main())
208 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file