-
-
Notifications
You must be signed in to change notification settings - Fork 773
Use declarative summary method for all sub-configs #4739
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
Open
svartkanin
wants to merge
12
commits into
archlinux:master
Choose a base branch
from
svartkanin:refactor-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c66ca3f
Refactor configuration file
svartkanin 0ed4ab7
Merge remote-tracking branch 'origin/master' into refactor-config
dgirtler e75e775
Update
dgirtler b65f591
Merge remote-tracking branch 'origin/master' into refactor-config
svartkanin 6c21490
Merge remote-tracking branch 'origin/master' into refactor-config
svartkanin e96ca1b
Update
svartkanin 303f7f4
Update
svartkanin ab7e458
Update
svartkanin 015a74b
Merge remote-tracking branch 'origin/master' into refactor-config
svartkanin f2be09c
Fix tests
svartkanin 2cfda8e
Update
svartkanin 0d49ce2
Merge remote-tracking branch 'origin/master' into refactor-config
svartkanin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from enum import StrEnum, auto | ||
| from typing import Any, NotRequired, Self, TypedDict, override | ||
|
|
||
| from archinstall.lib.models.config import SubConfig | ||
| from archinstall.lib.models.config import SubConfig, SummaryLevel | ||
| from archinstall.lib.translationhandler import tr | ||
|
|
||
|
|
||
|
|
@@ -85,14 +85,21 @@ class ApplicationSerialization(TypedDict): | |
|
|
||
|
|
||
| @dataclass | ||
| class AudioConfiguration: | ||
| class AudioConfiguration(SubConfig): | ||
| audio: Audio | ||
|
|
||
| NAME: str = tr('Audio') | ||
|
|
||
| @override | ||
| def json(self) -> AudioConfigSerialization: | ||
| return { | ||
| 'audio': self.audio.value, | ||
| } | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return [self.audio.value] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: dict[str, Any]) -> Self: | ||
| return cls( | ||
|
|
@@ -101,26 +108,42 @@ def parse_arg(cls, arg: dict[str, Any]) -> Self: | |
|
|
||
|
|
||
| @dataclass | ||
| class BluetoothConfiguration: | ||
| class BluetoothConfiguration(SubConfig): | ||
| enabled: bool | ||
|
|
||
| NAME: str = tr('Bluetooth') | ||
|
|
||
| @override | ||
| def json(self) -> BluetoothConfigSerialization: | ||
| return {'enabled': self.enabled} | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| if self.enabled: | ||
| return [tr('enabled')] | ||
| return [] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: BluetoothConfigSerialization) -> Self: | ||
| return cls(arg['enabled']) | ||
|
|
||
|
|
||
| @dataclass | ||
| class PowerManagementConfiguration: | ||
| class PowerManagementConfiguration(SubConfig): | ||
| power_management: PowerManagement | ||
|
|
||
| NAME: str = tr('Power management') | ||
|
|
||
| @override | ||
| def json(self) -> PowerManagementConfigSerialization: | ||
| return { | ||
| 'power_management': self.power_management.value, | ||
| } | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| return [self.power_management.value] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: PowerManagementConfigSerialization) -> Self: | ||
| return cls( | ||
|
|
@@ -129,26 +152,42 @@ def parse_arg(cls, arg: PowerManagementConfigSerialization) -> Self: | |
|
|
||
|
|
||
| @dataclass | ||
| class PrintServiceConfiguration: | ||
| class PrintServiceConfiguration(SubConfig): | ||
| enabled: bool | ||
|
|
||
| NAME: str = tr('Print service') | ||
|
|
||
| @override | ||
| def json(self) -> PrintServiceConfigSerialization: | ||
| return {'enabled': self.enabled} | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| if self.enabled: | ||
| return [tr('enabled')] | ||
| return [] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: PrintServiceConfigSerialization) -> Self: | ||
| return cls(arg['enabled']) | ||
|
|
||
|
|
||
| @dataclass | ||
| class FirewallConfiguration: | ||
| class FirewallConfiguration(SubConfig): | ||
| firewall: Firewall | ||
|
|
||
| NAME: str = tr('Firewall') | ||
|
|
||
| @override | ||
| def json(self) -> FirewallConfigSerialization: | ||
| return { | ||
| 'firewall': self.firewall.value, | ||
| } | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| return [self.firewall.value] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: dict[str, Any]) -> Self: | ||
| return cls( | ||
|
|
@@ -157,12 +196,21 @@ def parse_arg(cls, arg: dict[str, Any]) -> Self: | |
|
|
||
|
|
||
| @dataclass | ||
| class FontsConfiguration: | ||
| class FontsConfiguration(SubConfig): | ||
| fonts: list[FontPackage] | ||
|
|
||
| NAME: str = tr('Fonts') | ||
|
|
||
| @override | ||
| def json(self) -> FontsConfigSerialization: | ||
| return {'fonts': [f.value for f in self.fonts]} | ||
|
|
||
| @override | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| if self.fonts: | ||
| return [', '.join(f.value for f in self.fonts)] | ||
| return [] | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: FontsConfigSerialization) -> Self: | ||
| return cls(fonts=[FontPackage(f) for f in arg['fonts']]) | ||
|
|
@@ -173,6 +221,8 @@ class ZramConfiguration(SubConfig): | |
| enabled: bool | ||
| algorithm: ZramAlgorithm = ZramAlgorithm.ZSTD | ||
|
|
||
| NAME: str = tr('Zram') | ||
|
|
||
| @classmethod | ||
| def parse_arg(cls, arg: bool | dict[str, Any]) -> Self: | ||
| if isinstance(arg, bool): | ||
|
|
@@ -190,16 +240,14 @@ def json(self) -> dict[str, bool | str]: | |
| } | ||
|
|
||
| @override | ||
| def summary(self) -> list[str] | None: | ||
| out: list[str] = [] | ||
|
|
||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| if self.enabled: | ||
| out.append(tr('Zram enabled')) | ||
|
|
||
| out.append(tr('Zram algorithm {}').format(self.algorithm)) | ||
| return out | ||
| return [ | ||
| tr('enabled'), | ||
| tr('Algorithm "{}"').format(self.algorithm), | ||
| ] | ||
|
|
||
| return None | ||
| return [tr('Zram disabled')] | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -211,6 +259,8 @@ class ApplicationConfiguration(SubConfig): | |
| firewall_config: FirewallConfiguration | None = None | ||
| fonts_config: FontsConfiguration | None = None | ||
|
|
||
| NAME: str = tr('Application') | ||
|
|
||
| @classmethod | ||
| def parse_arg( | ||
| cls, | ||
|
|
@@ -268,26 +318,24 @@ def json(self) -> ApplicationSerialization: | |
| return config | ||
|
|
||
| @override | ||
| def summary(self) -> list[str]: | ||
| out: list[str] = [] | ||
|
|
||
| if self.bluetooth_config and self.bluetooth_config.enabled: | ||
| out.append(tr('Bluetooth enabled')) | ||
|
|
||
| if self.audio_config: | ||
| out.append(tr('Audio server "{}"').format(self.audio_config.audio)) | ||
| def summary(self, level: SummaryLevel = SummaryLevel.BASIC) -> list[str]: | ||
| configs = [ | ||
| self.bluetooth_config, | ||
| self.audio_config, | ||
| self.power_management_config, | ||
| self.print_service_config, | ||
| self.firewall_config, | ||
| self.fonts_config, | ||
| ] | ||
|
|
||
| if self.power_management_config: | ||
| out.append(tr('Power management "{}"').format(self.power_management_config.power_management)) | ||
|
|
||
| if self.print_service_config and self.print_service_config.enabled: | ||
| out.append(tr('Print service enabled')) | ||
|
|
||
| if self.firewall_config: | ||
| out.append(tr('Firewall "{}"').format(self.firewall_config.firewall)) | ||
| out: list[str] = [] | ||
|
|
||
| if self.fonts_config and self.fonts_config.fonts: | ||
| fonts = ', '.join(f.value for f in self.fonts_config.fonts) | ||
| out.append(tr('Extra fonts "{}"').format(fonts)) | ||
| for config in configs: | ||
| if config: | ||
| summary = config.summary(level) | ||
| if len(summary) == 1: | ||
| out.append(f'{config.NAME} "{summary[0]}"') | ||
| else: | ||
| out.append('?????') | ||
|
|
||
| return out | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The
leveldefault (SummaryLevel.Basic) can be removed from all thesummarymethods if onlyas_summarycalls them.as_summaryalready hasSummaryLevel.Basicas the default forleveland passes it to thesummarymethods here. If this is unnecessary duplication of the default, makelevelrequired forsummarymethods by removing the default from their parameters.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.
Explained in the comment above, this is the first use case for the new summary. In a follow up I'll use it for the installation confirmation screen as well which needs all the detailed setting summaries