pmbootstrap/pmb/config/merge_with_args.py

38 lines
1.4 KiB
Python
Raw Normal View History

2023-01-22 18:11:10 +00:00
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.config
def merge_with_args(args):
"""
We have the internal config (pmb/config/__init__.py) and the user config
2021-05-19 19:24:52 +00:00
(usually ~/.config/pmbootstrap.cfg, can be changed with the '-c'
parameter).
Args holds the variables parsed from the commandline (e.g. -j fills out
args.jobs), and values specified on the commandline count the most.
In case it is not specified on the commandline, for the keys in
pmb.config.config_keys, we look into the value set in the the user config.
When that is empty as well (e.g. just before pmbootstrap init), or the key
is not in pmb.config_keys, we use the default value from the internal
config.
"""
# Use defaults from the user's config file
cfg = pmb.config.load(args)
for key in cfg["pmbootstrap"]:
if key not in args or getattr(args, key) is None:
value = cfg["pmbootstrap"][key]
if key in pmb.config.defaults:
default = pmb.config.defaults[key]
if isinstance(default, bool):
value = (value.lower() == "true")
setattr(args, key, value)
pmb.config/install: add flexible provider selection for "pmbootstrap init" (MR 2132) The provider selection for "pmbootstrap init" added in this commit is a flexible way to offer UI/device-specific configuration options in "pmbootstrap init", without hardcoding them in pmbootstrap. Instead, the options are defined entirely in pmaports using APK's virtual package provider mechanism. The code in pmbootstrap searches for available providers and displays them together with their pkgdesc. There are many possible use cases for this but I have tested two so far: 1. Selecting root provider (sudo vs doas). This can be defined entirely in postmarketos-base, without having to handle this specifically in pmbootstrap. $ pmbootstrap init [...] Available providers for postmarketos-root (2): * sudo: Use sudo to run root commands (**default**) * doas: Use doas (minimal replacement for sudo) to run root commands (Note: Does not support all functionality of sudo) Provider [default]: doas 2. Device-specific options. My main motivation for working on this feature is a new configuration option for the MSM8916-based devices. It allows more control about which firmware to enable: $ pmbootstrap init [...] Available providers for soc-qcom-msm8916-rproc (3): * all: Enable all remote processors (audio goes through modem) (default) * no-modem: Disable only modem (audio bypasses modem, ~80 MiB more RAM) * none: Disable all remote processors (no WiFi/BT/modem, ~90 MiB more RAM) Provider [default]: no-modem The configuration prompts show up dynamically by defining _pmb_select="<virtual packages>" in postmarketos-base, a UI PKGBUILD or the device APKBUILD. Selecting "default" (just pressing enter) means that no provider is selected. This allows APK to choose it automatically based on the "provider_priority". It also provides compatibility with existing installation; APK will just choose the default provider when upgrading. The selection can still be changed after installation by installing another provider using "apk". Note that at the end this is just a more convenient interface for the already existing "extra packages" prompt. When using pmbootstrap in automated scripts the providers (e.g. "postmarketos-root-doas") can be simply selected through the existing "extra_packages" option.
2021-10-22 10:57:01 +00:00
setattr(args, 'selected_providers', cfg['providers'])
# Use defaults from pmb.config.defaults
for key, value in pmb.config.defaults.items():
if key not in args or getattr(args, key) is None:
setattr(args, key, value)