From adebcc80a4213510dd49e981a5be922469e54436 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Sat, 11 Feb 2017 19:48:25 -0600 Subject: [PATCH] fix config file handling so that apps can be run from dev copies and installed copies seamlessly --- web-greeter/greeter.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web-greeter/greeter.py b/web-greeter/greeter.py index 4f2f576..38db4ba 100644 --- a/web-greeter/greeter.py +++ b/web-greeter/greeter.py @@ -35,7 +35,6 @@ from typing import ( # 3rd-Party Libs from whither.app import App -from whither.base.data import AttributeDict from whither.base.config_loader import ConfigLoader from whither.bridge import BridgeObject @@ -60,7 +59,7 @@ class WebGreeter(App): greeter_config = None # type: ClassVar[BridgeObj] theme_utils = None # type: ClassVar[BridgeObj] - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__('WebGreeter', *args, **kwargs) self.greeter = Greeter(self.config.themes_dir) @@ -72,9 +71,25 @@ class WebGreeter(App): self._web_container.load_script(':/_greeter/js/bundle.js', 'Web Greeter Bundle') self.load_theme() + @classmethod + def __pre_init__(cls): + ConfigLoader.add_filter(cls.validate_greeter_config_data) + def _before_web_container_init(self): self.get_and_apply_user_config() + @classmethod + def validate_greeter_config_data(cls, key: str, data: str) -> str: + if "'@" not in data: + return data + + if 'WebGreeter' == key: + path = '../build/web-greeter/whither.yml' + else: + path = '../build/dist/web-greeter.yml' + + return open(path, 'r').read() + def get_and_apply_user_config(self): config_file = os.path.join(self.config.config_dir, 'web-greeter.yml') branding_config = ConfigLoader('branding', config_file).config