Skip to content

Commit

Permalink
logreader: skip internal source if not available (commaai#31400)
Browse files Browse the repository at this point in the history
* logreader: skip internal source if not available

* raise exception

* but only when appropriate
  • Loading branch information
gregjhogan authored Feb 10, 2024
1 parent 743c418 commit 667693b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tools/lib/filereader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import os
import socket
from urllib.parse import urlparse

from openpilot.tools.lib.url_file import URLFile

DATA_ENDPOINT = os.getenv("DATA_ENDPOINT", "http://data-raw.comma.internal/")

def internal_source_available():
try:
hostname = urlparse(DATA_ENDPOINT).hostname
if hostname:
socket.gethostbyname(hostname)
return True
except socket.gaierror:
pass
return False

def resolve_name(fn):
if fn.startswith("cd:/"):
return fn.replace("cd:/", DATA_ENDPOINT)
Expand Down
5 changes: 4 additions & 1 deletion tools/lib/logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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 FileReader, file_exists
from openpilot.tools.lib.filereader import FileReader, file_exists, internal_source_available
from openpilot.tools.lib.helpers import RE
from openpilot.tools.lib.route import Route, SegmentRange

Expand Down Expand Up @@ -143,6 +143,9 @@ def valid_file(fn):
return apply_strategy(mode, rlog_paths, qlog_paths, valid_file=valid_file)

def internal_source(sr: SegmentRange, mode: ReadMode):
if not internal_source_available():
raise Exception("Internal source not available")

segs = parse_slice(sr)

def get_internal_url(sr: SegmentRange, seg, file):
Expand Down

0 comments on commit 667693b

Please sign in to comment.