-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_ogs5py_scripts.py
56 lines (47 loc) · 1.43 KB
/
run_ogs5py_scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
run all ogs5py benchmarks
"""
import sys
import os
import fnmatch
import time
from pexpect.popen_spawn import PopenSpawn
import pexpect
from ogs5py.tools.tools import Output
# pexpect.spawn just runs on unix-like systems
if sys.platform == "win32":
CmdRun = PopenSpawn
else:
CmdRun = pexpect.spawn
def call_script(script, output, timeout=3):
cwd, script_file = os.path.split(script)
args = [sys.executable, "-u", script_file]
try:
child = CmdRun(
" ".join(args), timeout=timeout, logfile=output, cwd=cwd
)
# wait for ogs to finish
child.expect(pexpect.EOF)
except pexpect.TIMEOUT:
output.write("...timeout\n".encode())
def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result
if __name__ == "__main__":
timeout = 3 # None for no timeout
out_dir = os.path.join(os.getcwd(), "benchmarks")
# out_dir = os.path.join(os.getcwd(), "benchmarks_FEM_active")
scripts = find("*.py", out_dir)
log_name = os.path.join(
out_dir, "run_log_" + time.strftime("%Y-%m-%d_%H-%M-%S") + ".txt"
)
output = Output(log_name, print_log=True)
for script in scripts:
print(script)
call_script(script, output, timeout=timeout)
output.close()