From 52a08a492f28a09a237ed0367c8cc03b53d72112 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 1 Sep 2020 13:43:19 +0200 Subject: Added user interaction: select_mirror_Regions --- archinstall/lib/user_interaction.py | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index f9e7bf18..8b093f13 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -38,7 +38,7 @@ def select_language(options, show_only_country_codes=True): # I'm leaving "options" on purpose here. # Since languages possibly contains a filtered version of # all possible language layouts, and we might want to write - # for instance sv-latin1 (if we know that exists) without havnig to + # for instance sv-latin1 (if we know that exists) without having to # go through the search step. elif selected_language in options: selected_language = options[options.index(selected_language)] @@ -46,4 +46,40 @@ def select_language(options, show_only_country_codes=True): RequirementError("Selected language does not exist.") return selected_language + raise RequirementError("Selecting languages require a least one language to be given as an option.") + +def select_mirror_regions(mirrors, show_top_mirrors=True): + # TODO: Support multiple options and country ycodes, SE,UK for instance. + regions = sorted(list(regions.keys())) + selected_mirrors = {} + + if len(regions) >= 1: + for index, region in enumerate(regionss): + print(f"{index}: {region}") + + print(' -- You can enter ? or help to search for more regions --') + selected_mirror = input('Select one of the above regions to download packages from (by number or full name): ') + if selected_mirror.lower() in ('?', 'help'): + filter_string = input('Search for a region containing (example: "united"): ').strip().lower() + for region in mirrors: + if filter_string in region.lower(): + selected_mirrors[region] = mirrors[region] + + return selected_mirrors + + elif selected_mirror.isdigit() and (pos := int(selected_mirror)) <= len(languages)-1: + region = sorted(list(mirrors.keys()))[int(selected_mirror)] + selected_mirrors[region] = mirrors[region] + # I'm leaving "mirrors" on purpose here. + # Since region possibly contains a known region of + # all possible regions, and we might want to write + # for instance Sweden (if we know that exists) without having to + # go through the search step. + elif selected_mirror in mirrors: + selected_mirrors[selected_mirror] = mirrors[mirrors.index(selected_mirror)] + else: + RequirementError("Selected language does not exist.") + + return selected_mirrors + raise RequirementError("Selecting languages require a least one language to be given as an option.") \ No newline at end of file -- cgit v1.2.3-70-g09d2