From 988659f308dd93a8104884096b6b4bed1bbadce6 Mon Sep 17 00:00:00 2001 From: Marcin Date: Wed, 22 Nov 2023 10:22:31 +0100 Subject: [PATCH] core: add header-only log file load capability --- pyulog/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pyulog/core.py b/pyulog/core.py index f2f52f5..e6092f1 100644 --- a/pyulog/core.py +++ b/pyulog/core.py @@ -93,7 +93,7 @@ def parse_string(cstr): ret = _parse_string(cstr) return ret - def __init__(self, log_file, message_name_filter_list=None, disable_str_exceptions=True): + def __init__(self, log_file, message_name_filter_list=None, disable_str_exceptions=True, header_only=False): """ Initialize the object & load the file. @@ -135,7 +135,7 @@ def __init__(self, log_file, message_name_filter_list=None, disable_str_exceptio ULog._disable_str_exceptions = disable_str_exceptions if log_file is not None: - self._load_file(log_file, message_name_filter_list) + self._load_file(log_file, message_name_filter_list, header_only) ## parsed data @@ -812,7 +812,7 @@ def _add_message_info_multiple(self, msg_info): self._msg_info_multiple_dict[msg_info.key] = [[msg_info.value]] self._msg_info_multiple_dict_types[msg_info.key] = msg_info.type - def _load_file(self, log_file, message_name_filter_list): + def _load_file(self, log_file, message_name_filter_list, header_only=False): """ load and parse an ULog file into memory """ if isinstance(log_file, str): self._file_handle = open(log_file, "rb") #pylint: disable=consider-using-with @@ -827,6 +827,11 @@ def _load_file(self, log_file, message_name_filter_list): if self._debug: print("header end offset: {:}".format(self._file_handle.tell())) + if header_only: + self._file_handle.close() + del self._file_handle + return + if self.has_data_appended and len(self._appended_offsets) > 0: if self._debug: print('This file has data appended')