mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-22 03:42:07 +08:00
f5e5d688c3
version: sunnypilot v0.9.9 release date: 2025-03-18T06:26:39 master commit: 8e5b656e654a7694c22f2b0b7bee0802db02b4af
15 lines
495 B
Python
15 lines
495 B
Python
import os
|
|
import urllib.parse
|
|
|
|
DEFAULT_CACHE_DIR = os.getenv("CACHE_ROOT", os.path.expanduser("~/.commacache"))
|
|
|
|
def cache_path_for_file_path(fn, cache_dir=DEFAULT_CACHE_DIR):
|
|
dir_ = os.path.join(cache_dir, "local")
|
|
os.makedirs(dir_, exist_ok=True)
|
|
fn_parsed = urllib.parse.urlparse(fn)
|
|
if fn_parsed.scheme == '':
|
|
cache_fn = os.path.abspath(fn).replace("/", "_")
|
|
else:
|
|
cache_fn = f'{fn_parsed.hostname}_{fn_parsed.path.replace("/", "_")}'
|
|
return os.path.join(dir_, cache_fn)
|