config: prompt_profile(): handle uninitialised PKGBUILDs gracefully and warn user

This commit is contained in:
InsanePrawn 2022-09-14 04:02:36 +02:00
parent 72d9bf3a37
commit ba5cda7cfa

View file

@ -1,5 +1,7 @@
import click
import logging
import os
from copy import deepcopy
from typing import Any, Iterable, Optional, Union
@ -89,6 +91,15 @@ def prompt_profile(
raise Exception(f'Unknown profile "{name}"')
logging.info(f'Configuring profile "{name}"')
changed = False
if not (no_parse or os.path.exists(os.path.join(config.get_path('pkgbuilds'), 'device'))):
logging.warning("PKGBUILDS NOT INITIALISED:\n"
"Usually we'd present you with detailed lists of choices for devices and flavours in this dialogue,\n"
"but your pkgbuilds.git seem to not have been cloned yet.\n\n"
"You can:\n1. complete the dialogue with default values for now\n"
"2. run `kupferbootstrap packages update` afterwards\n"
f"3. then get back to this dialogue by running `kupferbootstrap config profile init {name}`\n\n"
"You can also use `kupferbootstrap packages flavours` and `kupferbootstrap packages devices` to list them.")
no_parse = True
for key, current in profile.items():
current = profile[key]
text = f'{name}.{key}'
@ -99,7 +110,7 @@ def prompt_profile(
elif key == 'flavour':
parse_prompt = prompt_profile_flavour
else:
raise Exception(f'config: Unhanled parseable field {key}, this is a bug in kupferbootstrap.')
raise Exception(f'config: Unhandled parseable field {key}, this is a bug in kupferbootstrap.')
result, _changed = parse_prompt(current, name) # type: ignore
else:
result, _changed = prompt_config(text=text, default=current, field_type=type(PROFILE_DEFAULTS[key])) # type: ignore