|
|
|
@ -6,12 +6,14 @@ from typing import Optional |
|
|
|
|
|
|
|
|
|
from openpilot.common.params import Params |
|
|
|
|
from openpilot.system.hardware.hw import Paths |
|
|
|
|
from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT |
|
|
|
|
|
|
|
|
|
class OpenpilotPrefix: |
|
|
|
|
def __init__(self, prefix: Optional[str] = None, clean_dirs_on_exit: bool = True): |
|
|
|
|
def __init__(self, prefix: Optional[str] = None, clean_dirs_on_exit: bool = True, shared_download_cache: bool = False): |
|
|
|
|
self.prefix = prefix if prefix else str(uuid.uuid4().hex[0:15]) |
|
|
|
|
self.msgq_path = os.path.join('/dev/shm', self.prefix) |
|
|
|
|
self.clean_dirs_on_exit = clean_dirs_on_exit |
|
|
|
|
self.shared_download_cache = shared_download_cache |
|
|
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
|
self.original_prefix = os.environ.get('OPENPILOT_PREFIX', None) |
|
|
|
@ -22,6 +24,9 @@ class OpenpilotPrefix: |
|
|
|
|
pass |
|
|
|
|
os.makedirs(Paths.log_root(), exist_ok=True) |
|
|
|
|
|
|
|
|
|
if self.shared_download_cache: |
|
|
|
|
os.environ["COMMA_CACHE"] = DEFAULT_DOWNLOAD_CACHE_ROOT |
|
|
|
|
|
|
|
|
|
return self |
|
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_obj, exc_tb): |
|
|
|
@ -42,5 +47,6 @@ class OpenpilotPrefix: |
|
|
|
|
os.remove(symlink_path) |
|
|
|
|
shutil.rmtree(self.msgq_path, ignore_errors=True) |
|
|
|
|
shutil.rmtree(Paths.log_root(), ignore_errors=True) |
|
|
|
|
if not os.environ.get("COMMA_CACHE", False): |
|
|
|
|
shutil.rmtree(Paths.download_cache_root(), ignore_errors=True) |
|
|
|
|
shutil.rmtree(Paths.comma_home(), ignore_errors=True) |
|
|
|
|