| 54 | |
| 55 | |
| 56 | class TeleportLocalState: |
| 57 | def __init__(self, data: dict[str, Any] | None): |
| 58 | self.data = data or {} |
| 59 | |
| 60 | @classmethod |
| 61 | def read(cls): |
| 62 | return TeleportLocalState(LocalState.read("teleport")) |
| 63 | |
| 64 | def write(self): |
| 65 | LocalState.write("teleport", self.data) |
| 66 | |
| 67 | def get_pid(self, app_name: str) -> str | None: |
| 68 | existing = self.data.get(app_name, {}) |
| 69 | return existing.get("pid") |
| 70 | |
| 71 | def set_pid(self, app_name: str, pid: str | None): |
| 72 | existing = self.data.get(app_name, {}) |
| 73 | existing["pid"] = pid |
| 74 | self.data[app_name] = existing |
| 75 | |
| 76 | def get_address(self, app_name: str) -> str | None: |
| 77 | existing = self.data.get(app_name, {}) |
| 78 | return existing.get("address") |
| 79 | |
| 80 | def set_address(self, app_name: str, addr: str | None): |
| 81 | existing = self.data.get(app_name, {}) |
| 82 | existing["address"] = addr |
| 83 | self.data[app_name] = existing |
| 84 | |
| 85 | def __str__(self): |
| 86 | return dedent(f""" |
| 87 | TeleportLocalState: |
| 88 | data: {self.data} |
| 89 | """) |