Skip to content

Commit

Permalink
core: add header-only log file load capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin authored and bkueng committed Nov 22, 2023
1 parent dce296d commit 9975391
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pyulog/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ 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,
parse_header_only=False):
"""
Initialize the object & load the file.
Expand Down Expand Up @@ -135,7 +136,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, parse_header_only)

## parsed data

Expand Down Expand Up @@ -812,7 +813,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, parse_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
Expand All @@ -827,6 +828,11 @@ def _load_file(self, log_file, message_name_filter_list):
if self._debug:
print("header end offset: {:}".format(self._file_handle.tell()))

if parse_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')
Expand Down

0 comments on commit 9975391

Please sign in to comment.