pmb: Make RunOutputTypeDefault and RunOutputTypePopen enums

This allows us to get rid of some of the validation in sanity_checks()
as mypy handles this validation at "build time", and any typos in the
enum instantiation would be a runtime error rather than a silent
failure.

Additionally, it allows us to encode some of the behaviour of the
different output types into the type definition itself by using methods.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2642
This commit is contained in:
Newbyte 2025-07-07 17:00:58 +02:00 committed by Oliver Smith
parent 77b2717d66
commit 7d2f055bcb
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
20 changed files with 167 additions and 84 deletions

View file

@ -24,7 +24,7 @@ import pmb.chroot.initfs
import pmb.config
import pmb.config.pmaports
import pmb.install.losetup
from pmb.types import Env, PathString, PmbArgs
from pmb.types import Env, PathString, PmbArgs, RunOutputTypeDefault
import pmb.helpers.run
import pmb.parse.cpuinfo
from pmb.core import Chroot, ChrootType
@ -470,7 +470,7 @@ def run(args: PmbArgs) -> None:
process = None
try:
signal.signal(signal.SIGTERM, sigterm_handler)
process = pmb.helpers.run.user(qemu, output="tui", env=env)
process = pmb.helpers.run.user(qemu, output=RunOutputTypeDefault.TUI, env=env)
except KeyboardInterrupt:
# In addition to not showing a trace when pressing ^C, let user know
# they can override this behavior: