mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-20 05:22:03 +08:00
f4ee52f095
date: 2024-02-12T12:52:55 commit: 0f5fdc8c6be06fb8901e8be8f3fa7d00596eb1f4
23 lines
578 B
Python
23 lines
578 B
Python
import os
|
|
|
|
from openpilot.tools.lib.url_file import URLFile
|
|
|
|
DATA_ENDPOINT = os.getenv("DATA_ENDPOINT", "http://data-raw.comma.internal/")
|
|
|
|
def resolve_name(fn):
|
|
if fn.startswith("cd:/"):
|
|
return fn.replace("cd:/", DATA_ENDPOINT)
|
|
return fn
|
|
|
|
def file_exists(fn):
|
|
fn = resolve_name(fn)
|
|
if fn.startswith(("http://", "https://")):
|
|
return URLFile(fn).get_length_online() != -1
|
|
return os.path.exists(fn)
|
|
|
|
def FileReader(fn, debug=False):
|
|
fn = resolve_name(fn)
|
|
if fn.startswith(("http://", "https://")):
|
|
return URLFile(fn, debug=debug)
|
|
return open(fn, "rb")
|