mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 05:24:06 +08:00
* filereader * support URLs in filereader, logreader * unused * use route files api; add auth file * Implement browser auth * Update readme, fix up cache paths * Add tests, clear token on 401 * Factor out URLFile * space
16 lines
510 B
Python
16 lines
510 B
Python
import os
|
|
import urllib.parse
|
|
from tools.lib.file_helpers import mkdirs_exists_ok
|
|
|
|
DEFAULT_CACHE_DIR = os.path.expanduser("~/.commacache")
|
|
|
|
def cache_path_for_file_path(fn, cache_prefix=None):
|
|
dir_ = os.path.join(DEFAULT_CACHE_DIR, "local")
|
|
mkdirs_exists_ok(dir_)
|
|
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)
|