pmbootstrap-meow/pmb/config/merge_with_args.py
Oliver Smith a7b881e4cc
Close #871: Enable binary repository (#887)
* add my own build key
* enable the repo in the config
* update the README file
* Adjust testcase, that validates the keys and enable it in testcases_fast.sh
* Only save/load keys to/from the config file, which we ask for during
  'pmbootstrap init', so the binary repo gets used even if a config file
  already exists (this also removes a workaround, that deletes the work
  folder path from the config dictionary before writing it)
* Download missing APKINDEX.tar.gz files with Python code, before
  attempting to build packages (so we know which ones aleady exist in
  the binary packages repository)
* Consider APKINDEX files older than 4 hours as outdated and download
  them again (also in Python code)
* Provide 'pmbootstrap update' to force-update the APKINDEX files
* Travis: more logging output on failure
* Only allow keys from config_keys to be used by "pmbootstrap config"
2017-11-19 15:04:08 +00:00

51 lines
2 KiB
Python

"""
Copyright 2017 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import pmb.config
def merge_with_args(args):
"""
We have the internal config (pmb/config/__init__.py) and the user config
(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)
# 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)