31 lines
720 B
Python
31 lines
720 B
Python
"""Execution context for checks (privilege phase, paths)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
PrivilegePhase = Literal["unprivileged", "privileged"]
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class RunContext:
|
|
"""Per-run environment passed into every check."""
|
|
|
|
home: Path
|
|
output_dir: Path
|
|
phase: PrivilegePhase
|
|
dry_run: bool = False
|
|
|
|
@classmethod
|
|
def default_home(cls) -> Path:
|
|
return Path(os.path.expanduser(os.environ.get("HOME", "~"))).resolve()
|
|
|
|
def is_root(self) -> bool:
|
|
try:
|
|
return os.geteuid() == 0
|
|
except AttributeError:
|
|
return False
|