Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions archinstall/lib/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from types import TracebackType
from typing import TYPE_CHECKING, ClassVar, Self

from .command import SysCommand, SysCommandWorker
from .command import SysCommand, SysCommandWorker, locate_binary
from .exceptions import SysCallError
from .general import locate_binary
from .output import error

if TYPE_CHECKING:
Expand Down
11 changes: 9 additions & 2 deletions archinstall/lib/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import time
from collections.abc import Iterator
from select import EPOLLHUP, EPOLLIN, epoll
from shutil import which
from types import TracebackType
from typing import Any, Self, override

from archinstall.lib.exceptions import SysCallError
from archinstall.lib.general import clear_vt100_escape_codes, locate_binary
from archinstall.lib.exceptions import RequirementError, SysCallError
from archinstall.lib.output import debug, error, logger
from archinstall.lib.utils.encoding import clear_vt100_escape_codes


class SysCommandWorker:
Expand Down Expand Up @@ -345,6 +346,12 @@ def run(
)


def locate_binary(name: str) -> str:
if path := which(name):
return path
raise RequirementError(f'Binary {name} does not exist.')


def _pid_exists(pid: int) -> bool:
try:
return any(subprocess.check_output(['ps', '--no-headers', '-o', 'pid', '-p', str(pid)]).strip())
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/disk/fido.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import ClassVar

from archinstall.lib.models.device import Fido2Device
from archinstall.lib.utils.encoding import clear_vt100_escape_codes_from_str

from ..command import SysCommand, SysCommandWorker
from ..exceptions import SysCallError
from ..general import clear_vt100_escape_codes_from_str
from ..models.users import Password
from ..output import error, info

Expand Down
46 changes: 19 additions & 27 deletions archinstall/lib/general.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import json
import re
import secrets
import string
from datetime import date, datetime
from enum import Enum
from functools import lru_cache
from pathlib import Path
from shutil import which
from typing import Any, override

from archinstall.lib.exceptions import RequirementError
from archinstall.lib.packages.packages import check_package_upgrade

# https://stackoverflow.com/a/43627833/929999
_VT100_ESCAPE_REGEX = r'\x1B\[[?0-9;]*[a-zA-Z]'
_VT100_ESCAPE_REGEX_BYTES = _VT100_ESCAPE_REGEX.encode()
from .output import debug


@lru_cache(maxsize=128)
def check_version_upgrade() -> str | None:
debug('Checking version')
upgrade = None

upgrade = check_package_upgrade('archinstall')

if upgrade is None:
debug('No archinstall upgrades found')
return None

debug(f'Archinstall latest: {upgrade}')

return upgrade


def running_from_host() -> bool:
Expand All @@ -26,25 +37,6 @@ def running_from_host() -> bool:
return is_host


def generate_password(length: int = 64) -> str:
haystack = string.printable # digits, ascii_letters, punctuation (!"#$[] etc) and whitespace
return ''.join(secrets.choice(haystack) for _ in range(length))


def locate_binary(name: str) -> str:
if path := which(name):
return path
raise RequirementError(f'Binary {name} does not exist.')


def clear_vt100_escape_codes(data: bytes) -> bytes:
return re.sub(_VT100_ESCAPE_REGEX_BYTES, b'', data)


def clear_vt100_escape_codes_from_str(data: str) -> str:
return re.sub(_VT100_ESCAPE_REGEX, '', data)


