From 2cb7d10ac77b618019cac8c3d1c9ec15fbfd0709 Mon Sep 17 00:00:00 2001 From: Min RK Date: Sat, 21 Jul 2018 00:18:58 -0700 Subject: [PATCH] add load_config top-level function to configurer for easy loading of the full config --- tljh/configurer.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tljh/configurer.py b/tljh/configurer.py index 4863204..ddc7a9d 100644 --- a/tljh/configurer.py +++ b/tljh/configurer.py @@ -7,6 +7,13 @@ be called many times per lifetime of a jupyterhub. Traitlets that modify the startup of JupyterHub should not be here. FIXME: A strong feeling that JSON Schema should be involved somehow. """ + +import os +import yaml + +INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh') +CONFIG_FILE = os.path.join(INSTALL_PREFIX, 'config.yaml') + # Default configuration for tljh # User provided config is merged into this default = { @@ -32,6 +39,19 @@ default = { } +def load_config(config_file=CONFIG_FILE): + """Load the current config as a dictionary + + merges overrides from config.yaml with default config + """ + if os.path.exists(config_file): + with open(config_file) as f: + config_overrides = yaml.safe_load(f) + else: + config_overrides = {} + return _merge_dictionaries(dict(default), config_overrides) + + def apply_config(config_overrides, c): """ Merge config_overrides with config defaults & apply to JupyterHub config c