From 00b0ae7ba439a5a420095175b3bedd52c569db51 Mon Sep 17 00:00:00 2001 From: Daniel Girtler Date: Wed, 19 Apr 2023 20:55:42 +1000 Subject: PyParted and a large rewrite of the underlying partitioning (#1604) * Invert mypy files * Add optional pre-commit hooks * New profile structure * Serialize profiles * Use profile instead of classmethod * Custom profile setup * Separator between back * Support profile import via url * Move profiles module * Refactor files * Remove symlink * Add user to docker group * Update schema description * Handle list services * mypy fixes * mypy fixes * Rename profilesv2 to profiles * flake8 * mypy again * Support selecting DM * Fix mypy * Cleanup * Update greeter setting * Update schema * Revert toml changes * Poc external dependencies * Dependency support * New encryption menu * flake8 * Mypy and flake8 * Unify lsblk command * Update bootloader configuration * Git hooks * Fix import * Pyparted * Remove custom font setting * flake8 * Remove default preview * Manual partitioning menu * Update structure * Disk configuration * Update filesystem * luks2 encryption * Everything works until installation * Btrfsutil * Btrfs handling * Update btrfs * Save encryption config * Fix pipewire issue * Update mypy version * Update all pre-commit * Update package versions * Revert audio/pipewire * Merge master PRs * Add master changes * Merge master changes * Small renaming * Pull master changes * Reset disk enc after disk config change * Generate locals * Update naming * Fix imports * Fix broken sync * Fix pre selection on table menu * Profile menu * Update profile * Fix post_install * Added python-pyparted to PKGBUILD, this requires [testing] to be enabled in order to run makepkg. Package still works via python -m build etc. * Swaped around some setuptools logic in pyproject Since we define `package-data` and `packages` there should be no need for: ``` [tool.setuptools.packages.find] where = ["archinstall", "archinstall.*"] ``` * Removed pyproject collisions. Duplicate definitions. * Made sure pyproject.toml includes languages * Add example and update README * Fix pyproject issues * Generate locale * Refactor imports * Simplify imports * Add profile description and package examples * Align code * Fix mypy * Simplify imports * Fix saving config * Fix wrong luks merge * Refactor installation * Fix cdrom device loading * Fix wrongly merged code * Fix imports and greeter * Don't terminate on partprobe error * Use specific path on partprobe from luks * Update archinstall/lib/disk/device_model.py Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> * Update archinstall/lib/disk/device_model.py Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> * Update github workflow to test archinstall installation * Update sway merge * Generate locales * Update workflow --------- Co-authored-by: Daniel Girtler Co-authored-by: Anton Hvornum Co-authored-by: Anton Hvornum Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> --- archinstall/default_profiles/profile.py | 206 ++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 archinstall/default_profiles/profile.py (limited to 'archinstall/default_profiles/profile.py') diff --git a/archinstall/default_profiles/profile.py b/archinstall/default_profiles/profile.py new file mode 100644 index 00000000..c7d6b3dc --- /dev/null +++ b/archinstall/default_profiles/profile.py @@ -0,0 +1,206 @@ +from __future__ import annotations + +from dataclasses import dataclass +from enum import Enum, auto +from typing import List, Optional, Any, Dict, TYPE_CHECKING, TypeVar + +from archinstall.lib.output import FormattedOutput + +if TYPE_CHECKING: + from archinstall.lib.installer import Installer + _: Any + + +TProfile = TypeVar('TProfile', bound='Profile') + + +class ProfileType(Enum): + # top level default_profiles + Server = 'Server' + Desktop = 'Desktop' + Xorg = 'Xorg' + Minimal = 'Minimal' + Custom = 'Custom' + # detailed selection default_profiles + ServerType = 'ServerType' + WindowMgr = 'Window Manager' + DesktopEnv = 'Desktop Environment' + CustomType = 'CustomType' + # special things + Tailored = 'Tailored' + Application = 'Application' + + +class GreeterType(Enum): + Lightdm = 'lightdm' + Sddm = 'sddm' + Gdm = 'gdm' + + +class SelectResult(Enum): + NewSelection = auto() + SameSelection = auto() + ResetCurrent = auto() + + +@dataclass +class ProfileInfo: + name: str + details: Optional[str] + gfx_driver: Optional[str] = None + greeter: Optional[str] = None + + @property + def absolute_name(self) -> str: + if self.details is not None: + return self.details + return self.name + + +class Profile: + def __init__( + self, + name: str, + profile_type: ProfileType, + description: str = '', + current_selection: List[TProfile] = [], + packages: List[str] = [], + services: List[str] = [], + support_gfx_driver: bool = False, + support_greeter: bool = False + ): + self.name = name + self.description = description + self.profile_type = profile_type + self._support_gfx_driver = support_gfx_driver + self._support_greeter = support_greeter + + # self.gfx_driver: Optional[str] = None + + self._current_selection = current_selection + self._packages = packages + self._services = services + + # Only used for custom default_profiles + self.custom_enabled = False + + @property + def current_selection(self) -> List[TProfile]: + return self._current_selection + + @property + def packages(self) -> List[str]: + """ + Returns a list of packages that should be installed when + this profile is among the choosen ones + """ + return self._packages + + @property + def services(self) -> List[str]: + """ + Returns a list of services that should be enabled when + this profile is among the chosen ones + """ + return self._services + + @property + def default_greeter_type(self) -> Optional[GreeterType]: + """ + Setting a default greeter type for a desktop profile + """ + return None + + def install(self, install_session: 'Installer'): + """ + Performs installation steps when this profile was selected + """ + + def post_install(self, install_session: 'Installer'): + """ + Hook that will be called when the installation process is + finished and custom installation steps for specific default_profiles + are needed + """ + + def json(self) -> Dict: + """ + Returns a json representation of the profile + """ + return {} + + def do_on_select(self) -> SelectResult: + """ + Hook that will be called when a profile is selected + """ + return SelectResult.NewSelection + + def current_selection_names(self) -> List[str]: + if self._current_selection: + return [s.name for s in self._current_selection] + return [] + + def reset(self): + self.set_current_selection([]) + + def set_current_selection(self, current_selection: List[TProfile]): + self._current_selection = current_selection + + def is_top_level_profile(self) -> bool: + top_levels = [ProfileType.Desktop, ProfileType.Server, ProfileType.Xorg, ProfileType.Minimal, ProfileType.Custom] + return self.profile_type in top_levels + + def is_desktop_profile(self) -> bool: + return self.profile_type == ProfileType.Desktop + + def is_server_type_profile(self) -> bool: + return self.profile_type == ProfileType.ServerType + + def is_desktop_type_profile(self) -> bool: + return self.profile_type == ProfileType.DesktopEnv or self.profile_type == ProfileType.WindowMgr + + def is_xorg_type_profile(self) -> bool: + return self.profile_type == ProfileType.Xorg + + def is_tailored(self) -> bool: + return self.profile_type == ProfileType.Tailored + + def is_custom_type_profile(self) -> bool: + return self.profile_type == ProfileType.CustomType + + def is_graphic_driver_supported(self) -> bool: + if not self._current_selection: + return self._support_gfx_driver + else: + if any([p._support_gfx_driver for p in self._current_selection]): + return True + return False + + def is_greeter_supported(self) -> bool: + return self._support_greeter + + def preview_text(self) -> Optional[str]: + """ + Used for preview text in profiles_bck. If a description is set for a + profile it will automatically display that one in the preivew. + If no preview or a different text should be displayed just + """ + if self.description: + return self.description + return None + + def packages_text(self) -> str: + text = str(_('Installed packages')) + ':\n' + + nr_packages = len(self.packages) + if nr_packages <= 5: + col = 1 + elif nr_packages <= 10: + col = 2 + elif nr_packages <= 15: + col = 3 + else: + col = 4 + + text += FormattedOutput.as_columns(self.packages, col) + return text -- cgit v1.2.3-70-g09d2