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
|
from __future__ import annotations
from typing import List, Any, TYPE_CHECKING, Optional
from ..hardware import SysInfo, GfxDriver
from ..menu import MenuSelectionType, Menu
from ..models.bootloader import Bootloader
if TYPE_CHECKING:
_: Any
def select_kernel(preset: List[str] = []) -> List[str]:
"""
Asks the user to select a kernel for system.
:return: The string as a selected kernel
:rtype: string
"""
kernels = ["linux", "linux-lts", "linux-zen", "linux-hardened"]
default_kernel = "linux"
warning = str(_('Are you sure you want to reset this setting?'))
choice = Menu(
_('Choose which kernels to use or leave blank for default "{}"').format(default_kernel),
kernels,
sort=True,
multi=True,
preset_values=preset,
allow_reset_warning_msg=warning
).run()
match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Selection: return choice.single_value
return []
def ask_for_bootloader(preset: Bootloader) -> Bootloader:
# when the system only supports grub
if not SysInfo.has_uefi():
options = [Bootloader.Grub.value]
default = Bootloader.Grub.value
else:
options = Bootloader.values()
default = Bootloader.Systemd.value
preset_value = preset.value if preset else None
choice = Menu(
_('Choose a bootloader'),
options,
preset_values=preset_value,
sort=False,
default_option=default
).run()
match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Selection: return Bootloader(choice.value)
return preset
def select_driver(options: List[GfxDriver] = [], current_value: Optional[GfxDriver] = None) -> Optional[GfxDriver]:
"""
Some what convoluted function, whose job is simple.
Select a graphics driver from a pre-defined set of popular options.
(The template xorg is for beginner users, not advanced, and should
there for appeal to the general public first and edge cases later)
"""
if not options:
options = [driver for driver in GfxDriver]
drivers = sorted([o.value for o in options])
if drivers:
title = ''
if SysInfo.has_amd_graphics():
title += str(_('For the best compatibility with your AMD hardware, you may want to use either the all open-source or AMD / ATI options.')) + '\n'
if SysInfo.has_intel_graphics():
title += str(_('For the best compatibility with your Intel hardware, you may want to use either the all open-source or Intel options.\n'))
if SysInfo.has_nvidia_graphics():
title += str(_('For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.\n'))
title += str(_('\nSelect a graphics driver or leave blank to install all open-source drivers'))
preset = current_value.value if current_value else None
choice = Menu(
title,
drivers,
preset_values=preset,
default_option=GfxDriver.AllOpenSource.value
).run()
if choice.type_ != MenuSelectionType.Selection:
return current_value
return GfxDriver(choice.single_value)
return current_value
def ask_for_swap(preset: bool = True) -> bool:
if preset:
preset_val = Menu.yes()
else:
preset_val = Menu.no()
prompt = _('Would you like to use swap on zram?')
choice = Menu(prompt, Menu.yes_no(), default_option=Menu.yes(), preset_values=preset_val).run()
match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Selection: return False if choice.value == Menu.no() else True
return preset
|