process replay: prefix setup in helper (#24636)
* prefix setup in helper
* context manager
* name change + none default
* skip checking prefix
* type hints + unset env
old-commit-hash: d6fb78b9a3
taco
parent
97bb8e2702
commit
bcc6ca0cf5
2 changed files with 28 additions and 25 deletions
@ -0,0 +1,26 @@ |
|||||||
|
import os |
||||||
|
import shutil |
||||||
|
import uuid |
||||||
|
|
||||||
|
from common.params import Params |
||||||
|
|
||||||
|
class OpenpilotPrefix(object): |
||||||
|
def __init__(self, prefix: str = None) -> None: |
||||||
|
self.prefix = prefix if prefix else str(uuid.uuid4()) |
||||||
|
self.msgq_path = os.path.join('/dev/shm', self.prefix) |
||||||
|
|
||||||
|
def __enter__(self): |
||||||
|
os.environ['OPENPILOT_PREFIX'] = self.prefix |
||||||
|
try: |
||||||
|
os.mkdir(self.msgq_path) |
||||||
|
except FileExistsError: |
||||||
|
pass |
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_obj, exc_tb): |
||||||
|
symlink_path = Params().get_param_path() |
||||||
|
if os.path.exists(symlink_path): |
||||||
|
shutil.rmtree(os.path.realpath(symlink_path), ignore_errors=True) |
||||||
|
os.remove(symlink_path) |
||||||
|
shutil.rmtree(self.msgq_path, ignore_errors=True) |
||||||
|
del os.environ['OPENPILOT_PREFIX'] |
||||||
|
return True |
Loading…
Reference in new issue