-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
52 lines (43 loc) · 1.55 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Setup credentials (.env) and application variables (config.yml)"""
import os
import yaml
class Config(object):
"""All configuration for this app is loaded here"""
def __init__(self, **opts):
if (os.environ.get('ENV') != 'prod'): # We are not in Heroku
self.init_environment()
"""Allow variables assigned in config.yml available the following variables
via properties"""
self.path = opts.get('path', os.path.abspath(os.path.dirname(__file__)))
with open(self.path + '/config.yml') as stream:
config = yaml.load(stream)
self._debug_mode = config['debug_mode']
self._endpoint = config['endpoint']
self._host = config['host']
self._keys = config['keys']
self._port = config['port']
@staticmethod
def init_environment():
"""Allow variables assigned in .env available using
os.environ.get('VAR_NAME')"""
base_path = os.path.abspath(os.path.dirname(__file__))
if os.path.exists(base_path + '/.env'):
for line in open(base_path + '/.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
@property
def debug_mode(self):
return self._debug_mode
@property
def endpoint(self):
return self._endpoint
@property
def host(self):
return self._host
@property
def keys(self):
return self._keys
@property
def port(self):
return self._port