Skip to content
Snippets Groups Projects
Commit e33c7b02 authored by Tobias Meisel's avatar Tobias Meisel
Browse files

[logparser] Providing regexes to parse_file is optional

parent 6049c1d6
No related branches found
No related tags found
1 merge request!130Logparser
...@@ -80,7 +80,7 @@ def parse_file( ...@@ -80,7 +80,7 @@ def parse_file(
file_name: Union[str, Path], file_name: Union[str, Path],
maximum_lines: Optional[int] = None, maximum_lines: Optional[int] = None,
force_parallel: bool = False, force_parallel: bool = False,
ogs_res: Callable = ogs_regexes, ogs_res: Optional[list] = None,
) -> list[Any]: ) -> list[Any]:
""" """
Parses a log file from OGS, applying regex patterns to extract specific information, Parses a log file from OGS, applying regex patterns to extract specific information,
...@@ -109,11 +109,14 @@ def parse_file( ...@@ -109,11 +109,14 @@ def parse_file(
process_regex = "" process_regex = ""
try_match = _try_match_serial_line try_match = _try_match_serial_line
def compile_re_fn(mpi_process_regex): def compile_re_fn(mpi_process_regex: str) -> Callable[[str], re.Pattern]:
return lambda regex: re.compile(mpi_process_regex + regex) return lambda regex: re.compile(mpi_process_regex + regex)
compile_re = compile_re_fn(process_regex) compile_re = compile_re_fn(process_regex)
patterns = [(compile_re(k), v) for k, v in ogs_res()]
if ogs_res is None:
ogs_res = ogs_regexes()
patterns = [(compile_re(k), v) for k, v in ogs_res]
number_of_lines_read = 0 number_of_lines_read = 0
with file_name.open() as file: with file_name.open() as file:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment