Decouple share_install_log from TUI module

This commit is contained in:
Softer 2026-05-04 14:25:57 +03:00
parent c0f023495d
commit 6f84eca51c
2 changed files with 28 additions and 31 deletions

View File

@ -337,11 +337,11 @@ def log(
print(text)
_PASTE_URL = 'https://paste.rs'
_PASTE_MAX_SIZE = 10 * 1024 * 1024
def share_install_log() -> int:
def share_install_log(
paste_url: str = 'https://paste.rs',
max_size: int = 10 * 1024 * 1024,
confirm: Callable[[str], bool] = lambda _: True,
) -> int:
log_path = logger.path
if not log_path.exists():
@ -353,27 +353,23 @@ def share_install_log() -> int:
info(f'Log file is empty: {log_path}')
return 1
if size > _PASTE_MAX_SIZE:
info(f'Log file exceeds {_PASTE_MAX_SIZE} bytes, uploading last {_PASTE_MAX_SIZE} bytes')
content = log_path.read_bytes()[-_PASTE_MAX_SIZE:]
if size > max_size:
info(f'Log file exceeds {max_size} bytes, uploading last {max_size} bytes')
content = log_path.read_bytes()[-max_size:]
else:
content = log_path.read_bytes()
header = f'About to upload {log_path} ({len(content)} bytes) to {_PASTE_URL}\n\n'
header = f'About to upload {log_path} ({len(content)} bytes) to {paste_url}\n\n'
header += 'The log may contain hostname, mirror URLs, package list and partition layout.\n'
header += 'The uploaded paste is public.\n\n'
header += 'Continue?'
from archinstall.tui.components import tui
confirmed: bool = tui.run(lambda: _confirm_share(header))
if not confirmed:
if not confirm(header):
info('Cancelled.')
return 1
try:
req = urllib.request.Request(_PASTE_URL, data=content)
req = urllib.request.Request(paste_url, data=content)
with urllib.request.urlopen(req) as response:
url = response.read().decode().strip()
except urllib.error.URLError as e:
@ -381,23 +377,9 @@ def share_install_log() -> int:
return 1
if not url.startswith('http'):
info(f'Unexpected response from {_PASTE_URL}: {url[:200]!r}')
info(f'Unexpected response from {paste_url}: {url[:200]!r}')
return 1
# raw print so the URL is pipe-friendly (no ANSI colors, no log prefix)
print(url)
return 0
async def _confirm_share(header: str) -> bool:
from archinstall.lib.menu.helpers import Confirmation
from archinstall.tui.menu_item import MenuItemGroup
result = await Confirmation(
group=MenuItemGroup.yes_no(),
header=header,
allow_skip=False,
preset=False,
).show()
return result.get_value()

View File

@ -11,6 +11,7 @@ from pathlib import Path
from archinstall.lib.args import ArchConfigHandler
from archinstall.lib.disk.utils import disk_layouts
from archinstall.lib.hardware import SysInfo
from archinstall.lib.menu.helpers import Confirmation
from archinstall.lib.network.wifi_handler import WifiHandler
from archinstall.lib.networking import ping
from archinstall.lib.output import debug, error, info, share_install_log, warn
@ -19,6 +20,7 @@ from archinstall.lib.pacman.pacman import Pacman
from archinstall.lib.translationhandler import tr, translation_handler
from archinstall.lib.utils.util import running_from_iso
from archinstall.tui.components import tui
from archinstall.tui.menu_item import MenuItemGroup
def _log_sys_info() -> None:
@ -73,6 +75,19 @@ def _list_scripts() -> str:
return '\n'.join(lines)
def _tui_confirm(header: str) -> bool:
async def _ask() -> bool:
result = await Confirmation(
group=MenuItemGroup.yes_no(),
header=header,
allow_skip=False,
preset=False,
).show()
return result.get_value()
return tui.run(_ask)
def run() -> int:
"""
This can either be run as the compiled and installed application: python setup.py install
@ -80,7 +95,7 @@ def run() -> int:
In any case we will be attempting to load the provided script to be run from the scripts/ folder
"""
if 'share-log' in sys.argv:
return share_install_log()
return share_install_log(confirm=_tui_confirm)
arch_config_handler = ArchConfigHandler()