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
)):
60 '${RED}*** Error ***${NORMAL} In '+os
.path
.abspath(f
.name
))
64 ret
= FreeFOAM
.tutorial
.TutorialRunner
.main(self
)
69 # Analyse all log files
71 os
.path
.join(self
.tutorials_dir
, 'testLoopReport'), 'wt')
72 logs
= open(os
.path
.join(self
.tutorials_dir
, 'logs'), 'wt')
73 for parent
, dirs
, files
in os
.walk(self
.tutorials_dir
):
76 # skip test directories if not in test_mode and vice versa
77 if bool(parent
[-5:] == '-test') ^
bool(self
.test_mode
):
79 l
= os
.path
.join(parent
, f
)
80 logs
.writelines(open(l
, 'rt').readlines())
82 self
._logReport
(l
, testReport
)
89 def _logReport(self
, logName
, reportFile
):
90 """Extracts useful info from log file `logName` and writes it to file
91 object `reportFile`."""
99 for l
in open(logName
, 'rt'):
101 r
'(?:APPLICATION:\s+(?P<app>\S+)|CASE:\s+(?P<case>\S+))', l
)
108 if re
.search('FOAM FATAL', l
):
110 elif re
.search(r
'U[xyz](:|\s)*solution singularity', l
):
112 elif re
.match(r
'^\s*[Ee]nd\s*\.?\s*$', l
):
114 elif re
.match(r
'^REPORT:\s+SUCCESS', l
):
117 m
= re
.search(r
'Execution\S+\s+=\s+(?P<time>\S+\s+\S+)', l
)
119 time
= m
.group('time')
121 if bool(case
) != bool(app
):
122 raise LogParserError('Failed to parse "%s"'%logName
)
123 elif not case
and not app
:
127 appAndCase
= "Application %s - case %s"%(app
,
128 os
.path
.relpath(case
, self
.tutorials_dir
))
131 reportFile
.write('%s: ** FOAM FATAL ERROR **\n'%appAndCase
)
133 reportFile
.write('%s: ** Solution singularity **\n'%appAndCase
)
134 elif completed
and success
:
135 reportFile
.write('%s: completed'%appAndCase
)
137 reportFile
.write(' in %s\n'%time
)
139 reportFile
.write('\n')
141 reportFile
.write('%s: unconfirmed completion\n'%appAndCase
)
143 def _testReport(self
):
148 'interpolationScheme',
155 for parent
, dirs
, files
in os
.walk(self
.tutorials_dir
):
156 # skip test directories if not in test_mode and vice versa
157 if bool(parent
[-5:] == '-test') ^
bool(self
.test_mode
):
162 # scan log for APPLICATION and then for schemes and solver
164 log
= open(os
.path
.join(parent
, f
), 'rt')
168 m
= re
.match(r
'APPLICATION:\s*(?P<app>\S+)', l
)
170 app
= os
.path
.basename(m
.group('app'))
171 if app
not in solvers_tmp
:
172 solvers_tmp
[app
] = set()
173 schemes_tmp
[app
] = {}
175 for st
in fv_schemes
:
177 if st
not in schemes_tmp
[app
]:
178 schemes_tmp
[app
][st
] = set()
179 schemes_tmp
[app
][st
].add(l
.split()[-1])
180 m
= re
.match(r
'(\S+):\s+Solving for', l
)
182 solvers_tmp
[app
].add(m
.group(1))
183 # write schemes and solvers information per application
184 SC
= open(os
.path
.join(self
.tutorials_dir
, 'FvSchemes'), 'wt')
185 SO
= open(os
.path
.join(self
.tutorials_dir
, 'FvSolution'), 'wt')
186 applications
= solvers_tmp
.keys()
188 for app
in applications
:
191 for st
in fv_schemes
:
193 if st
in schemes_tmp
[app
] and len(schemes_tmp
[app
][st
]) > 0:
194 tmp
= list(schemes_tmp
[app
][st
])
196 SC
.write(' '+'\n '.join(tmp
)+'\n')
197 if len(solvers_tmp
[app
]) > 0:
198 tmp
= list(solvers_tmp
[app
])
200 SO
.write(' '+'\n '.join(tmp
)+'\n')
204 if __name__
== '__main__':
205 os
.chdir(os
.path
.abspath(os
.path
.dirname(sys
.argv
[0])))
206 sys
.argv
[0] = os
.path
.basename(sys
.argv
[0])
207 sys
.exit(AllTutorialsRunner().main())
209 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file