1
Fork 0

add seperate settings file

This commit is contained in:
Jake Howard 2016-09-08 21:50:22 +01:00
parent 523cd966d2
commit feb438eaa2
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 33 additions and 0 deletions

30
config/__init__.py Normal file
View file

@ -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()

1
config/config.yml Normal file
View file

@ -0,0 +1 @@
foo: bar

View file

@ -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'