Refactor Boot (#4124)
This commit is contained in:
parent
5811f81e59
commit
2e9d5e4829
|
|
@ -1,16 +1,21 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import Self
|
from typing import TYPE_CHECKING, ClassVar, Self
|
||||||
|
|
||||||
from .exceptions import SysCallError
|
from .exceptions import SysCallError
|
||||||
from .general import SysCommand, SysCommandWorker, locate_binary
|
from .general import SysCommand, SysCommandWorker, locate_binary
|
||||||
from .installer import Installer
|
|
||||||
from .output import error
|
from .output import error
|
||||||
from .storage import storage
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .installer import Installer
|
||||||
|
|
||||||
|
|
||||||
class Boot:
|
class Boot:
|
||||||
|
_active_boot: ClassVar[Self | None] = None
|
||||||
|
|
||||||
def __init__(self, installation: Installer):
|
def __init__(self, installation: Installer):
|
||||||
self.instance = installation
|
self.instance = installation
|
||||||
self.container_name = 'archinstall'
|
self.container_name = 'archinstall'
|
||||||
|
|
@ -18,12 +23,12 @@ class Boot:
|
||||||
self.ready = False
|
self.ready = False
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
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.')
|
raise KeyError('Archinstall only supports booting up one instance and another session is already active.')
|
||||||
|
|
||||||
if existing_session:
|
if Boot._active_boot:
|
||||||
self.session = existing_session.session
|
self.session = Boot._active_boot.session
|
||||||
self.ready = existing_session.ready
|
self.ready = Boot._active_boot.ready
|
||||||
else:
|
else:
|
||||||
# '-P' or --console=pipe could help us not having to do a bunch
|
# '-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.
|
# of os.write() calls, but instead use pipes (stdin, stdout and stderr) as usual.
|
||||||
|
|
@ -46,7 +51,7 @@ class Boot:
|
||||||
self.ready = True
|
self.ready = True
|
||||||
break
|
break
|
||||||
|
|
||||||
storage['active_boot'] = self
|
Boot._active_boot = self
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
|
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
|
||||||
|
|
@ -75,7 +80,7 @@ class Boot:
|
||||||
shutdown_exit_code = shutdown.exit_code
|
shutdown_exit_code = shutdown.exit_code
|
||||||
|
|
||||||
if self.session and (self.session.exit_code == 0 or shutdown_exit_code == 0):
|
if self.session and (self.session.exit_code == 0 or shutdown_exit_code == 0):
|
||||||
storage['active_boot'] = None
|
Boot._active_boot = None
|
||||||
else:
|
else:
|
||||||
session_exit_code = self.session.exit_code if self.session else -1
|
session_exit_code = self.session.exit_code if self.session else -1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ from archinstall.lib.translationhandler import tr
|
||||||
from archinstall.tui.curses_menu import Tui
|
from archinstall.tui.curses_menu import Tui
|
||||||
|
|
||||||
from .args import arch_config_handler
|
from .args import arch_config_handler
|
||||||
|
from .boot import Boot
|
||||||
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
|
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
|
||||||
from .general import SysCommand, run
|
from .general import SysCommand, run
|
||||||
from .hardware import SysInfo
|
from .hardware import SysInfo
|
||||||
|
|
@ -1977,8 +1978,6 @@ class Installer:
|
||||||
|
|
||||||
# In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968
|
# 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.
|
# 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:
|
with Boot(self) as session:
|
||||||
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')
|
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')
|
||||||
|
|
||||||
|
|
@ -2005,8 +2004,6 @@ class Installer:
|
||||||
error(f'Invalid x11-keyboard language specified: {language}')
|
error(f'Invalid x11-keyboard language specified: {language}')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
from .boot import Boot
|
|
||||||
|
|
||||||
with Boot(self) as session:
|
with Boot(self) as session:
|
||||||
session.SysCommand(['localectl', 'set-x11-keymap', '""'])
|
session.SysCommand(['localectl', 'set-x11-keymap', '""'])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,10 @@
|
||||||
from typing import TYPE_CHECKING, NotRequired, TypedDict
|
from typing import TYPE_CHECKING, NotRequired, TypedDict
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from archinstall.lib.boot import Boot
|
|
||||||
from archinstall.lib.installer import Installer
|
from archinstall.lib.installer import Installer
|
||||||
|
|
||||||
|
|
||||||
class _StorageDict(TypedDict):
|
class _StorageDict(TypedDict):
|
||||||
active_boot: NotRequired['Boot | None']
|
|
||||||
installation_session: NotRequired['Installer']
|
installation_session: NotRequired['Installer']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue