From 1b3cffb3dfb165433bcf839151f1a719300fd891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Werner=20Ll=C3=A1cer?= Date: Mon, 29 Nov 2021 18:07:10 +0100 Subject: [PATCH] device configuration options taken out from ask_user_questions. Forced by flake8 --- examples/guided.py | 61 ++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/examples/guided.py b/examples/guided.py index d40243d8..b4b29eee 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -63,6 +63,39 @@ def load_config(): except: raise ValueError("--disk_layouts= needs either a JSON file or a JSON string given with a valid disk layout.") +def ask_device_configuration(): + """ Conveys the questions the user is asked about the disk configuration + """ + # forced as separate module by flake 8 + # Ask which harddrives/block-devices we will install to + # and convert them into archinstall.BlockDevice() objects. + if archinstall.arguments.get('harddrives', None) is None: + archinstall.arguments['harddrives'] = archinstall.generic_multi_select(archinstall.all_disks(), + text="Select one or more harddrives to use and configure (leave blank to skip this step): ", + allow_empty=True) + # we skip the customary .get('harddrives',None) 'cause we are pretty certain that at this point it contains at least an empty list + if not archinstall.arguments['harddrives']: + archinstall.log("You decided to skip harddrive selection",fg="red",level=logging.INFO) + archinstall.log(f"and will use whatever drive-setup is mounted at {archinstall.storage['MOUNT_POINT']} (experimental)",fg="red",level=logging.INFO) + archinstall.log("WARNING: Archinstall won't check the suitability of this setup",fg="red",level=logging.INFO) + if input("Do you wish to continue ? [Y/n]").strip().lower() == 'n': + exit(1) + else: + if archinstall.storage.get('disk_layouts', None) is None: + archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'], archinstall.arguments.get('advanced', False)) + + # Get disk encryption password (or skip if blank) + if archinstall.arguments.get('!encryption-password', None) is None: + if passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): '): + archinstall.arguments['!encryption-password'] = passwd + + if archinstall.arguments.get('!encryption-password', None): + # If no partitions was marked as encrypted, but a password was supplied and we have some disks to format.. + # Then we need to identify which partitions to encrypt. This will default to / (root). + if len(list(archinstall.encrypted_partitions(archinstall.storage['disk_layouts']))) == 0: + archinstall.storage['disk_layouts'] = archinstall.select_encrypted_partitions(archinstall.storage['disk_layouts'], archinstall.arguments['!encryption-password']) + + def ask_user_questions(): """ First, we'll ask the user for a bunch of user input. @@ -101,33 +134,7 @@ def ask_user_questions(): if not archinstall.arguments.get('sys-encoding', None): archinstall.arguments['sys-encoding'] = 'utf-8' - # Ask which harddrives/block-devices we will install to - # and convert them into archinstall.BlockDevice() objects. - if archinstall.arguments.get('harddrives', None) is None: - archinstall.arguments['harddrives'] = archinstall.generic_multi_select(archinstall.all_disks(), - text="Select one or more harddrives to use and configure (leave blank to skip this step): ", - allow_empty=True) - # we skip the customary .get('harddrives',None) 'cause we are pretty certain that at this point it contains at least an empty list - if not archinstall.arguments['harddrives']: - archinstall.log("You decided to skip harddrive selection",fg="red",level=logging.INFO) - archinstall.log(f"and will use whatever drive-setup is mounted at {archinstall.storage['MOUNT_POINT']} (experimental)",fg="red",level=logging.INFO) - archinstall.log("WARNING: Archinstall won't check the suitability of this setup",fg="red",level=logging.INFO) - if input("Do you wish to continue ? [Y/n]").strip().lower() == 'n': - exit(1) - else: - if archinstall.storage.get('disk_layouts', None) is None: - archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'], archinstall.arguments.get('advanced', False)) - - # Get disk encryption password (or skip if blank) - if archinstall.arguments.get('!encryption-password', None) is None: - if passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): '): - archinstall.arguments['!encryption-password'] = passwd - - if archinstall.arguments.get('!encryption-password', None): - # If no partitions was marked as encrypted, but a password was supplied and we have some disks to format.. - # Then we need to identify which partitions to encrypt. This will default to / (root). - if len(list(archinstall.encrypted_partitions(archinstall.storage['disk_layouts']))) == 0: - archinstall.storage['disk_layouts'] = archinstall.select_encrypted_partitions(archinstall.storage['disk_layouts'], archinstall.arguments['!encryption-password']) + ask_device_configuration() # Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode) if not archinstall.arguments.get("bootloader", None):