Close #326: Implement command to retrieve and set configuration values (#359)

* Implement command to retrieve and set configuration values
* qemu: show advice to use "pmbootstrap config"
* Allow "pmbootstrap config" without positional arguments (prints the full config)
* Check valid variable names
This commit is contained in:
Pablo Castellano 2017-08-14 16:25:28 +02:00 committed by Oliver Smith
parent ab1bcd2e6f
commit 401c29af76
4 changed files with 34 additions and 1 deletions

View file

@ -21,6 +21,8 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
import logging
import json
import sys
import pmb.aportgen
import pmb.build
import pmb.config
@ -80,6 +82,25 @@ def chroot(args):
pmb.chroot.root(args, args.command, suffix, log=False)
def config(args):
pmb.helpers.logging.disable()
if args.name and args.name not in pmb.config.defaults:
valid_keys = ", ".join(sorted(pmb.config.defaults.keys()))
print("The variable name you have specified is invalid.")
print("The following are supported: " + valid_keys)
sys.exit(1)
cfg = pmb.config.load(args)
if args.value:
cfg["pmbootstrap"][args.name] = args.value
pmb.config.save(args, cfg)
elif args.name:
value = cfg["pmbootstrap"].get(args.name, "")
print(value)
else:
cfg.write(sys.stdout)
def index(args):
pmb.build.index_repo(args)