def jsonify(obj: Any, safe: bool = True) -> Any:
"""
Converts objects into json.dumps() compatible nested dictionaries.
Expand Down
3 changes: 1 addition & 2 deletions archinstall/lib/global_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from archinstall.lib.models.authentication import AuthenticationConfiguration
from archinstall.lib.models.device import DiskLayoutConfiguration, DiskLayoutType, FilesystemType, PartitionModification
from archinstall.lib.network.network_menu import ask_to_configure_network
from archinstall.lib.packages import list_available_packages
from archinstall.lib.packages.packages import ask_additional_packages_to_install, list_available_packages
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup

from .applications.application_menu import ApplicationMenu
Expand All @@ -17,7 +17,6 @@
from .hardware import SysInfo
from .interactions.general_conf import (
add_number_of_parallel_downloads,
ask_additional_packages_to_install,
ask_for_a_timezone,
ask_hostname,
ask_ntp,
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Unit,
)
from archinstall.lib.models.packages import Repository
from archinstall.lib.packages import installed_package
from archinstall.lib.packages.packages import installed_package
from archinstall.lib.translationhandler import tr

from .args import arch_config_handler
Expand Down
2 changes: 0 additions & 2 deletions archinstall/lib/interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)
from .general_conf import (
add_number_of_parallel_downloads,
ask_additional_packages_to_install,
ask_for_a_timezone,
ask_hostname,
ask_ntp,
Expand All @@ -18,7 +17,6 @@

__all__ = [
'add_number_of_parallel_downloads',
'ask_additional_packages_to_install',
'ask_for_a_timezone',
'ask_for_swap',
'ask_hostname',
Expand Down
88 changes: 2 additions & 86 deletions archinstall/lib/interactions/general_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
from enum import Enum
from pathlib import Path

from archinstall.lib.menu.helpers import Confirmation, Input, Loading, Notify, Selection
from archinstall.lib.models.packages import Repository
from archinstall.lib.packages.packages import list_available_packages
from archinstall.lib.menu.helpers import Confirmation, Input, Selection
from archinstall.lib.translationhandler import tr
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
from archinstall.tui.ui.result import ResultType

from ..locale.utils import list_timezones
from ..models.packages import AvailablePackage, PackageGroup
from ..output import debug, warn
from ..output import warn
from ..translationhandler import Language


Expand Down Expand Up @@ -132,87 +129,6 @@ def select_archinstall_language(languages: list[Language], preset: Language) ->
raise ValueError('Language selection not handled')


def ask_additional_packages_to_install(
preset: list[str] = [],
repositories: set[Repository] = set(),
) -> list[str]:
repositories |= {Repository.Core, Repository.Extra}

respos_text = ', '.join(r.value for r in repositories)
output = tr('Repositories: {}').format(respos_text) + '\n'
output += tr('Loading packages...')

result = Loading[dict[str, AvailablePackage]](
header=output,
data_callback=lambda: list_available_packages(tuple(repositories)),
).show()

if result.type_ != ResultType.Selection:
debug('Error while loading packages')
return preset

packages = result.get_value()

if not packages:
Notify(tr('No packages found')).show()
return []

package_groups = PackageGroup.from_available_packages(packages)

# Additional packages (with some light weight error handling for invalid package names)
header = tr('Only packages such as base, sudo, linux, linux-firmware, efibootmgr and optional profile packages are installed.') + '\n'
header += tr('Note: base-devel is no longer installed by default. Add it here if you need build tools.') + '\n'
header += tr('Select any packages from the below list that should be installed additionally') + '\n'

# there are over 15k packages so this needs to be quick
preset_packages: list[AvailablePackage | PackageGroup] = []
for p in preset:
if p in packages:
preset_packages.append(packages[p])
elif p in package_groups:
preset_packages.append(package_groups[p])

items = [
MenuItem(
name,
value=pkg,
preview_action=lambda x: x.value.info() if x.value else None,
)
for name, pkg in packages.items()
]

items += [
MenuItem(
name,
value=group,
preview_action=lambda x: x.value.info() if x.value else None,
)
for name, group in package_groups.items()
]

menu_group = MenuItemGroup(items, sort_items=True)
menu_group.set_selected_by_value(preset_packages)

pck_result = Selection[AvailablePackage | PackageGroup](
menu_group,
header=header,
allow_reset=True,
allow_skip=True,
multi=True,
preview_location='right',
enable_filter=True,
).show()

match pck_result.type_:
case ResultType.Skip:
return preset
case ResultType.Reset:
return []
case ResultType.Selection:
selected_pacakges = pck_result.get_values()
return [pkg.name for pkg in selected_pacakges]


def add_number_of_parallel_downloads(preset: int = 1) -> int | None:
max_recommended = 5

Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/luks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from archinstall.lib.disk.utils import get_lsblk_info, umount
from archinstall.lib.models.device import DEFAULT_ITER_TIME
from archinstall.lib.utils.util import generate_password

from .command import SysCommand, SysCommandWorker, run
from .exceptions import DiskError, SysCallError
from .general import generate_password
from .models.users import Password
from .output import debug, info

Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any

from .utils.unicode import unicode_ljust, unicode_rjust
from .utils.encoding import unicode_ljust, unicode_rjust

if TYPE_CHECKING:
from _typeshed import DataclassInstance
Expand Down
6 changes: 0 additions & 6 deletions archinstall/lib/packages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
from .packages import installed_package, list_available_packages

__all__ = [
'installed_package',
'list_available_packages',
]
Loading