Log only if config was really changed

Print to stdout only if config option has been really changed.
If the new setting is equal to old one, be silent.

Signed-off-by: Alexey Minnekhanov <alexeymin@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2539
This commit is contained in:
Alexey Minnekhanov 2025-01-28 11:25:55 +03:00
parent 9d03657b80
commit d5e4d76118
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -249,12 +249,17 @@ def config(args: PmbArgs) -> None:
name = args.name.split(".", 1)[1]
# Ignore mypy 'error: TypedDict key must be a string literal'.
# Argparse already ensures 'name' is a valid Config.Mirrors key.
config.mirrors[name] = args.value # type: ignore
if value_changed := (config.mirrors[name] != args.value): # type: ignore
config.mirrors[name] = args.value # type: ignore
elif isinstance(getattr(Config, args.name), list):
setattr(config, args.name, args.value.split(","))
new_list = args.value.split(",")
if value_changed := (getattr(config, args.name, None) != new_list):
setattr(config, args.name, new_list)
else:
setattr(config, args.name, args.value)
logging.info("Config changed: " + args.name + "='" + args.value + "'")
if value_changed := (getattr(config, args.name) != args.value):
setattr(config, args.name, args.value)
if value_changed:
print(f"{args.name} = {args.value}")
pmb.config.save(args.config, config)
elif args.name:
if hasattr(config, args.name):