From feb438eaa258119a657de7e4db8b1308a353e571 Mon Sep 17 00:00:00 2001 From: TheOrangeOne Date: Thu, 8 Sep 2016 21:50:22 +0100 Subject: [PATCH] add seperate settings file --- config/__init__.py | 30 ++++++++++++++++++++++++++++++ config/config.yml | 1 + config/pelicanconf.py | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 config/__init__.py create mode 100644 config/config.yml diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..dc1cd9b --- /dev/null +++ b/config/__init__.py @@ -0,0 +1,30 @@ +import yaml +import os.path + + +class DotDictionary(dict): + def __getattr__(self, attr): + value = self[attr] + if type(value) == dict: + value = DotDictionary(value) + return value + __setattr__ = dict.__setitem__ + __delattr__ = dict.__delitem__ + + +class WrappedSettings: + def __init__(self): + self.settings_dir = os.path.join(os.path.dirname(__file__), 'config.yml') + settings = open(self.settings_dir) + self.settings = yaml.load(settings) + + def __getattr__(self, name): + value = getattr(self.settings, name) + if type(value) == dict: + value = DotDictionary(value) + return value + + def __str__(self): + return str(self.settings) + +settings = WrappedSettings() diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 0000000..20e9ff3 --- /dev/null +++ b/config/config.yml @@ -0,0 +1 @@ +foo: bar diff --git a/config/pelicanconf.py b/config/pelicanconf.py index 96c046e..471a128 100644 --- a/config/pelicanconf.py +++ b/config/pelicanconf.py @@ -4,6 +4,8 @@ from git import Repo import sys, os sys.path.insert(0, os.path.realpath('./')) +from config import settings + # Global core settings AUTHOR = 'Jake Howard' SITENAME = 'TheOrangeOne'