From 938fd72080d27c6327a3b843ae85ea6ef4cc0e29 Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 10 Oct 2018 00:13:34 +0200 Subject: [PATCH] Issue #93: Use THEN to execute (LoadComponentConfigs) --- .gitignore | 2 +- amazon_dash/config.py | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 104638a..86046be 100644 --- a/.gitignore +++ b/.gitignore @@ -91,5 +91,5 @@ ENV/ # Created by .ignore support plugin (hsz.mobi) .idea -/amazon-dash.yml /_e3/ +/*.yml diff --git a/amazon_dash/config.py b/amazon_dash/config.py index a099508..19703d2 100644 --- a/amazon_dash/config.py +++ b/amazon_dash/config.py @@ -5,6 +5,8 @@ from pwd import getpwuid from jsonschema import validate, ValidationError +from then.configs.components import LoadComponentConfigs +from then.helper import Then from yaml import load from yaml.error import YAMLError @@ -196,9 +198,11 @@ def only_root_write(path): return True -class Config(dict): +class Config: """Parse and validate yaml Amazon-dash file config. The instance behaves like a dictionary """ + then = None + def __init__(self, file, ignore_perms=False, **kwargs): """Set the config file and validate file permissions @@ -226,15 +230,17 @@ def read(self): :return: None """ - try: - data = load(open(self.file), Loader) - except (UnicodeDecodeError, YAMLError) as e: - raise InvalidConfig(self.file, '{}'.format(e)) - try: - validate(data, SCHEMA) - except ValidationError as e: - raise InvalidConfig(self.file, e) - self.update(data) + self.then = Then(LoadComponentConfigs(self.file, section='actions')) + pass + # try: + # data = load(open(self.file), Loader) + # except (UnicodeDecodeError, YAMLError) as e: + # raise InvalidConfig(self.file, '{}'.format(e)) + # try: + # validate(data, SCHEMA) + # except ValidationError as e: + # raise InvalidConfig(self.file, e) + # self.update(data) def check_config(file, printfn=print):