-
-
Notifications
You must be signed in to change notification settings - Fork 736
Add Pacman settings submenu with Color and ParallelDownloads #4404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c38ee3c
Add Pacman settings submenu with Color and ParallelDownloads
Softer 310118b
Skip _apply_to_live when user exits Pacman menu without changes
Softer 97af5d1
Use TypedDict for PacmanConfiguration serialization
Softer f2fc47b
Merge remote-tracking branch 'origin/master' into pacman-config-menu
Softer 739b5eb
Show Pacman menu by default, keep ParallelDownloads behind --advanced
Softer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Any, Self | ||
|
|
||
| from archinstall.lib.translationhandler import tr | ||
|
|
||
|
|
||
| @dataclass | ||
| class PacmanConfiguration: | ||
| parallel_downloads: int = 5 | ||
| color: bool = True | ||
|
|
||
| @classmethod | ||
| def default(cls) -> Self: | ||
| return cls() | ||
|
|
||
| def json(self) -> dict[str, Any]: | ||
| return { | ||
| 'parallel_downloads': self.parallel_downloads, | ||
| 'color': self.color, | ||
| } | ||
|
|
||
| def preview(self) -> str: | ||
| color_str = str(self.color) | ||
| output = '{}: {}\n'.format(tr('Parallel Downloads'), self.parallel_downloads) | ||
| output += '{}: {}'.format(tr('Color'), color_str) | ||
| return output | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, args: dict[str, Any]) -> Self: | ||
| config = cls.default() | ||
|
|
||
| if 'parallel_downloads' in args: | ||
| config.parallel_downloads = int(args['parallel_downloads']) | ||
| if 'color' in args: | ||
| config.color = bool(args['color']) | ||
|
|
||
| return config | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| from typing import override | ||
|
|
||
| from archinstall.lib.menu.abstract_menu import AbstractSubMenu | ||
| from archinstall.lib.menu.helpers import Confirmation, Input | ||
| from archinstall.lib.models.pacman import PacmanConfiguration | ||
| from archinstall.lib.pathnames import PACMAN_CONF | ||
| from archinstall.lib.translationhandler import tr | ||
| from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup | ||
| from archinstall.tui.ui.result import ResultType | ||
|
|
||
|
|
||
| class PacmanMenu(AbstractSubMenu[PacmanConfiguration]): | ||
| def __init__( | ||
| self, | ||
| pacman_conf: PacmanConfiguration, | ||
| ): | ||
| self._pacman_conf = pacman_conf | ||
| menu_options = self._define_menu_options() | ||
|
|
||
| self._item_group = MenuItemGroup(menu_options, sort_items=False, checkmarks=True) | ||
| super().__init__( | ||
| self._item_group, | ||
| config=self._pacman_conf, | ||
| allow_reset=True, | ||
| ) | ||
|
|
||
| def _define_menu_options(self) -> list[MenuItem]: | ||
| return [ | ||
| MenuItem( | ||
| text=tr('Parallel Downloads'), | ||
| action=select_parallel_downloads, | ||
| value=self._pacman_conf.parallel_downloads, | ||
| preview_action=lambda item: str(item.get_value()), | ||
| key='parallel_downloads', | ||
| ), | ||
| MenuItem( | ||
| text=tr('Color'), | ||
| action=select_color, | ||
| value=self._pacman_conf.color, | ||
| preview_action=lambda item: str(item.get_value()), | ||
| key='color', | ||
| ), | ||
| ] | ||
|
|
||
| @override | ||
| async def show(self) -> PacmanConfiguration | None: | ||
| config = await super().show() | ||
|
|
||
| if config is None: | ||
| return PacmanConfiguration.default() | ||
|
|
||
| _apply_to_live(config.parallel_downloads) | ||
|
|
||
| return config | ||
|
|
||
|
|
||
| def _apply_to_live(parallel_downloads: int) -> None: | ||
| """Apply ParallelDownloads to live system pacman.conf for faster installation.""" | ||
| with PACMAN_CONF.open() as f: | ||
| pacman_conf = f.read().split('\n') | ||
|
|
||
| with PACMAN_CONF.open('w') as fwrite: | ||
| for line in pacman_conf: | ||
| if 'ParallelDownloads' in line: | ||
| fwrite.write(f'ParallelDownloads = {parallel_downloads}\n') | ||
| else: | ||
| fwrite.write(f'{line}\n') | ||
|
|
||
|
|
||
| async def select_parallel_downloads(preset: int = 5) -> int | None: | ||
| max_recommended = 10 | ||
|
|
||
| header = tr('Enter the number of parallel downloads (1-{})').format(max_recommended) | ||
|
|
||
| def validator(s: str) -> str | None: | ||
| try: | ||
| value = int(s) | ||
| if 1 <= value <= max_recommended: | ||
| return None | ||
| return tr('Value must be between 1 and {}').format(max_recommended) | ||
| except Exception: | ||
| return tr('Please enter a valid number') | ||
|
|
||
| result = await Input( | ||
| header=header, | ||
| allow_skip=True, | ||
| allow_reset=True, | ||
| validator_callback=validator, | ||
| default_value=str(preset), | ||
| ).show() | ||
|
|
||
| match result.type_: | ||
| case ResultType.Skip: | ||
| return preset | ||
| case ResultType.Reset: | ||
| return 5 | ||
| case ResultType.Selection: | ||
| return int(result.get_value()) | ||
|
|
||
|
|
||
| async def select_color(preset: bool = True) -> bool | None: | ||
| result = await Confirmation( | ||
| header=tr('Enable colored output for pacman'), | ||
| preset=preset, | ||
| allow_skip=True, | ||
| ).show() | ||
|
|
||
| match result.type_: | ||
| case ResultType.Skip: | ||
| return preset | ||
| case ResultType.Reset: | ||
| return True | ||
| case ResultType.Selection: | ||
| return result.get_value() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be using
Anybut rather a dedicated serialization type, see https://github.com/svartkanin/archinstall/blob/a48ecf044bcfc59da01c804ff683ebe0cd7a20ae/archinstall/lib/models/authentication.py?plain=1#L14