Skip to content

Commit

Permalink
tools: keep re pattern file small (commaai#33084)
Browse files Browse the repository at this point in the history
remove bz2 from re file
  • Loading branch information
sshane authored Jul 26, 2024
1 parent f39c5c2 commit e68bb26
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 23 deletions.
3 changes: 1 addition & 2 deletions selfdrive/debug/run_process_on_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import argparse

from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS, replay_process
from openpilot.tools.lib.helpers import save_log
from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.logreader import LogReader, save_log

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run process on route and create new logs",
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/test/process_replay/model_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from openpilot.selfdrive.test.process_replay.compare_logs import compare_logs, format_diff
from openpilot.selfdrive.test.process_replay.process_replay import get_process_config, replay_process
from openpilot.tools.lib.framereader import FrameReader
from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.helpers import save_log
from openpilot.tools.lib.logreader import LogReader, save_log

TEST_ROUTE = "2f4452b03ccb98f0|2022-12-03--13-45-30"
SEGMENT = 6
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/test/process_replay/regen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from openpilot.selfdrive.test.update_ci_routes import upload_route
from openpilot.tools.lib.route import Route
from openpilot.tools.lib.framereader import FrameReader, BaseFrameReader, FrameType
from openpilot.tools.lib.logreader import LogReader, LogIterable
from openpilot.tools.lib.helpers import save_log
from openpilot.tools.lib.logreader import LogReader, LogIterable, save_log


class DummyFrameReader(BaseFrameReader):
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/test/process_replay/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, FAKEDATA, replay_process, \
check_openpilot_enabled, check_most_messages_valid
from openpilot.tools.lib.filereader import FileReader
from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.helpers import save_log
from openpilot.tools.lib.logreader import LogReader, save_log

source_segments = [
("BODY", "937ccb7243511b65|2022-05-24--16-03-09--1"), # COMMA.COMMA_BODY
Expand Down
13 changes: 0 additions & 13 deletions tools/lib/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import bz2


# regex patterns
class RE:
DONGLE_ID = r'(?P<dongle_id>[a-f0-9]{16})'
Expand All @@ -18,13 +15,3 @@ class RE:

EXPLORER_FILE = fr'^(?P<segment_name>{SEGMENT_NAME})--(?P<file_name>[a-z]+\.[a-z0-9]+)$'
OP_SEGMENT_DIR = fr'^(?P<segment_name>{SEGMENT_NAME})$'


def save_log(dest, log_msgs, compress=True):
dat = b"".join(msg.as_builder().to_bytes() for msg in log_msgs)

if compress:
dat = bz2.compress(dat)

with open(dest, "wb") as f:
f.write(dat)
10 changes: 10 additions & 0 deletions tools/lib/logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
RawLogIterable = Iterable[bytes]


def save_log(dest, log_msgs, compress=True):
dat = b"".join(msg.as_builder().to_bytes() for msg in log_msgs)

if compress:
dat = bz2.compress(dat)

with open(dest, "wb") as f:
f.write(dat)


class _LogFileReader:
def __init__(self, fn, canonicalize=True, only_union_types=False, sort_by_time=False, dat=None):
self.data_version = None
Expand Down
3 changes: 1 addition & 2 deletions tools/plotjuggler/juggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

from openpilot.common.basedir import BASEDIR
from openpilot.selfdrive.car.fingerprints import MIGRATION
from openpilot.tools.lib.helpers import save_log
from openpilot.tools.lib.logreader import LogReader, ReadMode
from openpilot.tools.lib.logreader import LogReader, ReadMode, save_log

juggle_dir = os.path.dirname(os.path.realpath(__file__))

Expand Down

0 comments on commit e68bb26

Please sign in to comment.