Skip to content

Commit a7e838e

Browse files
committed
Move run_custom_user_commands to fix an import cycle
1 parent 83c3a76 commit a7e838e

4 files changed

Lines changed: 22 additions & 27 deletions

File tree

archinstall/lib/general.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
from pathlib import Path
1919
from select import EPOLLHUP, EPOLLIN, epoll
2020
from shutil import which
21-
from typing import TYPE_CHECKING, Any, override
21+
from typing import Any, override
2222
from urllib.request import Request, urlopen
2323

2424
from .exceptions import RequirementError, SysCallError
25-
from .output import debug, error, info
25+
from .output import debug, error
2626
from .storage import storage
2727

28-
if TYPE_CHECKING:
29-
from .installer import Installer
30-
3128
# https://stackoverflow.com/a/43627833/929999
3229
_VT100_ESCAPE_REGEX = r'\x1B\[[?0-9;]*[a-zA-Z]'
3330
_VT100_ESCAPE_REGEX_BYTES = _VT100_ESCAPE_REGEX.encode()
@@ -463,20 +460,6 @@ def _pid_exists(pid: int) -> bool:
463460
return False
464461

465462

466-
def run_custom_user_commands(commands: list[str], installation: Installer) -> None:
467-
for index, command in enumerate(commands):
468-
script_path = f"/var/tmp/user-command.{index}.sh"
469-
chroot_path = f"{installation.target}/{script_path}"
470-
471-
info(f'Executing custom command "{command}" ...')
472-
with open(chroot_path, "w") as user_script:
473-
user_script.write(command)
474-
475-
SysCommand(f"arch-chroot {installation.target} bash {script_path}")
476-
477-
os.unlink(chroot_path)
478-
479-
480463
def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict[str, Any]) -> bool:
481464
"""
482465
Load a JSON encoded dictionary from a stream and merge it into an existing dictionary.

archinstall/lib/installer.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@
5757
__accessibility_packages__ = ["brltty", "espeakup", "alsa-utils"]
5858

5959

60-
def accessibility_tools_in_use() -> bool:
61-
return os.system('systemctl is-active --quiet espeakup.service') == 0
62-
63-
6460
class Installer:
6561
def __init__(
6662
self,
@@ -1654,3 +1650,21 @@ def _service_state(self, service_name: str) -> str:
16541650
f'systemctl show --no-pager -p SubState --value {service_name}',
16551651
environment_vars={'SYSTEMD_COLORS': '0'}
16561652
).decode()
1653+
1654+
1655+
def accessibility_tools_in_use() -> bool:
1656+
return os.system('systemctl is-active --quiet espeakup.service') == 0
1657+
1658+
1659+
def run_custom_user_commands(commands: list[str], installation: Installer) -> None:
1660+
for index, command in enumerate(commands):
1661+
script_path = f"/var/tmp/user-command.{index}.sh"
1662+
chroot_path = f"{installation.target}/{script_path}"
1663+
1664+
info(f'Executing custom command "{command}" ...')
1665+
with open(chroot_path, "w") as user_script:
1666+
user_script.write(command)
1667+
1668+
SysCommand(f"arch-chroot {installation.target} bash {script_path}")
1669+
1670+
os.unlink(chroot_path)

archinstall/scripts/guided.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from archinstall.lib.configuration import ConfigurationOutput
66
from archinstall.lib.disk.filesystem import FilesystemHandler
77
from archinstall.lib.disk.utils import disk_layouts
8-
from archinstall.lib.general import run_custom_user_commands
98
from archinstall.lib.global_menu import GlobalMenu
10-
from archinstall.lib.installer import Installer, accessibility_tools_in_use
9+
from archinstall.lib.installer import Installer, accessibility_tools_in_use, run_custom_user_commands
1110
from archinstall.lib.interactions.general_conf import ask_chroot
1211
from archinstall.lib.models import AudioConfiguration, Bootloader
1312
from archinstall.lib.models.device_model import (

examples/interactive_installation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from archinstall.lib.configuration import ConfigurationOutput
66
from archinstall.lib.disk.filesystem import FilesystemHandler
77
from archinstall.lib.disk.utils import disk_layouts
8-
from archinstall.lib.general import run_custom_user_commands
98
from archinstall.lib.global_menu import GlobalMenu
10-
from archinstall.lib.installer import Installer, accessibility_tools_in_use
9+
from archinstall.lib.installer import Installer, accessibility_tools_in_use, run_custom_user_commands
1110
from archinstall.lib.interactions.general_conf import ask_chroot
1211
from archinstall.lib.models import AudioConfiguration, Bootloader
1312
from archinstall.lib.models.device_model import (

0 commit comments

Comments
 (0)