From 1a10fe3f51f7555bf8c29046c707719d7dccb33c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 09:58:33 +0200 Subject: Implementing error handling for #50. So that the errors do not come at the very end, but in the beginning right after the user inputted something (quicker feedback to the user). --- archinstall/lib/packages.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/packages.py b/archinstall/lib/packages.py index 3a671784..29728abc 100644 --- a/archinstall/lib/packages.py +++ b/archinstall/lib/packages.py @@ -1,5 +1,6 @@ import urllib.request, urllib.parse import ssl, json +from .lib.exceptions import * BASE_URL = 'https://www.archlinux.org/packages/search/json/?name={package}' @@ -24,4 +25,19 @@ def find_packages(*names): result = {} for package in names: result[package] = find_package(package) - return result \ No newline at end of file + return result + +def validate_package_list(packages :list): + """ + Validates a list of given packages. + Raises `RequirementError` if one or more packages are not found. + """ + invalid_packages = [] + for package in packages: + if not find_package(package)['results']: + invalid_packages.append(package) + + if invalid_packages: + raise RequirementError(f"Invalid package names: {invalid_packages}") + + return True \ No newline at end of file -- cgit v1.2.3-54-g00ecf From ea84565f8636c0f393e336dbbc93c15cfdba6895 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 10:03:26 +0200 Subject: Implementing error handling for #50. So that the errors do not come at the very end, but in the beginning right after the user inputted something (quicker feedback to the user). --- examples/guided.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/guided.py b/examples/guided.py index dcc8279c..83eeabe3 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -53,6 +53,7 @@ archinstall.set_keyboard_language(keyboard_language) # Set which region to download packages from during the installation mirror_regions = archinstall.select_mirror_regions(archinstall.list_mirrors()) +# Ask which harddrive/block-device we will install to harddrive = archinstall.select_disk(archinstall.all_disks()) while (disk_password := getpass.getpass(prompt='Enter disk encryption password (leave blank for no encryption): ')): disk_password_verification = getpass.getpass(prompt='And one more time for verification: ') @@ -61,9 +62,11 @@ while (disk_password := getpass.getpass(prompt='Enter disk encryption password ( continue break +# Ask for a hostname hostname = input('Desired hostname for the installation: ') if len(hostname) == 0: hostname = 'ArchInstall' +# Ask for a root password (optional, but triggers requirement for super-user if skipped) while (root_pw := getpass.getpass(prompt='Enter root password (leave blank to leave root disabled): ')): root_pw_verification = getpass.getpass(prompt='And one more time for verification: ') if root_pw != root_pw_verification: @@ -71,6 +74,7 @@ while (root_pw := getpass.getpass(prompt='Enter root password (leave blank to le continue break +# Ask for additional users (super-user if root pw was not set) users = {} new_user_text = 'Any additional users to install (leave blank for no users): ' if len(root_pw.strip()) == 0: @@ -92,6 +96,7 @@ while 1: users[new_user] = new_user_passwd break +# Ask for archinstall-specific profiles (such as desktop environments etc) while 1: profile = archinstall.select_profile(archinstall.list_profiles()) if type(profile) != str: # Got a imported profile @@ -103,7 +108,19 @@ while 1: else: break -packages = input('Additional packages aside from base (space separated): ').split(' ') +# Additional packages (with some light weight error handling for invalid package names) +while 1: + packages = [package for package in input('Additional packages aside from base (space separated): ').split(' ') if len(package)] + + try: + if packages and archinstall.validate_package_list(packages): + break + except RequirementError as e: + print(e) + +# TODO: Print a summary here of all the options chosen. +# Ideally, archinstall should keep track of this internally +# and there should be something like print(archinstall.config). """ Issue a final warning before we continue with something un-revertable. -- cgit v1.2.3-54-g00ecf From 0e8130af9a2f18603d9bc8a4331f7d67a56b1b9f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 13:13:09 +0200 Subject: Wrong relative import, corrected to avoid .lib.lib.exceptions --- archinstall/lib/packages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/packages.py b/archinstall/lib/packages.py index 29728abc..2f5ebe94 100644 --- a/archinstall/lib/packages.py +++ b/archinstall/lib/packages.py @@ -1,6 +1,6 @@ import urllib.request, urllib.parse import ssl, json -from .lib.exceptions import * +from .exceptions import * BASE_URL = 'https://www.archlinux.org/packages/search/json/?name={package}' -- cgit v1.2.3-54-g00ecf From 9c5d1e98916d41c3a8cb951dcec08217cddefbed Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 13:20:58 +0200 Subject: Added error handling to guided.py when not selecting a profile to install. --- archinstall/lib/user_interaction.py | 8 +++----- examples/guided.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index e01859b3..0d3a12f5 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -81,11 +81,9 @@ def select_profile(options): print(' -- (Leave blank to skip this next optional step) --') selected_profile = input('Any particular pre-programmed profile you want to install: ') - #print(' -- You can enter ? or help to search for more profiles --') - #if selected_profile.lower() in ('?', 'help'): - # filter_string = input('Search for layout containing (example: "sv-"): ') - # new_options = search_keyboard_layout(filter_string) - # return select_language(new_options) + if len(selected_profile.strip()) <= 0: + return None + if selected_profile.isdigit() and (pos := int(selected_profile)) <= len(profiles)-1: selected_profile = profiles[pos] elif selected_profile in options: diff --git a/examples/guided.py b/examples/guided.py index 83eeabe3..03874ada 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -24,7 +24,7 @@ def perform_installation(device, boot_partition, language, mirrors): if len(packages) and packages[0] != '': installation.add_additional_packages(packages) - if len(profile.strip()): + if profile and len(profile.strip()): installation.install_profile(profile) for user, password in users.items(): -- cgit v1.2.3-54-g00ecf From dafe304b0060c2a189f19e11d8f0e755e3d0026c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 13:21:42 +0200 Subject: Added error handling to guided.py when not selecting a profile to install. --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/guided.py b/examples/guided.py index 03874ada..f0a9d46b 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -99,7 +99,7 @@ while 1: # Ask for archinstall-specific profiles (such as desktop environments etc) while 1: profile = archinstall.select_profile(archinstall.list_profiles()) - if type(profile) != str: # Got a imported profile + if profile and type(profile) != str: # Got a imported profile if not profile[1]._prep_function(): archinstall.log(' * Profile\'s preperation requirements was not fulfilled.', bg='black', fg='red') continue -- cgit v1.2.3-54-g00ecf From 4b1f22bf91ebd635eaccde670ddba2207b59713b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 13:23:51 +0200 Subject: Added error handling to guided.py when not selecting a profile to install. --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/guided.py b/examples/guided.py index f0a9d46b..aa5ec98d 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -115,7 +115,7 @@ while 1: try: if packages and archinstall.validate_package_list(packages): break - except RequirementError as e: + except archinstall.RequirementError as e: print(e) # TODO: Print a summary here of all the options chosen. -- cgit v1.2.3-54-g00ecf From a69e1af4f1b13e0a47d4dc634c03b5bc383b9adc Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 13:25:13 +0200 Subject: Added error handling to guided.py when not selecting a profile to install. --- examples/guided.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/guided.py b/examples/guided.py index aa5ec98d..30514a71 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -112,8 +112,11 @@ while 1: while 1: packages = [package for package in input('Additional packages aside from base (space separated): ').split(' ') if len(package)] + if not packages: + break + try: - if packages and archinstall.validate_package_list(packages): + if archinstall.validate_package_list(packages): break except archinstall.RequirementError as e: print(e) -- cgit v1.2.3-54-g00ecf