Added profile `desktop.py` which helps users select a desktop environment. Also added `archinstall.generic_select` to help with selecting generic things from a list of options.
This commit is contained in:
parent
60aaae4337
commit
a60a3ca812
|
|
@ -5,6 +5,34 @@ from .locale_helpers import search_keyboard_layout
|
||||||
## TODO: Some inconsistencies between the selection processes.
|
## TODO: Some inconsistencies between the selection processes.
|
||||||
## Some return the keys from the options, some the values?
|
## Some return the keys from the options, some the values?
|
||||||
|
|
||||||
|
def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True):
|
||||||
|
"""
|
||||||
|
A generic select function that does not output anything
|
||||||
|
other than the options and their indexs. As an example:
|
||||||
|
|
||||||
|
generic_select(["first", "second", "third option"])
|
||||||
|
1: first
|
||||||
|
2: second
|
||||||
|
3: third option
|
||||||
|
"""
|
||||||
|
|
||||||
|
if type(options) == dict: options = list(options)
|
||||||
|
if sort: options = sorted(list(options))
|
||||||
|
if len(options) <= 0: raise RequirementError('generic_select() requires at least one option to operate.')
|
||||||
|
|
||||||
|
for index, option in enumerate(options):
|
||||||
|
print(f"{index}: {option}")
|
||||||
|
|
||||||
|
selected_option = input(input_text)
|
||||||
|
if selected_option.isdigit():
|
||||||
|
selected_option = dict_o_disks[int(selected_option)-1]
|
||||||
|
elif selected_option in dict_o_disks:
|
||||||
|
pass # We gave a correct absolute value
|
||||||
|
else:
|
||||||
|
raise RequirementError(f'Selected option "{selected_option}" does not exist in available options: {options}')
|
||||||
|
|
||||||
|
return selected_option
|
||||||
|
|
||||||
def select_disk(dict_o_disks):
|
def select_disk(dict_o_disks):
|
||||||
"""
|
"""
|
||||||
Asks the user to select a harddrive from the `dict_o_disks` selection.
|
Asks the user to select a harddrive from the `dict_o_disks` selection.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
# A desktop environment selector.
|
||||||
|
|
||||||
|
import archinstall, os
|
||||||
|
|
||||||
|
def _prep_function(*args, **kwargs):
|
||||||
|
"""
|
||||||
|
Magic function called by the importing installer
|
||||||
|
before continuing any further. It also avoids executing any
|
||||||
|
other code in this stage. So it's a safe way to ask the user
|
||||||
|
for more input before any other installer steps start.
|
||||||
|
"""
|
||||||
|
|
||||||
|
supported_desktops = ['gnome', 'kde', 'awesome']
|
||||||
|
dektop = archinstall.generic_select(supported_desktops, 'Select your desired desktop environemtn: ')
|
||||||
|
|
||||||
|
profile = archinstall.Profile(None, dektop)
|
||||||
|
# Loading the instructions with a custom namespace, ensures that a __name__ comparison is never triggered.
|
||||||
|
with profile.load_instructions(namespace=f"{dektop}.py") as imported:
|
||||||
|
if hasattr(imported, '_prep_function'):
|
||||||
|
return imported._prep_function()
|
||||||
|
else:
|
||||||
|
print(f"Deprecated (??): {dektop} profile has no _prep_function() anymore")
|
||||||
|
|
||||||
|
if __name__ == 'desktop':
|
||||||
|
print('The desktop.py profile should never be executed as a stand-alone.')
|
||||||
|
|
||||||
|
"""
|
||||||
|
This "profile" is a meta-profile.
|
||||||
|
It will not return itself, there for this __name__ will never
|
||||||
|
be executed. Instead, whatever profile was selected will have
|
||||||
|
it's handle returned and that __name__ will be executed later on.
|
||||||
|
"""
|
||||||
Loading…
Reference in New Issue