diff --git a/archinstall/lib/boot.py b/archinstall/lib/boot.py index 46ea6bf876..2729819cb6 100644 --- a/archinstall/lib/boot.py +++ b/archinstall/lib/boot.py @@ -1,16 +1,21 @@ +from __future__ import annotations + import time from collections.abc import Iterator from types import TracebackType -from typing import Self +from typing import TYPE_CHECKING, ClassVar, Self from .exceptions import SysCallError from .general import SysCommand, SysCommandWorker, locate_binary -from .installer import Installer from .output import error -from .storage import storage + +if TYPE_CHECKING: + from .installer import Installer class Boot: + _active_boot: ClassVar[Self | None] = None + def __init__(self, installation: Installer): self.instance = installation self.container_name = 'archinstall' @@ -18,12 +23,12 @@ def __init__(self, installation: Installer): self.ready = False def __enter__(self) -> Self: - if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance: + if Boot._active_boot and Boot._active_boot.instance != self.instance: raise KeyError('Archinstall only supports booting up one instance and another session is already active.') - if existing_session: - self.session = existing_session.session - self.ready = existing_session.ready + if Boot._active_boot: + self.session = Boot._active_boot.session + self.ready = Boot._active_boot.ready else: # '-P' or --console=pipe could help us not having to do a bunch # of os.write() calls, but instead use pipes (stdin, stdout and stderr) as usual. @@ -46,7 +51,7 @@ def __enter__(self) -> Self: self.ready = True break - storage['active_boot'] = self + Boot._active_boot = self return self def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: @@ -75,7 +80,7 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio shutdown_exit_code = shutdown.exit_code if self.session and (self.session.exit_code == 0 or shutdown_exit_code == 0): - storage['active_boot'] = None + Boot._active_boot = None else: session_exit_code = self.session.exit_code if self.session else -1 diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index a1e9d91c18..68633a2edd 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -36,6 +36,7 @@ from archinstall.tui.curses_menu import Tui from .args import arch_config_handler +from .boot import Boot from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError from .general import SysCommand, run from .hardware import SysInfo @@ -1977,8 +1978,6 @@ def set_keyboard_language(self, language: str) -> bool: # In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968 # Setting an empty keymap first, allows the subsequent call to set layout for both console and x11. - from .boot import Boot - with Boot(self) as session: os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""') @@ -2005,8 +2004,6 @@ def set_x11_keyboard_language(self, language: str) -> bool: error(f'Invalid x11-keyboard language specified: {language}') return False - from .boot import Boot - with Boot(self) as session: session.SysCommand(['localectl', 'set-x11-keymap', '""']) diff --git a/archinstall/lib/storage.py b/archinstall/lib/storage.py index 68861cac64..4c706a8f48 100644 --- a/archinstall/lib/storage.py +++ b/archinstall/lib/storage.py @@ -8,12 +8,10 @@ from typing import TYPE_CHECKING, NotRequired, TypedDict if TYPE_CHECKING: - from archinstall.lib.boot import Boot from archinstall.lib.installer import Installer class _StorageDict(TypedDict): - active_boot: NotRequired['Boot | None'] installation_session: NotRequired['Installer']