mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-06-25 18:08:22 -04:00
config: add Config.enforce_profile_flavour_set()
This commit is contained in:
parent
d3cdd64aea
commit
2a20f6c45a
3 changed files with 15 additions and 8 deletions
|
@ -172,7 +172,7 @@ def cmd_config_init(ctx, sections: list[str] = CONFIG_SECTIONS, non_interactive:
|
||||||
config.update(results)
|
config.update(results)
|
||||||
if 'profiles' in sections:
|
if 'profiles' in sections:
|
||||||
current_profile = 'default' if 'current' not in config.file.profiles else config.file.profiles.current
|
current_profile = 'default' if 'current' not in config.file.profiles else config.file.profiles.current
|
||||||
new_current, _ = prompt_config('profile.current', default=current_profile, field_type=str)
|
new_current, _ = prompt_config('profiles.current', default=current_profile, field_type=str)
|
||||||
profile, changed = prompt_profile(new_current, create=True)
|
profile, changed = prompt_profile(new_current, create=True)
|
||||||
config.update_profile(new_current, profile)
|
config.update_profile(new_current, profile)
|
||||||
if not noop:
|
if not noop:
|
||||||
|
|
|
@ -233,7 +233,8 @@ class ConfigStateHolder:
|
||||||
self._profile_cache = resolve_profile(name=name, sparse_profiles=self.file.profiles, resolved=self._profile_cache)
|
self._profile_cache = resolve_profile(name=name, sparse_profiles=self.file.profiles, resolved=self._profile_cache)
|
||||||
return self._profile_cache[name]
|
return self._profile_cache[name]
|
||||||
|
|
||||||
def enforce_profile_device_set(self, profile_name: Optional[str] = None, hint_or_set_arch: bool = False) -> Profile:
|
def _enforce_profile_field(self, field: str, profile_name: Optional[str] = None, hint_or_set_arch: bool = False) -> Profile:
|
||||||
|
# TODO: device
|
||||||
profile_name = profile_name if profile_name is not None else self.file.profiles.current
|
profile_name = profile_name if profile_name is not None else self.file.profiles.current
|
||||||
arch_hint = ''
|
arch_hint = ''
|
||||||
if not hint_or_set_arch:
|
if not hint_or_set_arch:
|
||||||
|
@ -243,20 +244,26 @@ class ConfigStateHolder:
|
||||||
'e.g. `kupferbootstrap packages build --arch x86_64`')
|
'e.g. `kupferbootstrap packages build --arch x86_64`')
|
||||||
if not self.is_loaded():
|
if not self.is_loaded():
|
||||||
if not self.file_state.exception:
|
if not self.file_state.exception:
|
||||||
raise Exception('Error enforcing/ config profile device: config hadnt even been loaded yet.\n'
|
raise Exception(f'Error enforcing config profile {field}: config hadn\'t even been loaded yet.\n'
|
||||||
'This is a bug in kupferbootstrap!')
|
'This is a bug in kupferbootstrap!')
|
||||||
raise Exception("Profile device couldn't be resolved because the config file couldn't be loaded.\n"
|
raise Exception(f"Profile {field} couldn't be resolved because the config file couldn't be loaded.\n"
|
||||||
"If the config doesn't exist, try running `kupferbootstrap config init`.\n"
|
"If the config doesn't exist, try running `kupferbootstrap config init`.\n"
|
||||||
f"Error: {self.file_state.exception}")
|
f"Error: {self.file_state.exception}")
|
||||||
if profile_name and profile_name not in self.file.profiles:
|
if profile_name and profile_name not in self.file.profiles:
|
||||||
raise Exception(f'Unknown profile "{profile_name}". Please run `kupferbootstrap config profile init`{arch_hint}')
|
raise Exception(f'Unknown profile "{profile_name}". Please run `kupferbootstrap config profile init`{arch_hint}')
|
||||||
profile = self.get_profile(profile_name)
|
profile = self.get_profile(profile_name)
|
||||||
if not profile.device:
|
if field not in profile or not profile[field]:
|
||||||
m = (f'Profile "{profile_name}" has no device configured.\n'
|
m = (f'Profile "{profile_name}" has no {field.upper()} configured.\n'
|
||||||
f'Please run `kupferbootstrap config profile init device`{arch_hint}')
|
f'Please run `kupferbootstrap config profile init {field}`{arch_hint}')
|
||||||
raise Exception(m)
|
raise Exception(m)
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
|
def enforce_profile_device_set(self, **kwargs) -> Profile:
|
||||||
|
return self._enforce_profile_field(field='device', **kwargs)
|
||||||
|
|
||||||
|
def enforce_profile_flavour_set(self, **kwargs) -> Profile:
|
||||||
|
return self._enforce_profile_field(field='flavour', **kwargs)
|
||||||
|
|
||||||
def get_path(self, path_name: str) -> str:
|
def get_path(self, path_name: str) -> str:
|
||||||
paths = self.file.paths
|
paths = self.file.paths
|
||||||
return resolve_path_template(paths[path_name], paths)
|
return resolve_path_template(paths[path_name], paths)
|
||||||
|
|
|
@ -146,5 +146,5 @@ def get_device(name: str, pkgbuilds: Optional[dict[str, Pkgbuild]] = None, lazy:
|
||||||
|
|
||||||
|
|
||||||
def get_profile_device(profile_name: Optional[str] = None, hint_or_set_arch: bool = False):
|
def get_profile_device(profile_name: Optional[str] = None, hint_or_set_arch: bool = False):
|
||||||
profile = config.enforce_profile_device_set(profile_name, hint_or_set_arch=hint_or_set_arch)
|
profile = config.enforce_profile_device_set(profile_name=profile_name, hint_or_set_arch=hint_or_set_arch)
|
||||||
return get_device(profile.device)
|
return get_device(profile.device)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue