mirror of
https://github.com/thib8956/advent-of-code.git
synced 2026-11-27 00:46:34 +00:00
aoc_run: filter output
This commit is contained in:
1 parent
4cdea76660
commit
5d21a3648d
1 file changed
+9
-3
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@@ -153,7 +154,7 @@ def run(year, day):
|
|||||||
res = get_input_file(year, day)
|
res = get_input_file(year, day)
|
||||||
f.write(res.read())
|
f.write(res.read())
|
||||||
|
|
||||||
run_day(script_path, input_path)
|
run_day(script_path, input_path, print_full_output=True)
|
||||||
else:
|
else:
|
||||||
for day in range(1, get_max_day(year) + 1):
|
for day in range(1, get_max_day(year) + 1):
|
||||||
script_path, input_path = resolve_paths(year, day)
|
script_path, input_path = resolve_paths(year, day)
|
||||||
@@ -167,7 +168,7 @@ def run(year, day):
|
|||||||
run_day(script_path, input_path)
|
run_day(script_path, input_path)
|
||||||
|
|
||||||
|
|
||||||
def run_day(script_path, input_path):
|
def run_day(script_path, input_path, print_full_output=False):
|
||||||
try:
|
try:
|
||||||
print(f"> running {script_path}\n")
|
print(f"> running {script_path}\n")
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@@ -184,7 +185,12 @@ def run_day(script_path, input_path):
|
|||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(res.stdout.decode())
|
if print_full_output:
|
||||||
|
print(res.stdout.decode())
|
||||||
|
else:
|
||||||
|
res = re.findall(rb"Part [12].*\n", res.stdout)
|
||||||
|
for item in res:
|
||||||
|
print(item.decode(), end="")
|
||||||
print(f"\n> ran {script_path} in {elapsed:.3f}s")
|
print(f"\n> ran {script_path} in {elapsed:.3f}s")
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print(f"> timeout {script_path} after 30s", file=sys.stderr)
|
print(f"> timeout {script_path} after 30s", file=sys.stderr)
|
||||||
Reference in new issue
Block a user