Skip to content

Commit

Permalink
Issue #93: Use THEN to execute (LoadComponentConfigs)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Oct 9, 2018
1 parent 5b2490c commit 938fd72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ ENV/

# Created by .ignore support plugin (hsz.mobi)
.idea
/amazon-dash.yml
/_e3/
/*.yml
26 changes: 16 additions & 10 deletions amazon_dash/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 938fd72

Please sign in to comment.