Replace more Optional instances with union syntax in lib/ (#2841)
This commit is contained in:
parent
57e4362a49
commit
0dc77f8e8a
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .general import SysCommandWorker
|
from .general import SysCommandWorker
|
||||||
|
|
@ -17,7 +17,7 @@ class UnknownFilesystemFormat(Exception):
|
||||||
|
|
||||||
|
|
||||||
class SysCallError(Exception):
|
class SysCallError(Exception):
|
||||||
def __init__(self, message: str, exit_code: Optional[int] = None, worker: Optional['SysCommandWorker'] = None) -> None:
|
def __init__(self, message: str, exit_code: int | None = None, worker: 'SysCommandWorker | None' = None) -> None:
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self.message = message
|
self.message = message
|
||||||
self.exit_code = exit_code
|
self.exit_code = exit_code
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import pathlib
|
||||||
from collections.abc import Callable, Iterator
|
from collections.abc import Callable, Iterator
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional, Any, Union, TYPE_CHECKING
|
from typing import Any, Union, TYPE_CHECKING
|
||||||
from select import epoll, EPOLLIN, EPOLLHUP
|
from select import epoll, EPOLLIN, EPOLLHUP
|
||||||
from shutil import which
|
from shutil import which
|
||||||
|
|
||||||
|
|
@ -104,11 +104,11 @@ class SysCommandWorker:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
cmd: Union[str, list[str]],
|
cmd: Union[str, list[str]],
|
||||||
callbacks: Optional[dict[str, Any]] = None,
|
callbacks: dict[str, Any] | None = None,
|
||||||
peek_output: Optional[bool] = False,
|
peek_output: bool | None = False,
|
||||||
environment_vars: Optional[dict[str, Any]] = None,
|
environment_vars: dict[str, Any] | None = None,
|
||||||
logfile: Optional[None] = None,
|
logfile: None = None,
|
||||||
working_directory: Optional[str] = './',
|
working_directory: str | None = './',
|
||||||
remove_vt100_escape_codes_from_lines: bool = True
|
remove_vt100_escape_codes_from_lines: bool = True
|
||||||
):
|
):
|
||||||
callbacks = callbacks or {}
|
callbacks = callbacks or {}
|
||||||
|
|
@ -129,13 +129,13 @@ class SysCommandWorker:
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
self.working_directory = working_directory
|
self.working_directory = working_directory
|
||||||
|
|
||||||
self.exit_code: Optional[int] = None
|
self.exit_code: int | None = None
|
||||||
self._trace_log = b''
|
self._trace_log = b''
|
||||||
self._trace_log_pos = 0
|
self._trace_log_pos = 0
|
||||||
self.poll_object = epoll()
|
self.poll_object = epoll()
|
||||||
self.child_fd: Optional[int] = None
|
self.child_fd: int | None = None
|
||||||
self.started: Optional[float] = None
|
self.started: float | None = None
|
||||||
self.ended: Optional[float] = None
|
self.ended: float | None = None
|
||||||
self.remove_vt100_escape_codes_from_lines: bool = remove_vt100_escape_codes_from_lines
|
self.remove_vt100_escape_codes_from_lines: bool = remove_vt100_escape_codes_from_lines
|
||||||
|
|
||||||
def __contains__(self, key: bytes) -> bool:
|
def __contains__(self, key: bytes) -> bool:
|
||||||
|
|
@ -349,10 +349,10 @@ class SysCommand:
|
||||||
self,
|
self,
|
||||||
cmd: Union[str, list[str]],
|
cmd: Union[str, list[str]],
|
||||||
callbacks: dict[str, Callable[[Any], Any]] = {},
|
callbacks: dict[str, Callable[[Any], Any]] = {},
|
||||||
start_callback: Optional[Callable[[Any], Any]] = None,
|
start_callback: Callable[[Any], Any] | None = None,
|
||||||
peek_output: Optional[bool] = False,
|
peek_output: bool | None = False,
|
||||||
environment_vars: Optional[dict[str, Any]] = None,
|
environment_vars: dict[str, Any] | None = None,
|
||||||
working_directory: Optional[str] = './',
|
working_directory: str | None = './',
|
||||||
remove_vt100_escape_codes_from_lines: bool = True):
|
remove_vt100_escape_codes_from_lines: bool = True):
|
||||||
|
|
||||||
self._callbacks = callbacks.copy()
|
self._callbacks = callbacks.copy()
|
||||||
|
|
@ -365,10 +365,10 @@ class SysCommand:
|
||||||
self.working_directory = working_directory
|
self.working_directory = working_directory
|
||||||
self.remove_vt100_escape_codes_from_lines = remove_vt100_escape_codes_from_lines
|
self.remove_vt100_escape_codes_from_lines = remove_vt100_escape_codes_from_lines
|
||||||
|
|
||||||
self.session: Optional[SysCommandWorker] = None
|
self.session: SysCommandWorker | None = None
|
||||||
self.create_session()
|
self.create_session()
|
||||||
|
|
||||||
def __enter__(self) -> Optional[SysCommandWorker]:
|
def __enter__(self) -> SysCommandWorker | None:
|
||||||
return self.session
|
return self.session
|
||||||
|
|
||||||
def __exit__(self, *args: str, **kwargs: dict[str, Any]) -> None:
|
def __exit__(self, *args: str, **kwargs: dict[str, Any]) -> None:
|
||||||
|
|
@ -383,7 +383,7 @@ class SysCommand:
|
||||||
for line in self.session:
|
for line in self.session:
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
def __getitem__(self, key: slice) -> Optional[bytes]:
|
def __getitem__(self, key: slice) -> bytes | None:
|
||||||
if not self.session:
|
if not self.session:
|
||||||
raise KeyError("SysCommand() does not have an active session.")
|
raise KeyError("SysCommand() does not have an active session.")
|
||||||
elif type(key) is slice:
|
elif type(key) is slice:
|
||||||
|
|
@ -397,7 +397,7 @@ class SysCommand:
|
||||||
def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str:
|
def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str:
|
||||||
return self.decode('UTF-8', errors='backslashreplace') or ''
|
return self.decode('UTF-8', errors='backslashreplace') or ''
|
||||||
|
|
||||||
def __json__(self) -> dict[str, Union[str, bool, list[str], dict[str, Any], Optional[bool], Optional[dict[str, Any]]]]:
|
def __json__(self) -> dict[str, Union[str, bool, list[str], dict[str, Any], bool | None, dict[str, Any] | None]]:
|
||||||
return {
|
return {
|
||||||
'cmd': self.cmd,
|
'cmd': self.cmd,
|
||||||
'callbacks': self._callbacks,
|
'callbacks': self._callbacks,
|
||||||
|
|
@ -454,14 +454,14 @@ class SysCommand:
|
||||||
return self.session._trace_log
|
return self.session._trace_log
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def exit_code(self) -> Optional[int]:
|
def exit_code(self) -> int | None:
|
||||||
if self.session:
|
if self.session:
|
||||||
return self.session.exit_code
|
return self.session.exit_code
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def trace_log(self) -> Optional[bytes]:
|
def trace_log(self) -> bytes | None:
|
||||||
if self.session:
|
if self.session:
|
||||||
return self.session._trace_log
|
return self.session._trace_log
|
||||||
return None
|
return None
|
||||||
|
|
@ -496,7 +496,7 @@ def json_stream_to_structure(configuration_identifier: str, stream: str, target:
|
||||||
+configuration_identifier is just a parameter to get meaningful, but not so long messages
|
+configuration_identifier is just a parameter to get meaningful, but not so long messages
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raw: Optional[str] = None
|
raw: str | None = None
|
||||||
# Try using the stream as a URL that should be grabbed
|
# Try using the stream as a URL that should be grabbed
|
||||||
if urllib.parse.urlparse(stream).scheme:
|
if urllib.parse.urlparse(stream).scheme:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Optional, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from . import disk
|
from . import disk
|
||||||
from .general import secret
|
from .general import secret
|
||||||
|
|
@ -275,8 +275,8 @@ class GlobalMenu(AbstractMenu):
|
||||||
if o.key is not None:
|
if o.key is not None:
|
||||||
self._item_group.find_by_key(o.key).text = o.text
|
self._item_group.find_by_key(o.key).text = o.text
|
||||||
|
|
||||||
def _disk_encryption(self, preset: Optional[disk.DiskEncryption]) -> Optional[disk.DiskEncryption]:
|
def _disk_encryption(self, preset: disk.DiskEncryption | None) -> disk.DiskEncryption | None:
|
||||||
disk_config: Optional[disk.DiskLayoutConfiguration] = self._item_group.find_by_key('disk_config').value
|
disk_config: disk.DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
|
||||||
|
|
||||||
if not disk_config:
|
if not disk_config:
|
||||||
# this should not happen as the encryption menu has the disk_config as dependency
|
# this should not happen as the encryption menu has the disk_config as dependency
|
||||||
|
|
@ -292,14 +292,14 @@ class GlobalMenu(AbstractMenu):
|
||||||
locale_config = LocaleMenu(preset).run()
|
locale_config = LocaleMenu(preset).run()
|
||||||
return locale_config
|
return locale_config
|
||||||
|
|
||||||
def _prev_locale(self, item: MenuItem) -> Optional[str]:
|
def _prev_locale(self, item: MenuItem) -> str | None:
|
||||||
if not item.value:
|
if not item.value:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
config: LocaleConfiguration = item.value
|
config: LocaleConfiguration = item.value
|
||||||
return config.preview()
|
return config.preview()
|
||||||
|
|
||||||
def _prev_network_config(self, item: MenuItem) -> Optional[str]:
|
def _prev_network_config(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
network_config: NetworkConfiguration = item.value
|
network_config: NetworkConfiguration = item.value
|
||||||
if network_config.type == NicType.MANUAL:
|
if network_config.type == NicType.MANUAL:
|
||||||
|
|
@ -310,31 +310,31 @@ class GlobalMenu(AbstractMenu):
|
||||||
return output
|
return output
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_additional_pkgs(self, item: MenuItem) -> Optional[str]:
|
def _prev_additional_pkgs(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
return format_cols(item.value, None)
|
return format_cols(item.value, None)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_additional_repos(self, item: MenuItem) -> Optional[str]:
|
def _prev_additional_repos(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
repos = ', '.join(item.value)
|
repos = ', '.join(item.value)
|
||||||
return f'{_("Additional repositories")}: {repos}'
|
return f'{_("Additional repositories")}: {repos}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_tz(self, item: MenuItem) -> Optional[str]:
|
def _prev_tz(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
return f'{_("Timezone")}: {item.value}'
|
return f'{_("Timezone")}: {item.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_ntp(self, item: MenuItem) -> Optional[str]:
|
def _prev_ntp(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
output = f'{_("NTP")}: '
|
output = f'{_("NTP")}: '
|
||||||
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
||||||
return output
|
return output
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_disk_config(self, item: MenuItem) -> Optional[str]:
|
def _prev_disk_config(self, item: MenuItem) -> str | None:
|
||||||
disk_layout_conf: Optional[disk.DiskLayoutConfiguration] = item.value
|
disk_layout_conf: disk.DiskLayoutConfiguration | None = item.value
|
||||||
|
|
||||||
if disk_layout_conf:
|
if disk_layout_conf:
|
||||||
output = str(_('Configuration type: {}')).format(disk_layout_conf.config_type.display_msg()) + '\n'
|
output = str(_('Configuration type: {}')).format(disk_layout_conf.config_type.display_msg()) + '\n'
|
||||||
|
|
@ -349,55 +349,55 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_swap(self, item: MenuItem) -> Optional[str]:
|
def _prev_swap(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
output = f'{_("Swap on zram")}: '
|
output = f'{_("Swap on zram")}: '
|
||||||
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
||||||
return output
|
return output
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_uki(self, item: MenuItem) -> Optional[str]:
|
def _prev_uki(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
output = f'{str(_('Unified kernel images'))}: '
|
output = f'{str(_('Unified kernel images'))}: '
|
||||||
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
output += str(_('Enabled')) if item.value else str(_('Disabled'))
|
||||||
return output
|
return output
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_hostname(self, item: MenuItem) -> Optional[str]:
|
def _prev_hostname(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
return f'{_("Hostname")}: {item.value}'
|
return f'{_("Hostname")}: {item.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_root_pwd(self, item: MenuItem) -> Optional[str]:
|
def _prev_root_pwd(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
return f'{_("Root password")}: {secret(item.value)}'
|
return f'{_("Root password")}: {secret(item.value)}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_audio(self, item: MenuItem) -> Optional[str]:
|
def _prev_audio(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
config: AudioConfiguration = item.value
|
config: AudioConfiguration = item.value
|
||||||
return f'{_("Audio")}: {config.audio.value}'
|
return f'{_("Audio")}: {config.audio.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_parallel_dw(self, item: MenuItem) -> Optional[str]:
|
def _prev_parallel_dw(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
return f'{_("Parallel Downloads")}: {item.value}'
|
return f'{_("Parallel Downloads")}: {item.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_kernel(self, item: MenuItem) -> Optional[str]:
|
def _prev_kernel(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
kernel = ', '.join(item.value)
|
kernel = ', '.join(item.value)
|
||||||
return f'{_("Kernel")}: {kernel}'
|
return f'{_("Kernel")}: {kernel}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_bootloader(self, item: MenuItem) -> Optional[str]:
|
def _prev_bootloader(self, item: MenuItem) -> str | None:
|
||||||
if item.value is not None:
|
if item.value is not None:
|
||||||
return f'{_("Bootloader")}: {item.value.value}'
|
return f'{_("Bootloader")}: {item.value.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_disk_encryption(self, item: MenuItem) -> Optional[str]:
|
def _prev_disk_encryption(self, item: MenuItem) -> str | None:
|
||||||
disk_config: Optional[disk.DiskLayoutConfiguration] = self._item_group.find_by_key('disk_config').value
|
disk_config: disk.DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
|
||||||
enc_config: Optional[disk.DiskEncryption] = item.value
|
enc_config: disk.DiskEncryption | None = item.value
|
||||||
|
|
||||||
if disk_config and not disk.DiskEncryption.validate_enc(disk_config):
|
if disk_config and not disk.DiskEncryption.validate_enc(disk_config):
|
||||||
return str(_('LVM disk encryption with more than 2 partitions is currently not supported'))
|
return str(_('LVM disk encryption with more than 2 partitions is currently not supported'))
|
||||||
|
|
@ -419,7 +419,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _validate_bootloader(self) -> Optional[str]:
|
def _validate_bootloader(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
Checks the selected bootloader is valid for the selected filesystem
|
Checks the selected bootloader is valid for the selected filesystem
|
||||||
type of the boot partition.
|
type of the boot partition.
|
||||||
|
|
@ -431,7 +431,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
shim if necessary.
|
shim if necessary.
|
||||||
"""
|
"""
|
||||||
bootloader = self._item_group.find_by_key('bootloader').value
|
bootloader = self._item_group.find_by_key('bootloader').value
|
||||||
boot_partition: Optional[disk.PartitionModification] = None
|
boot_partition: disk.PartitionModification | None = None
|
||||||
|
|
||||||
if disk_config := self._item_group.find_by_key('disk_config').value:
|
if disk_config := self._item_group.find_by_key('disk_config').value:
|
||||||
for layout in disk_config.device_modifications:
|
for layout in disk_config.device_modifications:
|
||||||
|
|
@ -449,7 +449,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_install_invalid_config(self, item: MenuItem) -> Optional[str]:
|
def _prev_install_invalid_config(self, item: MenuItem) -> str | None:
|
||||||
if missing := self._missing_configs():
|
if missing := self._missing_configs():
|
||||||
text = str(_('Missing configurations:\n'))
|
text = str(_('Missing configurations:\n'))
|
||||||
for m in missing:
|
for m in missing:
|
||||||
|
|
@ -461,15 +461,15 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_users(self, item: MenuItem) -> Optional[str]:
|
def _prev_users(self, item: MenuItem) -> str | None:
|
||||||
users: Optional[list[User]] = item.value
|
users: list[User] | None = item.value
|
||||||
|
|
||||||
if users:
|
if users:
|
||||||
return FormattedOutput.as_table(users)
|
return FormattedOutput.as_table(users)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_profile(self, item: MenuItem) -> Optional[str]:
|
def _prev_profile(self, item: MenuItem) -> str | None:
|
||||||
profile_config: Optional[ProfileConfiguration] = item.value
|
profile_config: ProfileConfiguration | None = item.value
|
||||||
|
|
||||||
if profile_config and profile_config.profile:
|
if profile_config and profile_config.profile:
|
||||||
output = str(_('Profiles')) + ': '
|
output = str(_('Profiles')) + ': '
|
||||||
|
|
@ -488,14 +488,14 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _set_root_password(self, preset: Optional[str] = None) -> Optional[str]:
|
def _set_root_password(self, preset: str | None = None) -> str | None:
|
||||||
password = get_password(text=str(_('Root password')), allow_skip=True)
|
password = get_password(text=str(_('Root password')), allow_skip=True)
|
||||||
return password
|
return password
|
||||||
|
|
||||||
def _select_disk_config(
|
def _select_disk_config(
|
||||||
self,
|
self,
|
||||||
preset: Optional[disk.DiskLayoutConfiguration] = None
|
preset: disk.DiskLayoutConfiguration | None = None
|
||||||
) -> Optional[disk.DiskLayoutConfiguration]:
|
) -> disk.DiskLayoutConfiguration | None:
|
||||||
disk_config = disk.DiskLayoutConfigurationMenu(preset).run()
|
disk_config = disk.DiskLayoutConfigurationMenu(preset).run()
|
||||||
|
|
||||||
if disk_config != preset:
|
if disk_config != preset:
|
||||||
|
|
@ -503,7 +503,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return disk_config
|
return disk_config
|
||||||
|
|
||||||
def _select_bootloader(self, preset: Optional[Bootloader]) -> Optional[Bootloader]:
|
def _select_bootloader(self, preset: Bootloader | None) -> Bootloader | None:
|
||||||
bootloader = ask_for_bootloader(preset)
|
bootloader = ask_for_bootloader(preset)
|
||||||
|
|
||||||
if bootloader:
|
if bootloader:
|
||||||
|
|
@ -516,21 +516,21 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
return bootloader
|
return bootloader
|
||||||
|
|
||||||
def _select_profile(self, current_profile: Optional[ProfileConfiguration]):
|
def _select_profile(self, current_profile: ProfileConfiguration | None):
|
||||||
from .profile.profile_menu import ProfileMenu
|
from .profile.profile_menu import ProfileMenu
|
||||||
profile_config = ProfileMenu(preset=current_profile).run()
|
profile_config = ProfileMenu(preset=current_profile).run()
|
||||||
return profile_config
|
return profile_config
|
||||||
|
|
||||||
def _create_user_account(self, preset: Optional[list[User]] = None) -> list[User]:
|
def _create_user_account(self, preset: list[User] | None = None) -> list[User]:
|
||||||
preset = [] if preset is None else preset
|
preset = [] if preset is None else preset
|
||||||
users = ask_for_additional_users(defined_users=preset)
|
users = ask_for_additional_users(defined_users=preset)
|
||||||
return users
|
return users
|
||||||
|
|
||||||
def _mirror_configuration(self, preset: Optional[MirrorConfiguration] = None) -> Optional[MirrorConfiguration]:
|
def _mirror_configuration(self, preset: MirrorConfiguration | None = None) -> MirrorConfiguration | None:
|
||||||
mirror_configuration = MirrorMenu(preset=preset).run()
|
mirror_configuration = MirrorMenu(preset=preset).run()
|
||||||
return mirror_configuration
|
return mirror_configuration
|
||||||
|
|
||||||
def _prev_mirror_config(self, item: MenuItem) -> Optional[str]:
|
def _prev_mirror_config(self, item: MenuItem) -> str | None:
|
||||||
if not item.value:
|
if not item.value:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from .. import disk
|
from .. import disk
|
||||||
from ..disk.device_model import BtrfsMountOption
|
from ..disk.device_model import BtrfsMountOption
|
||||||
|
|
@ -22,8 +21,8 @@ if TYPE_CHECKING:
|
||||||
_: Any
|
_: Any
|
||||||
|
|
||||||
|
|
||||||
def select_devices(preset: Optional[list[disk.BDevice]] = []) -> list[disk.BDevice]:
|
def select_devices(preset: list[disk.BDevice] | None = []) -> list[disk.BDevice]:
|
||||||
def _preview_device_selection(selection: disk._DeviceInfo) -> Optional[str]:
|
def _preview_device_selection(selection: disk._DeviceInfo) -> str | None:
|
||||||
dev = disk.device_handler.get_device(selection.path)
|
dev = disk.device_handler.get_device(selection.path)
|
||||||
if dev and dev.partition_infos:
|
if dev and dev.partition_infos:
|
||||||
return FormattedOutput.as_table(dev.partition_infos)
|
return FormattedOutput.as_table(dev.partition_infos)
|
||||||
|
|
@ -62,7 +61,7 @@ def select_devices(preset: Optional[list[disk.BDevice]] = []) -> list[disk.BDevi
|
||||||
|
|
||||||
def get_default_partition_layout(
|
def get_default_partition_layout(
|
||||||
devices: list[disk.BDevice],
|
devices: list[disk.BDevice],
|
||||||
filesystem_type: Optional[disk.FilesystemType] = None,
|
filesystem_type: disk.FilesystemType | None = None,
|
||||||
advanced_option: bool = False
|
advanced_option: bool = False
|
||||||
) -> list[disk.DeviceModification]:
|
) -> list[disk.DeviceModification]:
|
||||||
if len(devices) == 1:
|
if len(devices) == 1:
|
||||||
|
|
@ -98,9 +97,9 @@ def _manual_partitioning(
|
||||||
|
|
||||||
|
|
||||||
def select_disk_config(
|
def select_disk_config(
|
||||||
preset: Optional[disk.DiskLayoutConfiguration] = None,
|
preset: disk.DiskLayoutConfiguration | None = None,
|
||||||
advanced_option: bool = False
|
advanced_option: bool = False
|
||||||
) -> Optional[disk.DiskLayoutConfiguration]:
|
) -> disk.DiskLayoutConfiguration | None:
|
||||||
default_layout = disk.DiskLayoutType.Default.display_msg()
|
default_layout = disk.DiskLayoutType.Default.display_msg()
|
||||||
manual_mode = disk.DiskLayoutType.Manual.display_msg()
|
manual_mode = disk.DiskLayoutType.Manual.display_msg()
|
||||||
pre_mount_mode = disk.DiskLayoutType.Pre_mount.display_msg()
|
pre_mount_mode = disk.DiskLayoutType.Pre_mount.display_msg()
|
||||||
|
|
@ -174,8 +173,8 @@ def select_disk_config(
|
||||||
|
|
||||||
def select_lvm_config(
|
def select_lvm_config(
|
||||||
disk_config: disk.DiskLayoutConfiguration,
|
disk_config: disk.DiskLayoutConfiguration,
|
||||||
preset: Optional[disk.LvmConfiguration] = None,
|
preset: disk.LvmConfiguration | None = None,
|
||||||
) -> Optional[disk.LvmConfiguration]:
|
) -> disk.LvmConfiguration | None:
|
||||||
preset_value = preset.config_type.display_msg() if preset else None
|
preset_value = preset.config_type.display_msg() if preset else None
|
||||||
default_mode = disk.LvmLayoutType.Default.display_msg()
|
default_mode = disk.LvmLayoutType.Default.display_msg()
|
||||||
|
|
||||||
|
|
@ -292,9 +291,9 @@ def process_root_partition_size(total_size: disk.Size, sector_size: disk.SectorS
|
||||||
|
|
||||||
def suggest_single_disk_layout(
|
def suggest_single_disk_layout(
|
||||||
device: disk.BDevice,
|
device: disk.BDevice,
|
||||||
filesystem_type: Optional[disk.FilesystemType] = None,
|
filesystem_type: disk.FilesystemType | None = None,
|
||||||
advanced_options: bool = False,
|
advanced_options: bool = False,
|
||||||
separate_home: Optional[bool] = None
|
separate_home: bool | None = None
|
||||||
) -> disk.DeviceModification:
|
) -> disk.DeviceModification:
|
||||||
if not filesystem_type:
|
if not filesystem_type:
|
||||||
filesystem_type = select_main_filesystem_format(advanced_options)
|
filesystem_type = select_main_filesystem_format(advanced_options)
|
||||||
|
|
@ -424,7 +423,7 @@ def suggest_single_disk_layout(
|
||||||
|
|
||||||
def suggest_multi_disk_layout(
|
def suggest_multi_disk_layout(
|
||||||
devices: list[disk.BDevice],
|
devices: list[disk.BDevice],
|
||||||
filesystem_type: Optional[disk.FilesystemType] = None,
|
filesystem_type: disk.FilesystemType | None = None,
|
||||||
advanced_options: bool = False
|
advanced_options: bool = False
|
||||||
) -> list[disk.DeviceModification]:
|
) -> list[disk.DeviceModification]:
|
||||||
if not devices:
|
if not devices:
|
||||||
|
|
@ -453,7 +452,7 @@ def suggest_multi_disk_layout(
|
||||||
devices_delta[device] = delta
|
devices_delta[device] = delta
|
||||||
|
|
||||||
sorted_delta: list[tuple[disk.BDevice, Any]] = sorted(devices_delta.items(), key=lambda x: x[1])
|
sorted_delta: list[tuple[disk.BDevice, Any]] = sorted(devices_delta.items(), key=lambda x: x[1])
|
||||||
root_device: Optional[disk.BDevice] = sorted_delta[0][0]
|
root_device: disk.BDevice | None = sorted_delta[0][0]
|
||||||
|
|
||||||
if home_device is None or root_device is None:
|
if home_device is None or root_device is None:
|
||||||
text = str(_('The selected drives do not have the minimum capacity required for an automatic suggestion\n'))
|
text = str(_('The selected drives do not have the minimum capacity required for an automatic suggestion\n'))
|
||||||
|
|
@ -531,7 +530,7 @@ def suggest_multi_disk_layout(
|
||||||
|
|
||||||
def suggest_lvm_layout(
|
def suggest_lvm_layout(
|
||||||
disk_config: disk.DiskLayoutConfiguration,
|
disk_config: disk.DiskLayoutConfiguration,
|
||||||
filesystem_type: Optional[disk.FilesystemType] = None,
|
filesystem_type: disk.FilesystemType | None = None,
|
||||||
vg_grp_name: str = 'ArchinstallVg',
|
vg_grp_name: str = 'ArchinstallVg',
|
||||||
) -> disk.LvmConfiguration:
|
) -> disk.LvmConfiguration:
|
||||||
if disk_config.config_type != disk.DiskLayoutType.Default:
|
if disk_config.config_type != disk.DiskLayoutType.Default:
|
||||||
|
|
@ -574,7 +573,7 @@ def suggest_lvm_layout(
|
||||||
|
|
||||||
home_volume = False
|
home_volume = False
|
||||||
|
|
||||||
boot_part: Optional[disk.PartitionModification] = None
|
boot_part: disk.PartitionModification | None = None
|
||||||
other_part: list[disk.PartitionModification] = []
|
other_part: list[disk.PartitionModification] = []
|
||||||
|
|
||||||
for mod in disk_config.device_modifications:
|
for mod in disk_config.device_modifications:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Any, Optional, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from ..locale import list_timezones
|
from ..locale import list_timezones
|
||||||
from ..models.audio_configuration import Audio, AudioConfiguration
|
from ..models.audio_configuration import Audio, AudioConfiguration
|
||||||
|
|
@ -45,7 +45,7 @@ def ask_ntp(preset: bool = True) -> bool:
|
||||||
raise ValueError('Unhandled return type')
|
raise ValueError('Unhandled return type')
|
||||||
|
|
||||||
|
|
||||||
def ask_hostname(preset: Optional[str] = None) -> Optional[str]:
|
def ask_hostname(preset: str | None = None) -> str | None:
|
||||||
result = EditMenu(
|
result = EditMenu(
|
||||||
str(_('Hostname')),
|
str(_('Hostname')),
|
||||||
alignment=Alignment.CENTER,
|
alignment=Alignment.CENTER,
|
||||||
|
|
@ -65,7 +65,7 @@ def ask_hostname(preset: Optional[str] = None) -> Optional[str]:
|
||||||
raise ValueError('Unhandled result type')
|
raise ValueError('Unhandled result type')
|
||||||
|
|
||||||
|
|
||||||
def ask_for_a_timezone(preset: Optional[str] = None) -> Optional[str]:
|
def ask_for_a_timezone(preset: str | None = None) -> str | None:
|
||||||
default = 'UTC'
|
default = 'UTC'
|
||||||
timezones = list_timezones()
|
timezones = list_timezones()
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ def ask_for_a_timezone(preset: Optional[str] = None) -> Optional[str]:
|
||||||
return result.get_value()
|
return result.get_value()
|
||||||
|
|
||||||
|
|
||||||
def ask_for_audio_selection(preset: Optional[AudioConfiguration] = None) -> Optional[AudioConfiguration]:
|
def ask_for_audio_selection(preset: AudioConfiguration | None = None) -> AudioConfiguration | None:
|
||||||
items = [MenuItem(a.value, value=a) for a in Audio]
|
items = [MenuItem(a.value, value=a) for a in Audio]
|
||||||
group = MenuItemGroup(items)
|
group = MenuItemGroup(items)
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ def ask_for_audio_selection(preset: Optional[AudioConfiguration] = None) -> Opti
|
||||||
raise ValueError('Unhandled result type')
|
raise ValueError('Unhandled result type')
|
||||||
|
|
||||||
|
|
||||||
def select_language(preset: Optional[str] = None) -> Optional[str]:
|
def select_language(preset: str | None = None) -> str | None:
|
||||||
from ..locale.locale_menu import select_kb_layout
|
from ..locale.locale_menu import select_kb_layout
|
||||||
|
|
||||||
# We'll raise an exception in an upcoming version.
|
# We'll raise an exception in an upcoming version.
|
||||||
|
|
@ -165,7 +165,7 @@ def ask_additional_packages_to_install(preset: list[str] = []) -> list[str]:
|
||||||
header += str(_('If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.')) + '\n'
|
header += str(_('If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.')) + '\n'
|
||||||
header += str(_('Write additional packages to install (space separated, leave blank to skip)'))
|
header += str(_('Write additional packages to install (space separated, leave blank to skip)'))
|
||||||
|
|
||||||
def validator(value: str) -> Optional[str]:
|
def validator(value: str) -> str | None:
|
||||||
packages = value.split() if value else []
|
packages = value.split() if value else []
|
||||||
|
|
||||||
if len(packages) == 0:
|
if len(packages) == 0:
|
||||||
|
|
@ -204,7 +204,7 @@ def ask_additional_packages_to_install(preset: list[str] = []) -> list[str]:
|
||||||
return packages.split(' ')
|
return packages.split(' ')
|
||||||
|
|
||||||
|
|
||||||
def add_number_of_parallel_downloads(preset: Optional[int] = None) -> Optional[int]:
|
def add_number_of_parallel_downloads(preset: int | None = None) -> int | None:
|
||||||
max_recommended = 5
|
max_recommended = 5
|
||||||
|
|
||||||
header = str(_('This option enables the number of parallel downloads that can occur during package downloads')) + '\n'
|
header = str(_('This option enables the number of parallel downloads that can occur during package downloads')) + '\n'
|
||||||
|
|
@ -212,7 +212,7 @@ def add_number_of_parallel_downloads(preset: Optional[int] = None) -> Optional[i
|
||||||
header += str(_(' - Maximum recommended value : {} ( Allows {} parallel downloads at a time )')).format(max_recommended, max_recommended) + '\n'
|
header += str(_(' - Maximum recommended value : {} ( Allows {} parallel downloads at a time )')).format(max_recommended, max_recommended) + '\n'
|
||||||
header += str(_(' - Disable/Default : 0 ( Disables parallel downloading, allows only 1 download at a time )\n'))
|
header += str(_(' - Disable/Default : 0 ( Disables parallel downloading, allows only 1 download at a time )\n'))
|
||||||
|
|
||||||
def validator(s: str) -> Optional[str]:
|
def validator(s: str) -> str | None:
|
||||||
try:
|
try:
|
||||||
value = int(s)
|
value = int(s)
|
||||||
if value >= 0:
|
if value >= 0:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, TYPE_CHECKING, Optional
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from ..hardware import SysInfo, GfxDriver
|
from ..hardware import SysInfo, GfxDriver
|
||||||
from ..models.bootloader import Bootloader
|
from ..models.bootloader import Bootloader
|
||||||
|
|
@ -50,7 +50,7 @@ def select_kernel(preset: list[str] = []) -> list[str]:
|
||||||
return result.get_values()
|
return result.get_values()
|
||||||
|
|
||||||
|
|
||||||
def ask_for_bootloader(preset: Optional[Bootloader]) -> Optional[Bootloader]:
|
def ask_for_bootloader(preset: Bootloader | None) -> Bootloader | None:
|
||||||
# Systemd is UEFI only
|
# Systemd is UEFI only
|
||||||
if not SysInfo.has_uefi():
|
if not SysInfo.has_uefi():
|
||||||
options = [Bootloader.Grub, Bootloader.Limine]
|
options = [Bootloader.Grub, Bootloader.Limine]
|
||||||
|
|
@ -106,7 +106,7 @@ def ask_for_uki(preset: bool = True) -> bool:
|
||||||
raise ValueError('Unhandled result type')
|
raise ValueError('Unhandled result type')
|
||||||
|
|
||||||
|
|
||||||
def select_driver(options: list[GfxDriver] = [], preset: Optional[GfxDriver] = None) -> Optional[GfxDriver]:
|
def select_driver(options: list[GfxDriver] = [], preset: GfxDriver | None = None) -> GfxDriver | None:
|
||||||
"""
|
"""
|
||||||
Some what convoluted function, whose job is simple.
|
Some what convoluted function, whose job is simple.
|
||||||
Select a graphics driver from a pre-defined set of popular options.
|
Select a graphics driver from a pre-defined set of popular options.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, TYPE_CHECKING, Optional
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from .utils import list_keyboard_languages, list_locales, set_kb_layout, get_kb_layout
|
from .utils import list_keyboard_languages, list_locales, set_kb_layout, get_kb_layout
|
||||||
from ..menu import AbstractSubMenu
|
from ..menu import AbstractSubMenu
|
||||||
|
|
@ -99,7 +99,7 @@ class LocaleMenu(AbstractSubMenu):
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
def _prev_locale(self, item: MenuItem) -> Optional[str]:
|
def _prev_locale(self, item: MenuItem) -> str | None:
|
||||||
temp_locale = LocaleConfiguration(
|
temp_locale = LocaleConfiguration(
|
||||||
self._menu_item_group.find_by_key('keyboard-layout').get_value(),
|
self._menu_item_group.find_by_key('keyboard-layout').get_value(),
|
||||||
self._menu_item_group.find_by_key('sys-language').get_value(),
|
self._menu_item_group.find_by_key('sys-language').get_value(),
|
||||||
|
|
@ -119,14 +119,14 @@ class LocaleMenu(AbstractSubMenu):
|
||||||
self._data_store['sys-encoding']
|
self._data_store['sys-encoding']
|
||||||
)
|
)
|
||||||
|
|
||||||
def _select_kb_layout(self, preset: Optional[str]) -> Optional[str]:
|
def _select_kb_layout(self, preset: str | None) -> str | None:
|
||||||
kb_lang = select_kb_layout(preset)
|
kb_lang = select_kb_layout(preset)
|
||||||
if kb_lang:
|
if kb_lang:
|
||||||
set_kb_layout(kb_lang)
|
set_kb_layout(kb_lang)
|
||||||
return kb_lang
|
return kb_lang
|
||||||
|
|
||||||
|
|
||||||
def select_locale_lang(preset: Optional[str] = None) -> Optional[str]:
|
def select_locale_lang(preset: str | None = None) -> str | None:
|
||||||
locales = list_locales()
|
locales = list_locales()
|
||||||
locale_lang = set([locale.split()[0] for locale in locales])
|
locale_lang = set([locale.split()[0] for locale in locales])
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ def select_locale_lang(preset: Optional[str] = None) -> Optional[str]:
|
||||||
raise ValueError('Unhandled return type')
|
raise ValueError('Unhandled return type')
|
||||||
|
|
||||||
|
|
||||||
def select_locale_enc(preset: Optional[str] = None) -> Optional[str]:
|
def select_locale_enc(preset: str | None = None) -> str | None:
|
||||||
locales = list_locales()
|
locales = list_locales()
|
||||||
locale_enc = set([locale.split()[1] for locale in locales])
|
locale_enc = set([locale.split()[1] for locale in locales])
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ def select_locale_enc(preset: Optional[str] = None) -> Optional[str]:
|
||||||
raise ValueError('Unhandled return type')
|
raise ValueError('Unhandled return type')
|
||||||
|
|
||||||
|
|
||||||
def select_kb_layout(preset: Optional[str] = None) -> Optional[str]:
|
def select_kb_layout(preset: str | None = None) -> str | None:
|
||||||
"""
|
"""
|
||||||
Select keyboard layout
|
Select keyboard layout
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from typing import Any, Optional, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from ..output import error
|
from ..output import error
|
||||||
from ..output import unicode_ljust
|
from ..output import unicode_ljust
|
||||||
|
|
@ -19,14 +19,14 @@ class Selector:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
description: str,
|
description: str,
|
||||||
func: Optional[Callable[[Any], Any]] = None,
|
func: Callable[[Any], Any] | None = None,
|
||||||
display_func: Optional[Callable] = None,
|
display_func: Callable | None = None,
|
||||||
default: Optional[Any] = None,
|
default: Any | None = None,
|
||||||
enabled: bool = False,
|
enabled: bool = False,
|
||||||
dependencies: list[str] = [],
|
dependencies: list[str] = [],
|
||||||
dependencies_not: list[str] = [],
|
dependencies_not: list[str] = [],
|
||||||
exec_func: Optional[Callable] = None,
|
exec_func: Callable | None = None,
|
||||||
preview_func: Optional[Callable] = None,
|
preview_func: Callable | None = None,
|
||||||
mandatory: bool = False,
|
mandatory: bool = False,
|
||||||
no_store: bool = False
|
no_store: bool = False
|
||||||
):
|
):
|
||||||
|
|
@ -117,7 +117,7 @@ class Selector:
|
||||||
|
|
||||||
return f'{description} {current}'
|
return f'{description} {current}'
|
||||||
|
|
||||||
def set_current_selection(self, current: Optional[Any]) -> None:
|
def set_current_selection(self, current: Any | None) -> None:
|
||||||
self.current_selection = current
|
self.current_selection = current
|
||||||
|
|
||||||
def has_selection(self) -> bool:
|
def has_selection(self) -> bool:
|
||||||
|
|
@ -152,7 +152,7 @@ class AbstractMenu:
|
||||||
data_store: dict[str, Any],
|
data_store: dict[str, Any],
|
||||||
auto_cursor: bool = True,
|
auto_cursor: bool = True,
|
||||||
allow_reset: bool = False,
|
allow_reset: bool = False,
|
||||||
reset_warning: Optional[str] = None
|
reset_warning: str | None = None
|
||||||
):
|
):
|
||||||
self._menu_item_group = item_group
|
self._menu_item_group = item_group
|
||||||
self._data_store = data_store
|
self._data_store = data_store
|
||||||
|
|
@ -211,7 +211,7 @@ class AbstractMenu:
|
||||||
for item in self._menu_item_group.items:
|
for item in self._menu_item_group.items:
|
||||||
item.enabled = False
|
item.enabled = False
|
||||||
|
|
||||||
def run(self) -> Optional[Any]:
|
def run(self) -> Any | None:
|
||||||
self._sync_all_from_ds()
|
self._sync_all_from_ds()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import http.client
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from ..networking import ping, DownloadTimer
|
from ..networking import ping, DownloadTimer
|
||||||
from ..output import debug
|
from ..output import debug
|
||||||
|
|
@ -89,7 +88,7 @@ class MirrorStatusEntryV3(BaseModel):
|
||||||
return self._latency
|
return self._latency
|
||||||
|
|
||||||
@field_validator('score', mode='before')
|
@field_validator('score', mode='before')
|
||||||
def validate_score(cls, value: int) -> Optional[int]:
|
def validate_score(cls, value: int) -> int | None:
|
||||||
if value is not None:
|
if value is not None:
|
||||||
value = round(value)
|
value = round(value)
|
||||||
debug(f" score: {value}")
|
debug(f" score: {value}")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional, Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from ..profile import ProfileConfiguration
|
from ..profile import ProfileConfiguration
|
||||||
|
|
||||||
|
|
@ -27,10 +27,10 @@ class NicType(Enum):
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Nic:
|
class Nic:
|
||||||
iface: Optional[str] = None
|
iface: str | None = None
|
||||||
ip: Optional[str] = None
|
ip: str | None = None
|
||||||
dhcp: bool = True
|
dhcp: bool = True
|
||||||
gateway: Optional[str] = None
|
gateway: str | None = None
|
||||||
dns: list[str] = field(default_factory=list)
|
dns: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
def table_data(self) -> dict[str, Any]:
|
def table_data(self) -> dict[str, Any]:
|
||||||
|
|
@ -102,7 +102,7 @@ class NetworkConfiguration:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_arg(config: dict[str, Any]) -> Optional[NetworkConfiguration]:
|
def parse_arg(config: dict[str, Any]) -> NetworkConfiguration | None:
|
||||||
nic_type = config.get('type', None)
|
nic_type = config.get('type', None)
|
||||||
if not nic_type:
|
if not nic_type:
|
||||||
return None
|
return None
|
||||||
|
|
@ -123,7 +123,7 @@ class NetworkConfiguration:
|
||||||
def install_network_config(
|
def install_network_config(
|
||||||
self,
|
self,
|
||||||
installation: Any,
|
installation: Any,
|
||||||
profile_config: Optional[ProfileConfiguration] = None
|
profile_config: ProfileConfiguration | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
match self.type:
|
match self.type:
|
||||||
case NicType.ISO:
|
case NicType.ISO:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, Optional
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from archinstall.default_profiles.profile import Profile, GreeterType
|
from archinstall.default_profiles.profile import Profile, GreeterType
|
||||||
from .profile_model import ProfileConfiguration
|
from .profile_model import ProfileConfiguration
|
||||||
|
|
@ -21,7 +21,7 @@ if TYPE_CHECKING:
|
||||||
class ProfileMenu(AbstractSubMenu):
|
class ProfileMenu(AbstractSubMenu):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
preset: Optional[ProfileConfiguration] = None
|
preset: ProfileConfiguration | None = None
|
||||||
):
|
):
|
||||||
if preset:
|
if preset:
|
||||||
self._preset = preset
|
self._preset = preset
|
||||||
|
|
@ -64,7 +64,7 @@ class ProfileMenu(AbstractSubMenu):
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
def run(self) -> Optional[ProfileConfiguration]:
|
def run(self) -> ProfileConfiguration | None:
|
||||||
super().run()
|
super().run()
|
||||||
|
|
||||||
if self._data_store.get('profile', None):
|
if self._data_store.get('profile', None):
|
||||||
|
|
@ -76,7 +76,7 @@ class ProfileMenu(AbstractSubMenu):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _select_profile(self, preset: Optional[Profile]) -> Optional[Profile]:
|
def _select_profile(self, preset: Profile | None) -> Profile | None:
|
||||||
profile = select_profile(preset)
|
profile = select_profile(preset)
|
||||||
|
|
||||||
if profile is not None:
|
if profile is not None:
|
||||||
|
|
@ -99,9 +99,9 @@ class ProfileMenu(AbstractSubMenu):
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
def _select_gfx_driver(self, preset: Optional[GfxDriver] = None) -> Optional[GfxDriver]:
|
def _select_gfx_driver(self, preset: GfxDriver | None = None) -> GfxDriver | None:
|
||||||
driver = preset
|
driver = preset
|
||||||
profile: Optional[Profile] = self._item_group.find_by_key('profile').value
|
profile: Profile | None = self._item_group.find_by_key('profile').value
|
||||||
|
|
||||||
if profile:
|
if profile:
|
||||||
if profile.is_graphic_driver_supported():
|
if profile.is_graphic_driver_supported():
|
||||||
|
|
@ -130,20 +130,20 @@ class ProfileMenu(AbstractSubMenu):
|
||||||
|
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
def _prev_gfx(self, item: MenuItem) -> Optional[str]:
|
def _prev_gfx(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
driver = item.get_value().value
|
driver = item.get_value().value
|
||||||
packages = item.get_value().packages_text()
|
packages = item.get_value().packages_text()
|
||||||
return f'Driver: {driver}\n{packages}'
|
return f'Driver: {driver}\n{packages}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _prev_greeter(self, item: MenuItem) -> Optional[str]:
|
def _prev_greeter(self, item: MenuItem) -> str | None:
|
||||||
if item.value:
|
if item.value:
|
||||||
return f'{_("Greeter")}: {item.value.value}'
|
return f'{_("Greeter")}: {item.value.value}'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _preview_profile(self, item: MenuItem) -> Optional[str]:
|
def _preview_profile(self, item: MenuItem) -> str | None:
|
||||||
profile: Optional[Profile] = item.value
|
profile: Profile | None = item.value
|
||||||
text = ''
|
text = ''
|
||||||
|
|
||||||
if profile:
|
if profile:
|
||||||
|
|
@ -161,14 +161,14 @@ class ProfileMenu(AbstractSubMenu):
|
||||||
|
|
||||||
|
|
||||||
def select_greeter(
|
def select_greeter(
|
||||||
profile: Optional[Profile] = None,
|
profile: Profile | None = None,
|
||||||
preset: Optional[GreeterType] = None
|
preset: GreeterType | None = None
|
||||||
) -> Optional[GreeterType]:
|
) -> GreeterType | None:
|
||||||
if not profile or profile.is_greeter_supported():
|
if not profile or profile.is_greeter_supported():
|
||||||
items = [MenuItem(greeter.value, value=greeter) for greeter in GreeterType]
|
items = [MenuItem(greeter.value, value=greeter) for greeter in GreeterType]
|
||||||
group = MenuItemGroup(items, sort_items=True)
|
group = MenuItemGroup(items, sort_items=True)
|
||||||
|
|
||||||
default: Optional[GreeterType] = None
|
default: GreeterType | None = None
|
||||||
if preset is not None:
|
if preset is not None:
|
||||||
default = preset
|
default = preset
|
||||||
elif profile is not None:
|
elif profile is not None:
|
||||||
|
|
@ -196,10 +196,10 @@ def select_greeter(
|
||||||
|
|
||||||
|
|
||||||
def select_profile(
|
def select_profile(
|
||||||
current_profile: Optional[Profile] = None,
|
current_profile: Profile | None = None,
|
||||||
header: Optional[str] = None,
|
header: str | None = None,
|
||||||
allow_reset: bool = True,
|
allow_reset: bool = True,
|
||||||
) -> Optional[Profile]:
|
) -> Profile | None:
|
||||||
from archinstall.lib.profile.profiles_handler import profile_handler
|
from archinstall.lib.profile.profiles_handler import profile_handler
|
||||||
top_level_profiles = profile_handler.get_top_level_profiles()
|
top_level_profiles = profile_handler.get_top_level_profiles()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Any, Optional
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from ..hardware import GfxDriver
|
from ..hardware import GfxDriver
|
||||||
from archinstall.default_profiles.profile import Profile, GreeterType
|
from archinstall.default_profiles.profile import Profile, GreeterType
|
||||||
|
|
@ -12,9 +12,9 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ProfileConfiguration:
|
class ProfileConfiguration:
|
||||||
profile: Optional[Profile] = None
|
profile: Profile | None = None
|
||||||
gfx_driver: Optional[GfxDriver] = None
|
gfx_driver: GfxDriver | None = None
|
||||||
greeter: Optional[GreeterType] = None
|
greeter: GreeterType | None = None
|
||||||
|
|
||||||
def json(self) -> dict[str, Any]:
|
def json(self) -> dict[str, Any]:
|
||||||
from .profiles_handler import profile_handler
|
from .profiles_handler import profile_handler
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
from typing import TYPE_CHECKING, Any, Union
|
||||||
|
|
||||||
from ...default_profiles.profile import Profile, GreeterType
|
from ...default_profiles.profile import Profile, GreeterType
|
||||||
from .profile_model import ProfileConfiguration
|
from .profile_model import ProfileConfiguration
|
||||||
|
|
@ -26,14 +26,14 @@ if TYPE_CHECKING:
|
||||||
class ProfileHandler:
|
class ProfileHandler:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._profiles_path: Path = storage['PROFILE']
|
self._profiles_path: Path = storage['PROFILE']
|
||||||
self._profiles: Optional[list[Profile]] = None
|
self._profiles: list[Profile] | None = None
|
||||||
|
|
||||||
# special variable to keep track of a profile url configuration
|
# special variable to keep track of a profile url configuration
|
||||||
# it is merely used to be able to export the path again when a user
|
# it is merely used to be able to export the path again when a user
|
||||||
# wants to save the configuration
|
# wants to save the configuration
|
||||||
self._url_path = None
|
self._url_path = None
|
||||||
|
|
||||||
def to_json(self, profile: Optional[Profile]) -> dict[str, Any]:
|
def to_json(self, profile: Profile | None) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Serialize the selected profile setting to JSON
|
Serialize the selected profile setting to JSON
|
||||||
"""
|
"""
|
||||||
|
|
@ -51,11 +51,11 @@ class ProfileHandler:
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def parse_profile_config(self, profile_config: dict[str, Any]) -> Optional[Profile]:
|
def parse_profile_config(self, profile_config: dict[str, Any]) -> Profile | None:
|
||||||
"""
|
"""
|
||||||
Deserialize JSON configuration for profile
|
Deserialize JSON configuration for profile
|
||||||
"""
|
"""
|
||||||
profile: Optional[Profile] = None
|
profile: Profile | None = None
|
||||||
|
|
||||||
# the order of these is important, we want to
|
# the order of these is important, we want to
|
||||||
# load all the default_profiles from url and custom
|
# load all the default_profiles from url and custom
|
||||||
|
|
@ -154,7 +154,7 @@ class ProfileHandler:
|
||||||
remove_names = [p.name for p in profiles]
|
remove_names = [p.name for p in profiles]
|
||||||
self._profiles = [p for p in self.profiles if p.name not in remove_names]
|
self._profiles = [p for p in self.profiles if p.name not in remove_names]
|
||||||
|
|
||||||
def get_profile_by_name(self, name: str) -> Optional[Profile]:
|
def get_profile_by_name(self, name: str) -> Profile | None:
|
||||||
return next(filter(lambda x: x.name == name, self.profiles), None) # type: ignore
|
return next(filter(lambda x: x.name == name, self.profiles), None) # type: ignore
|
||||||
|
|
||||||
def get_top_level_profiles(self) -> list[Profile]:
|
def get_top_level_profiles(self) -> list[Profile]:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import gettext
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, TYPE_CHECKING, Optional
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from .output import error, debug
|
from .output import error, debug
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ class Language:
|
||||||
name_en: str
|
name_en: str
|
||||||
translation: gettext.NullTranslations
|
translation: gettext.NullTranslations
|
||||||
translation_percent: int
|
translation_percent: int
|
||||||
translated_lang: Optional[str]
|
translated_lang: str | None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display_name(self) -> str:
|
def display_name(self) -> str:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue