From 8c7d53004fcae9279e0279aea66a49ec41097f3d Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 5 Aug 2025 18:34:35 -0700 Subject: [PATCH] Revert "Filename: minor refactor (#35927)" This reverts commit 96313fa4c05b0713dbf76b39ea36fcb7b9455db5. --- tools/lib/logreader.py | 14 ++++++++++- tools/lib/route.py | 53 ++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/tools/lib/logreader.py b/tools/lib/logreader.py index a2b8be8705..1075bd2f08 100755 --- a/tools/lib/logreader.py +++ b/tools/lib/logreader.py @@ -21,7 +21,8 @@ from openpilot.common.swaglog import cloudlog from openpilot.tools.lib.comma_car_segments import get_url as get_comma_segments_url from openpilot.tools.lib.openpilotci import get_url from openpilot.tools.lib.filereader import DATA_ENDPOINT, FileReader, file_exists, internal_source_available -from openpilot.tools.lib.route import Route, SegmentRange, FileName +from openpilot.tools.lib.route import QCAMERA_FILENAMES, CAMERA_FILENAMES, DCAMERA_FILENAMES, \ + ECAMERA_FILENAMES, BOOTLOG_FILENAMES, Route, SegmentRange from openpilot.tools.lib.log_time_series import msgs_to_time_series LogMessage = type[capnp._DynamicStructReader] @@ -101,6 +102,17 @@ class ReadMode(enum.StrEnum): AUTO_INTERACTIVE = "i" # default to rlogs, fallback to qlogs with a prompt from the user +class FileName(enum.Enum): + #TODO use the ones from route.py + RLOG = ("rlog.zst", "rlog.bz2") + QLOG = ("qlog.zst", "qlog.bz2") + QCAMERA = QCAMERA_FILENAMES + FCAMERA = CAMERA_FILENAMES + ECAMERA = ECAMERA_FILENAMES + DCAMERA = DCAMERA_FILENAMES + BOOTLOG = BOOTLOG_FILENAMES + + LogPath = str | None Source = Callable[[SegmentRange, FileName], list[LogPath]] diff --git a/tools/lib/route.py b/tools/lib/route.py index 9f71ef727e..55ea956c5f 100644 --- a/tools/lib/route.py +++ b/tools/lib/route.py @@ -1,6 +1,5 @@ import os import re -import enum import requests from functools import cache from urllib.parse import urlparse @@ -11,16 +10,14 @@ from openpilot.tools.lib.auth_config import get_token from openpilot.tools.lib.api import APIError, CommaApi from openpilot.tools.lib.helpers import RE +QLOG_FILENAMES = ('qlog.bz2', 'qlog.zst', 'qlog') +QCAMERA_FILENAMES = ('qcamera.ts',) +LOG_FILENAMES = ('rlog.bz2', 'raw_log.bz2', 'rlog.zst', 'rlog') +CAMERA_FILENAMES = ('fcamera.hevc', 'video.hevc') +DCAMERA_FILENAMES = ('dcamera.hevc',) +ECAMERA_FILENAMES = ('ecamera.hevc',) +BOOTLOG_FILENAMES = ('bootlog.zst', 'bootlog.bz2', 'bootlog') -class FileName(enum.Enum): - #TODO use the ones from route.py - RLOG = ("rlog.zst", "rlog.bz2") - QLOG = ("qlog.zst", "qlog.bz2") - QCAMERA = ('qcamera.ts',) - FCAMERA = ('fcamera.hevc',) - ECAMERA = ('ecamera.hevc',) - DCAMERA = ('dcamera.hevc',) - BOOTLOG = ('bootlog.zst', 'bootlog.bz2') class Route: def __init__(self, name, data_dir=None): @@ -85,23 +82,23 @@ class Route: if segments.get(segment_name): segments[segment_name] = Segment( segment_name, - url if fn in FileName.RLOG else segments[segment_name].log_path, - url if fn in FileName.QLOG else segments[segment_name].qlog_path, - url if fn in FileName.FCAMERA else segments[segment_name].camera_path, - url if fn in FileName.DCAMERA else segments[segment_name].dcamera_path, - url if fn in FileName.ECAMERA else segments[segment_name].ecamera_path, - url if fn in FileName.QCAMERA else segments[segment_name].qcamera_path, + url if fn in LOG_FILENAMES else segments[segment_name].log_path, + url if fn in QLOG_FILENAMES else segments[segment_name].qlog_path, + url if fn in CAMERA_FILENAMES else segments[segment_name].camera_path, + url if fn in DCAMERA_FILENAMES else segments[segment_name].dcamera_path, + url if fn in ECAMERA_FILENAMES else segments[segment_name].ecamera_path, + url if fn in QCAMERA_FILENAMES else segments[segment_name].qcamera_path, self.metadata['url'], ) else: segments[segment_name] = Segment( segment_name, - url if fn in FileName.RLOG else None, - url if fn in FileName.QLOG else None, - url if fn in FileName.FCAMERA else None, - url if fn in FileName.DCAMERA else None, - url if fn in FileName.ECAMERA else None, - url if fn in FileName.QCAMERA else None, + url if fn in LOG_FILENAMES else None, + url if fn in QLOG_FILENAMES else None, + url if fn in CAMERA_FILENAMES else None, + url if fn in DCAMERA_FILENAMES else None, + url if fn in ECAMERA_FILENAMES else None, + url if fn in QCAMERA_FILENAMES else None, self.metadata['url'], ) @@ -139,32 +136,32 @@ class Route: for segment, files in segment_files.items(): try: - log_path = next(path for path, filename in files if filename in FileName.RLOG) + log_path = next(path for path, filename in files if filename in LOG_FILENAMES) except StopIteration: log_path = None try: - qlog_path = next(path for path, filename in files if filename in FileName.QLOG) + qlog_path = next(path for path, filename in files if filename in QLOG_FILENAMES) except StopIteration: qlog_path = None try: - camera_path = next(path for path, filename in files if filename in FileName.FCAMERA) + camera_path = next(path for path, filename in files if filename in CAMERA_FILENAMES) except StopIteration: camera_path = None try: - dcamera_path = next(path for path, filename in files if filename in FileName.DCAMERA) + dcamera_path = next(path for path, filename in files if filename in DCAMERA_FILENAMES) except StopIteration: dcamera_path = None try: - ecamera_path = next(path for path, filename in files if filename in FileName.ECAMERA) + ecamera_path = next(path for path, filename in files if filename in ECAMERA_FILENAMES) except StopIteration: ecamera_path = None try: - qcamera_path = next(path for path, filename in files if filename in FileName.QCAMERA) + qcamera_path = next(path for path, filename in files if filename in QCAMERA_FILENAMES) except StopIteration: qcamera_path = None