Skip to content

Commit bdd0099

Browse files
committed
Refactor Boot
1 parent 8f7d59b commit bdd0099

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

archinstall/lib/boot.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1+
from __future__ import annotations
2+
13
import time
24
from collections.abc import Iterator
35
from types import TracebackType
4-
from typing import Self
6+
from typing import TYPE_CHECKING, ClassVar, Self
57

68
from .exceptions import SysCallError
79
from .general import SysCommand, SysCommandWorker, locate_binary
8-
from .installer import Installer
910
from .output import error
10-
from .storage import storage
11+
12+
if TYPE_CHECKING:
13+
from .installer import Installer
1114

1215

1316
class Boot:
17+
_active_boot: ClassVar[Self | None] = None
18+
1419
def __init__(self, installation: Installer):
1520
self.instance = installation
1621
self.container_name = 'archinstall'
1722
self.session: SysCommandWorker | None = None
1823
self.ready = False
1924

2025
def __enter__(self) -> Self:
21-
if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance:
26+
if Boot._active_boot and Boot._active_boot.instance != self.instance:
2227
raise KeyError('Archinstall only supports booting up one instance and another session is already active.')
2328

24-
if existing_session:
25-
self.session = existing_session.session
26-
self.ready = existing_session.ready
29+
if Boot._active_boot:
30+
self.session = Boot._active_boot.session
31+
self.ready = Boot._active_boot.ready
2732
else:
2833
# '-P' or --console=pipe could help us not having to do a bunch
2934
# of os.write() calls, but instead use pipes (stdin, stdout and stderr) as usual.
@@ -46,7 +51,7 @@ def __enter__(self) -> Self:
4651
self.ready = True
4752
break
4853

49-
storage['active_boot'] = self
54+
Boot._active_boot = self
5055
return self
5156

5257
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
7580
shutdown_exit_code = shutdown.exit_code
7681

7782
if self.session and (self.session.exit_code == 0 or shutdown_exit_code == 0):
78-
storage['active_boot'] = None
83+
Boot._active_boot = None
7984
else:
8085
session_exit_code = self.session.exit_code if self.session else -1
8186

archinstall/lib/installer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from archinstall.tui.curses_menu import Tui
3737

3838
from .args import arch_config_handler
39+
from .boot import Boot
3940
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
4041
from .general import SysCommand, run
4142
from .hardware import SysInfo
@@ -1977,8 +1978,6 @@ def set_keyboard_language(self, language: str) -> bool:
19771978

19781979
# In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968
19791980
# Setting an empty keymap first, allows the subsequent call to set layout for both console and x11.
1980-
from .boot import Boot
1981-
19821981
with Boot(self) as session:
19831982
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')
19841983

@@ -2005,8 +2004,6 @@ def set_x11_keyboard_language(self, language: str) -> bool:
20052004
error(f'Invalid x11-keyboard language specified: {language}')
20062005
return False
20072006

2008-
from .boot import Boot
2009-
20102007
with Boot(self) as session:
20112008
session.SysCommand(['localectl', 'set-x11-keymap', '""'])
20122009

archinstall/lib/storage.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
from typing import TYPE_CHECKING, NotRequired, TypedDict
99

1010
if TYPE_CHECKING:
11-
from archinstall.lib.boot import Boot
1211
from archinstall.lib.installer import Installer
1312

1413

1514
class _StorageDict(TypedDict):
16-
active_boot: NotRequired['Boot | None']
1715
installation_session: NotRequired['Installer']
1816

1917

0 commit comments

Comments
 (0)