index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Daniel <blackrabbit256@gmail.com> | 2022-03-01 03:03:37 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-28 17:03:37 +0100 |
commit | 35a19a616aee602a849097411cc0254a27c3f9b7 (patch) | |
tree | 5b1db96f151fae55f7b76e06066fc747daf6b070 /archinstall/lib/user_interaction.py | |
parent | 04e3880d8f41a87889690609e20ab1220700c163 (diff) |
-rw-r--r-- | archinstall/lib/user_interaction.py | 66 |
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 1f62b7fd..f87f83be 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -9,11 +9,13 @@ import signal import sys import time from collections.abc import Iterable +from pathlib import Path from copy import copy from typing import List, Any, Optional, Dict, Union, TYPE_CHECKING # https://stackoverflow.com/a/39757388/929999 from .menu.text_input import TextInput +from .configuration import ConfigurationOutput from .models.network_configuration import NetworkConfiguration, NicType if TYPE_CHECKING: @@ -1165,3 +1167,67 @@ def generic_multi_select(p_options :Union[list,dict], sort=sort, multi=True, default=default) + + +def save_config(config: Dict): + def preview(selection: str): + if options['user_config'] == selection: + json_config = config_output.user_config_to_json() + return f'{config_output.user_configuration_file}\n{json_config}' + elif options['user_creds'] == selection: + if json_config := config_output.user_credentials_to_json(): + return f'{config_output.user_credentials_file}\n{json_config}' + else: + return str(_('No configuration')) + elif options['disk_layout'] == selection: + if json_config := config_output.disk_layout_to_json(): + return f'{config_output.disk_layout_file}\n{json_config}' + else: + return str(_('No configuration')) + elif options['all'] == selection: + output = f'{config_output.user_configuration_file}\n' + if json_config := config_output.user_credentials_to_json(): + output += f'{config_output.user_credentials_file}\n' + if json_config := config_output.disk_layout_to_json(): + output += f'{config_output.disk_layout_file}\n' + return output[:-1] + return None + + config_output = ConfigurationOutput(config) + + options = { + 'user_config': str(_('Save user configuration')), + 'user_creds': str(_('Save user credentials')), + 'disk_layout': str(_('Save disk layout')), + 'all': str(_('Save all')) + } + + selection = Menu( + _('Choose which configuration to save'), + list(options.values()), + sort=False, + skip=True, + preview_size=0.75, + preview_command=preview + ).run() + + if not selection: + return + + while True: + path = input(_('Enter a directory for the configuration(s) to be saved: ')).strip(' ') + dest_path = Path(path) + if dest_path.exists() and dest_path.is_dir(): + break + log(_('Not a valid directory: {}').format(dest_path), fg='red') + + if options['user_config'] == selection: + config_output.save_user_config(dest_path) + elif options['user_creds'] == selection: + config_output.save_user_creds(dest_path) + elif options['disk_layout'] == selection: + config_output.save_disk_layout(dest_path) + elif options['all'] == selection: + config_output.save_user_config(dest_path) + config_output.save_user_creds(dest_path) + config_output.save_disk_layout(dest_path) |