config: fixes + handle mirrors migration (MR 2252)

Get rid of config.mirror_alpine and mirrors_postmarketos and make sure
they get migrated over for existing users.

mirrors_postmarketos being a list was always a bit off, but now we have
per-aports mirrors which make a lot more sense for what we're trying to
do with systemd.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-10 05:46:26 +02:00 committed by Oliver Smith
parent aedab4df73
commit fc010bc7c8
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
7 changed files with 44 additions and 72 deletions

View file

@ -31,14 +31,15 @@ def load(path: Path) -> Config:
if key not in cfg["pmbootstrap"]:
continue
elif key == "mirror_alpine":
# DEPRCATED: We have special handling for this below.
# DEPRCATED
config.mirrors["alpine"] = cfg["pmbootstrap"]["mirror_alpine"]
continue
# Handle whacky type conversions
elif key == "mirrors_postmarketos":
mirrors = cfg["pmbootstrap"]["mirrors_postmarketos"].split(",")
if len(mirrors) > 1:
logging.warning("Multiple mirrors are not supported, using the last one")
config.mirrors_postmarketos = [mirrors[-1].strip("/master")]
config.mirrors["pmaports"] = mirrors[-1].strip("/master")
# Convert strings to paths
elif type(getattr(Config, key)) == PosixPath:
setattr(config, key, Path(cfg["pmbootstrap"][key]))
@ -52,8 +53,7 @@ def load(path: Path) -> Config:
setattr(config, key, cfg["pmbootstrap"][key])
# One time migration "mirror_alpine" -> mirrors.alpine
if "mirror_alpine" in cfg["pmbootstrap"]:
config.mirrors["alpine"] = cfg["pmbootstrap"]["mirror_alpine"]
if "mirror_alpine" in cfg["pmbootstrap"] or "mirrors_postmarketos" in cfg["pmbootstrap"]:
save(path, config)
return config
@ -87,9 +87,6 @@ def serialize(config: Config, skip_defaults=True) -> configparser.ConfigParser:
elif key.startswith("mirrors."):
_key = key.split(".")[1]
cfg["mirrors"][_key] = getattr(config, key)
# Handle whacky type conversions
elif key == "mirrors_postmarketos":
cfg["pmbootstrap"]["mirrors_postmarketos"] = ",".join(config.mirrors_postmarketos)
# Convert strings to paths
elif type(getattr(Config, key)) == PosixPath:
cfg["pmbootstrap"][key] = str(getattr(config, key))