Add initial questions to Auto Setup
This commit is contained in:
parent
02055c5b30
commit
0fc5c4b146
2 changed files with 60 additions and 20 deletions
|
|
@ -11,6 +11,7 @@ import wk # pylint: disable=wrong-import-position
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
PRESETS = {
|
PRESETS = {
|
||||||
|
'Default': {}, # Will be built at runtime using BASE_MENUS
|
||||||
'Additional User': {
|
'Additional User': {
|
||||||
'Configure System': (
|
'Configure System': (
|
||||||
'Chrome Notifications',
|
'Chrome Notifications',
|
||||||
|
|
@ -31,7 +32,7 @@ PRESETS = {
|
||||||
'Windows Activation',
|
'Windows Activation',
|
||||||
'Secure Boot',
|
'Secure Boot',
|
||||||
'Installed RAM',
|
'Installed RAM',
|
||||||
'Storage Volumes',
|
'Storage Status',
|
||||||
'Virus Protection',
|
'Virus Protection',
|
||||||
'Partitions 4K Aligned',
|
'Partitions 4K Aligned',
|
||||||
),
|
),
|
||||||
|
|
@ -52,7 +53,7 @@ PRESETS = {
|
||||||
'Windows Activation',
|
'Windows Activation',
|
||||||
'Secure Boot',
|
'Secure Boot',
|
||||||
'Installed RAM',
|
'Installed RAM',
|
||||||
'Storage Volumes',
|
'Storage Status',
|
||||||
'Virus Protection',
|
'Virus Protection',
|
||||||
'Partitions 4K Aligned',
|
'Partitions 4K Aligned',
|
||||||
),
|
),
|
||||||
|
|
@ -76,7 +77,7 @@ PRESETS = {
|
||||||
'Windows Activation',
|
'Windows Activation',
|
||||||
'Secure Boot',
|
'Secure Boot',
|
||||||
'Installed RAM',
|
'Installed RAM',
|
||||||
'Storage Volumes',
|
'Storage Status',
|
||||||
'Virus Protection',
|
'Virus Protection',
|
||||||
'Installed Office',
|
'Installed Office',
|
||||||
'Partitions 4K Aligned',
|
'Partitions 4K Aligned',
|
||||||
|
|
@ -88,19 +89,15 @@ PRESETS = {
|
||||||
class MenuEntry():
|
class MenuEntry():
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
"""Simple class to allow cleaner code below."""
|
"""Simple class to allow cleaner code below."""
|
||||||
def __init__(self, name, function=None, **kwargs):
|
def __init__(self, name, function=None, selected=True, **kwargs):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.details = {
|
self.details = {
|
||||||
'Function': function,
|
'Function': function,
|
||||||
'Selected': True,
|
'Selected': selected,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# TODO: DELETEME
|
|
||||||
def no_op(*args):
|
|
||||||
"""No Op"""
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
BASE_MENUS = {
|
BASE_MENUS = {
|
||||||
'Groups': {
|
'Groups': {
|
||||||
|
|
@ -113,7 +110,7 @@ BASE_MENUS = {
|
||||||
'Install Software': (
|
'Install Software': (
|
||||||
MenuEntry('Visual C++ Runtimes', 'auto_install_vcredists'),
|
MenuEntry('Visual C++ Runtimes', 'auto_install_vcredists'),
|
||||||
MenuEntry('Firefox', 'auto_install_firefox'),
|
MenuEntry('Firefox', 'auto_install_firefox'),
|
||||||
MenuEntry('LibreOffice', 'auto_install_libreoffice'),
|
MenuEntry('LibreOffice', 'auto_install_libreoffice', selected=False),
|
||||||
MenuEntry('Open Shell', 'auto_install_open_shell'),
|
MenuEntry('Open Shell', 'auto_install_open_shell'),
|
||||||
MenuEntry('Software Bundle', 'auto_install_software_bundle'),
|
MenuEntry('Software Bundle', 'auto_install_software_bundle'),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ from wk.std import (
|
||||||
clear_screen,
|
clear_screen,
|
||||||
color_string,
|
color_string,
|
||||||
pause,
|
pause,
|
||||||
|
print_error,
|
||||||
print_info,
|
print_info,
|
||||||
print_standard,
|
print_standard,
|
||||||
print_warning,
|
print_warning,
|
||||||
|
|
@ -299,6 +300,12 @@ def build_menus(base_menus, title, presets):
|
||||||
sys.modules[__name__], _function,
|
sys.modules[__name__], _function,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Update presets
|
||||||
|
for group, entries in base_menus['Groups'].items():
|
||||||
|
presets['Default'][group] = tuple(
|
||||||
|
entry.name for entry in entries if entry.details['Selected']
|
||||||
|
)
|
||||||
|
|
||||||
# Update presets Menu
|
# Update presets Menu
|
||||||
MENU_PRESETS.title = f'{title}\n{color_string("Load Preset", "GREEN")}'
|
MENU_PRESETS.title = f'{title}\n{color_string("Load Preset", "GREEN")}'
|
||||||
MENU_PRESETS.add_option('Default')
|
MENU_PRESETS.add_option('Default')
|
||||||
|
|
@ -312,23 +319,42 @@ def build_menus(base_menus, title, presets):
|
||||||
return menus
|
return menus
|
||||||
|
|
||||||
|
|
||||||
|
def check_os_and_set_menu_title(title):
|
||||||
|
"""Check OS version and update title for menus, returns str."""
|
||||||
|
color = None
|
||||||
|
os_name = get_os_name(check=False)
|
||||||
|
print_standard(f'Operating System: {os_name}')
|
||||||
|
|
||||||
|
# Check support status and set color
|
||||||
|
try:
|
||||||
|
get_os_name()
|
||||||
|
except GenericWarning:
|
||||||
|
# Outdated version
|
||||||
|
print_warning('OS version is outdated, updating is recommended.')
|
||||||
|
if not ask('Continue anyway?'):
|
||||||
|
abort()
|
||||||
|
color = 'YELLOW'
|
||||||
|
except GenericError:
|
||||||
|
# Unsupported version
|
||||||
|
print_error('OS version is unsupported, updating is recommended.')
|
||||||
|
if not ask('Continue anyway? (NOT RECOMMENDED)'):
|
||||||
|
abort()
|
||||||
|
color = 'RED'
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return f'{title} ({color_string(os_name, color)})'
|
||||||
|
|
||||||
|
|
||||||
def load_preset(menus, presets):
|
def load_preset(menus, presets):
|
||||||
"""Load menu settings from preset."""
|
"""Load menu settings from preset, returns selection (str)."""
|
||||||
selection = MENU_PRESETS.simple_select()
|
selection = MENU_PRESETS.simple_select()
|
||||||
|
|
||||||
# Exit early
|
# Exit early
|
||||||
if 'Main Menu' in selection:
|
if 'Main Menu' in selection:
|
||||||
return
|
return None
|
||||||
if 'Quit' in selection:
|
if 'Quit' in selection:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
# Default case
|
|
||||||
if 'Default' in selection:
|
|
||||||
for menu in menus.values():
|
|
||||||
for name in menu.options:
|
|
||||||
menu.options[name]['Selected'] = True
|
|
||||||
return
|
|
||||||
|
|
||||||
# Load preset
|
# Load preset
|
||||||
preset = presets[selection[0]]
|
preset = presets[selection[0]]
|
||||||
for group, menu in menus.items():
|
for group, menu in menus.items():
|
||||||
|
|
@ -337,6 +363,9 @@ def load_preset(menus, presets):
|
||||||
value = group_enabled and name in preset[group]
|
value = group_enabled and name in preset[group]
|
||||||
menu.options[name]['Selected'] = value
|
menu.options[name]['Selected'] = value
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return selection[0]
|
||||||
|
|
||||||
|
|
||||||
def run_auto_setup(base_menus, presets):
|
def run_auto_setup(base_menus, presets):
|
||||||
"""Run Auto Setup."""
|
"""Run Auto Setup."""
|
||||||
|
|
@ -346,11 +375,24 @@ def run_auto_setup(base_menus, presets):
|
||||||
set_title(title)
|
set_title(title)
|
||||||
print_info(title)
|
print_info(title)
|
||||||
print('')
|
print('')
|
||||||
|
print_standard('Initializing...')
|
||||||
|
|
||||||
|
# Check OS and update title for menus
|
||||||
|
title = check_os_and_set_menu_title(title)
|
||||||
|
|
||||||
# Generate menus
|
# Generate menus
|
||||||
print_standard('Initializing...')
|
|
||||||
menus = build_menus(base_menus, title, presets)
|
menus = build_menus(base_menus, title, presets)
|
||||||
|
|
||||||
|
# Get setup preset and ask initial questions
|
||||||
|
MENU_PRESETS.actions['Main Menu'].update({'Disabled':True, 'Hidden':True})
|
||||||
|
selection = load_preset(menus, presets)
|
||||||
|
MENU_PRESETS.actions['Main Menu'].update({'Disabled':False, 'Hidden':False})
|
||||||
|
clear_screen()
|
||||||
|
print_standard(f'{title}')
|
||||||
|
print('')
|
||||||
|
if selection == 'Default' and ask('Install LibreOffice?'):
|
||||||
|
menus['Install Software'].options['LibreOffice']['Selected'] = True
|
||||||
|
|
||||||
# Show Menu
|
# Show Menu
|
||||||
show_main_menu(base_menus, menus, presets)
|
show_main_menu(base_menus, menus, presets)
|
||||||
|
|
||||||
|
|
@ -1044,6 +1086,7 @@ def open_windows_updates():
|
||||||
|
|
||||||
def open_xmplay():
|
def open_xmplay():
|
||||||
"""Open XMPlay."""
|
"""Open XMPlay."""
|
||||||
|
sleep(2)
|
||||||
run_tool('XMPlay', 'XMPlay', 'music.7z', cbin=True, cwd=True, popen=True)
|
run_tool('XMPlay', 'XMPlay', 'music.7z', cbin=True, cwd=True, popen=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue