config: clean up parsing and add mirrors (MR 2252)

Add a new config section "mirrors", to replace the mirrors_alpine and
mirrors_postmarketos options. This will allow for more flexibility since
we can then handle the systemd staging repo (and others like plasma
nightly) with relative ease.

The loading/saving is fixed and now properly avoids writing out default
values, this way if the defaults are changed the user won't be stuck
with old values in their pmbootstrap.cfg.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-08 22:54:30 +02:00 committed by Oliver Smith
parent 8e18b16370
commit 7a8deb0f5e
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
5 changed files with 114 additions and 14 deletions

View file

@ -211,7 +211,7 @@ def chroot(args: PmbArgs):
def config(args: PmbArgs):
keys = pmb.config.config_keys
keys = Config.keys()
if args.name and args.name not in keys:
logging.info("NOTE: Valid config keys: " + ", ".join(keys))
raise RuntimeError("Invalid config key: " + args.name)
@ -222,7 +222,7 @@ def config(args: PmbArgs):
if args.reset:
if args.name is None:
raise RuntimeError("config --reset requires a name to be given.")
def_value = getattr(Config(), args.name)
def_value = Config.get_default(args.name)
setattr(config, args.name, def_value)
logging.info(f"Config changed to default: {args.name}='{def_value}'")
pmb.config.save(args.config, config)
@ -238,7 +238,11 @@ def config(args: PmbArgs):
value = ""
print(value)
else:
print(open(args.config).read())
# Serialize the entire config including default values for
# the user. Even though the defaults aren't actually written
# to disk.
cfg = pmb.config.serialize(config, skip_defaults=False)
cfg.write(sys.stdout)
# Don't write the "Done" message
pmb.helpers.logging.disable()