From d62d7c8622cc2d9d977f7d35741e8da1da381d5e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 19 Nov 2017 15:38:44 +0100 Subject: Add: check config (allows keys only, no None values) --- ick_controller.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ick_controller.py') diff --git a/ick_controller.py b/ick_controller.py index 58b05e8..7c611a8 100644 --- a/ick_controller.py +++ b/ick_controller.py @@ -56,6 +56,15 @@ def load_config(filename, defconf): return actual_config +def check_config(config, musthave): + for key in config: + if key not in musthave: + raise Exception('Config %s is not known' % key) + for key in musthave: + if config.get(key) is None: + raise Exception('Config %s must not be None' % key) + + def main(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) @@ -76,6 +85,7 @@ def main(): logging.info('config is %r', config) ick2.setup_logging(config) + check_config(config, default_config) ick2.log.log('info', msg_text='Ick2 controller starts', config=config) @@ -92,9 +102,12 @@ def main(): return application except SystemExit: - pass + raise except BaseException as e: logging.error(str(e)) + ick2.log.log( + 'error', msg_text='Uncaught exception', exception=str(e), + exc_info=True) sys.exit(1) -- cgit v1.2.1