You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

# Licensed under GPLv3
# Written by Sebastian Lohff (
from __future__ import print_function
import sys
def _config_error(msg):
print("Configuration error: %s" % (msg,), file=sys.stderr)
def _check_missing_keys(conf, sec, mandatory, users_choice=[]):
#d = conf[sec] if sec is not None else conf
#if sec is None:
# sec = "main"
d = conf
allowed = mandatory + users_choice
for key in d.iterkeys():
if key not in allowed:
_config_error("Key %s is not an allowed config key in section %s (allowed are %s)" % (key, sec, ", ".join(allowed)))
for key in mandatory:
if key not in d.iterkeys():
_config_error("Key %s is not present in section %s but mandatory" % (key, sec,))
def check_config(conf):
main_keys = ["music", "savedir", "playerInput"]
music_keys = ["startSong", "questionSong", "closingSong"]
_check_missing_keys(conf, "main", main_keys)
_check_missing_keys(conf["music"], "music", music_keys)
if conf["playerInput"]:
for i, inp in enumerate(conf["playerInput"], 1):
_check_missing_keys(inp, "playerInput %d" % i, ["Type"], ["Args"])