Replace Installer with path parameter in Boot (#4268)
This commit is contained in:
parent
76d6f08841
commit
f19f8d195f
|
|
@ -1,29 +1,28 @@
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
from pathlib import Path
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import TYPE_CHECKING, ClassVar, Self
|
from typing import ClassVar, Self
|
||||||
|
|
||||||
from archinstall.lib.command import SysCommand, SysCommandWorker, locate_binary
|
from archinstall.lib.command import SysCommand, SysCommandWorker, locate_binary
|
||||||
from archinstall.lib.exceptions import SysCallError
|
from archinstall.lib.exceptions import SysCallError
|
||||||
from archinstall.lib.output import error
|
from archinstall.lib.output import error
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from archinstall.lib.installer import Installer
|
|
||||||
|
|
||||||
|
|
||||||
class Boot:
|
class Boot:
|
||||||
_active_boot: ClassVar[Self | None] = None
|
_active_boot: ClassVar[Self | None] = None
|
||||||
|
|
||||||
def __init__(self, installation: Installer):
|
def __init__(self, path: Path | str):
|
||||||
self.instance = installation
|
if isinstance(path, Path):
|
||||||
|
path = str(path)
|
||||||
|
|
||||||
|
self.path = path
|
||||||
self.container_name = 'archinstall'
|
self.container_name = 'archinstall'
|
||||||
self.session: SysCommandWorker | None = None
|
self.session: SysCommandWorker | None = None
|
||||||
self.ready = False
|
self.ready = False
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
def __enter__(self) -> Self:
|
||||||
if Boot._active_boot and Boot._active_boot.instance != self.instance:
|
if Boot._active_boot and Boot._active_boot.path != self.path:
|
||||||
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 Boot._active_boot:
|
if Boot._active_boot:
|
||||||
|
|
@ -36,7 +35,7 @@ class Boot:
|
||||||
[
|
[
|
||||||
'systemd-nspawn',
|
'systemd-nspawn',
|
||||||
'-D',
|
'-D',
|
||||||
str(self.instance.target),
|
self.path,
|
||||||
'--timezone=off',
|
'--timezone=off',
|
||||||
'-b',
|
'-b',
|
||||||
'--no-pager',
|
'--no-pager',
|
||||||
|
|
@ -61,7 +60,7 @@ class Boot:
|
||||||
if exc_type is not None:
|
if exc_type is not None:
|
||||||
error(
|
error(
|
||||||
str(exc_value),
|
str(exc_value),
|
||||||
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
|
f'The error above occurred in a temporary boot-up of the installation {self.path!r}',
|
||||||
)
|
)
|
||||||
|
|
||||||
shutdown = None
|
shutdown = None
|
||||||
|
|
@ -85,7 +84,7 @@ class Boot:
|
||||||
session_exit_code = self.session.exit_code if self.session else -1
|
session_exit_code = self.session.exit_code if self.session else -1
|
||||||
|
|
||||||
raise SysCallError(
|
raise SysCallError(
|
||||||
f'Could not shut down temporary boot of {self.instance}: {session_exit_code}/{shutdown_exit_code}',
|
f'Could not shut down temporary boot of {self.path!r}: {session_exit_code}/{shutdown_exit_code}',
|
||||||
exit_code=next(filter(bool, [session_exit_code, shutdown_exit_code])),
|
exit_code=next(filter(bool, [session_exit_code, shutdown_exit_code])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2020,7 +2020,7 @@ 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.
|
||||||
with Boot(self) as session:
|
with Boot(self.target) as session:
|
||||||
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')
|
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -2046,7 +2046,7 @@ class Installer:
|
||||||
error(f'Invalid x11-keyboard language specified: {language}')
|
error(f'Invalid x11-keyboard language specified: {language}')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with Boot(self) as session:
|
with Boot(self.target) as session:
|
||||||
session.SysCommand(['localectl', 'set-x11-keymap', '""'])
|
session.SysCommand(['localectl', 'set-x11-keymap', '""'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue