1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
from __future__ import annotations
from enum import Enum, auto
from typing import List, Optional, Any, Dict, TYPE_CHECKING, TypeVar
from archinstall.lib.utils.util import format_cols
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-gtk-greeter'
LightdmSlick = 'lightdm-slick-greeter'
Sddm = 'sddm'
Gdm = 'gdm'
Ly = 'ly'
class SelectResult(Enum):
NewSelection = auto()
SameSelection = auto()
ResetCurrent = auto()
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.custom_settings: Dict[str, Any] = {}
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 chosen 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 set_custom_settings(self, settings: Dict[str, Any]):
"""
Set the custom settings for the profile.
This is also called when the settings are parsed from the config
and can be overridden to perform further actions based on the profile
"""
self.custom_settings = settings
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]:
"""
Override this method to provide a preview text for the profile
"""
return self.packages_text()
def packages_text(self, include_sub_packages: bool = False) -> Optional[str]:
header = str(_('Installed packages'))
text = ''
packages = []
if self.packages:
packages = self.packages
if include_sub_packages:
for p in self.current_selection:
if p.packages:
packages += p.packages
text += format_cols(sorted(set(packages)))
if text:
text = f'{header}: \n{text}'
return text
return None
|