Load process information from .env file.
(cls)
| 63 | |
| 64 | @classmethod |
| 65 | def load(cls) -> 'ProcessInfo': |
| 66 | """Load process information from .env file.""" |
| 67 | try: |
| 68 | for key in dotenv_values(cls._env_file).keys(): |
| 69 | os.environ.pop(key, None) # Remove old values |
| 70 | |
| 71 | if ProcessInfo._env_file.exists(): |
| 72 | load_dotenv(ProcessInfo._env_file, override=True) |
| 73 | |
| 74 | pid_str = os.getenv('KEEPER_SERVICE_PID') |
| 75 | pid = int(pid_str) if pid_str else None |
| 76 | |
| 77 | terminal = os.getenv('KEEPER_SERVICE_TERMINAL') or None |
| 78 | |
| 79 | is_running_str = os.getenv('KEEPER_SERVICE_IS_RUNNING', 'false') |
| 80 | is_running = ProcessInfo._str_to_bool(is_running_str) |
| 81 | |
| 82 | ngrok_pid_str = os.getenv('KEEPER_SERVICE_NGROK_PID') |
| 83 | ngrok_pid = int(ngrok_pid_str) if ngrok_pid_str else None |
| 84 | |
| 85 | cloudflare_pid_str = os.getenv('KEEPER_SERVICE_CLOUDFLARE_PID') |
| 86 | cloudflare_pid = int(cloudflare_pid_str) if cloudflare_pid_str else None |
| 87 | |
| 88 | logger.debug("Process information loaded successfully from .env") |
| 89 | return ProcessInfo( |
| 90 | pid=pid, |
| 91 | terminal=terminal, |
| 92 | is_running=is_running, |
| 93 | ngrok_pid=ngrok_pid, |
| 94 | cloudflare_pid=cloudflare_pid |
| 95 | ) |
| 96 | except Exception as e: |
| 97 | logger.error(f"Failed to load process information: {e}") |
| 98 | pass |
| 99 | |
| 100 | return ProcessInfo(pid=None, terminal=None, is_running=False, ngrok_pid=None, cloudflare_pid=None) |
| 101 | |
| 102 | @classmethod |
| 103 | def clear(cls) -> None: |
no test coverage detected