pmbootstrap-meow/pmb/config/load.py
Oliver Smith f21c216a26
Cosmetic: use SPDX license header (!1877)
While at it, also remove unnecessary "#!/usr/bin/env python3" in files
that only get imported, and adjust other empty/comment lines in the
beginnings of the files for consistency.

This makes files easier to read, and makes the pmbootstrap codebase more
consistent with the build.postmarketos.org codebase.
2020-02-24 03:11:10 +03:00

31 lines
1.1 KiB
Python

# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import configparser
import os
import pmb.config
def load(args):
cfg = configparser.ConfigParser()
if os.path.isfile(args.config):
cfg.read(args.config)
if "pmbootstrap" not in cfg:
cfg["pmbootstrap"] = {}
for key in pmb.config.defaults:
if key in pmb.config.config_keys and key not in cfg["pmbootstrap"]:
cfg["pmbootstrap"][key] = str(pmb.config.defaults[key])
# We used to save default values in the config, which can *not* be
# configured in "pmbootstrap init". That doesn't make sense, we always
# want to use the defaults from pmb/config/__init__.py in that case, not
# some outdated version we saved some time back (eg. aports folder,
# postmarketOS binary packages mirror).
if key not in pmb.config.config_keys and key in cfg["pmbootstrap"]:
logging.debug("Ignored unconfigurable and possibly outdated default"
" value from config: " + str(cfg["pmbootstrap"][key]))
del cfg["pmbootstrap"][key]
return cfg