No Description
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.

config.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Licensed under GPLv3
  2. # Written by Sebastian Lohff (seba@someserver.de)
  3. # http://seba-geek.de/projects/seopardy/
  4. from __future__ import print_function
  5. import sys
  6. def _config_error(msg):
  7. print("Configuration error: %s" % (msg,), file=sys.stderr)
  8. sys.exit(1)
  9. def _check_missing_keys(conf, sec, mandatory, users_choice=[]):
  10. #d = conf[sec] if sec is not None else conf
  11. #if sec is None:
  12. # sec = "main"
  13. d = conf
  14. allowed = mandatory + users_choice
  15. for key in d.iterkeys():
  16. if key not in allowed:
  17. _config_error("Key %s is not an allowed config key in section %s (allowed are %s)" % (key, sec, ", ".join(allowed)))
  18. for key in mandatory:
  19. if key not in d.iterkeys():
  20. _config_error("Key %s is not present in section %s but mandatory" % (key, sec,))
  21. def check_config(conf):
  22. main_keys = ["music", "savedir", "playerInput"]
  23. music_keys = ["startSong", "questionSong", "closingSong"]
  24. _check_missing_keys(conf, "main", main_keys)
  25. _check_missing_keys(conf["music"], "music", music_keys)
  26. if conf["playerInput"]:
  27. for i, inp in enumerate(conf["playerInput"], 1):
  28. _check_missing_keys(inp, "playerInput %d" % i, ["Type"], ["Args"])