2014-11-21 19:16:39 +00:00
|
|
|
from . import settings, utils
|
2010-08-23 11:06:52 +00:00
|
|
|
|
2013-04-12 15:39:10 +00:00
|
|
|
|
2010-08-23 11:06:52 +00:00
|
|
|
class Config(object):
|
2010-11-30 23:20:23 +00:00
|
|
|
"""
|
|
|
|
|
The global config wrapper that handles the backend.
|
|
|
|
|
"""
|
2010-08-23 11:06:52 +00:00
|
|
|
def __init__(self):
|
2010-12-01 17:13:37 +00:00
|
|
|
super(Config, self).__setattr__('_backend',
|
|
|
|
|
utils.import_module_attr(settings.BACKEND)())
|
2010-08-23 11:06:52 +00:00
|
|
|
|
|
|
|
|
def __getattr__(self, key):
|
2010-08-25 12:55:01 +00:00
|
|
|
try:
|
2010-11-30 23:20:23 +00:00
|
|
|
default, help_text = settings.CONFIG[key]
|
2010-12-01 17:13:37 +00:00
|
|
|
except KeyError:
|
2010-08-25 12:55:01 +00:00
|
|
|
raise AttributeError(key)
|
2010-11-30 23:20:23 +00:00
|
|
|
result = self._backend.get(key)
|
2010-08-23 11:06:52 +00:00
|
|
|
if result is None:
|
|
|
|
|
result = default
|
|
|
|
|
setattr(self, key, default)
|
2010-08-23 13:48:15 +00:00
|
|
|
return result
|
2010-11-30 23:20:23 +00:00
|
|
|
return result
|
2010-08-23 11:06:52 +00:00
|
|
|
|
|
|
|
|
def __setattr__(self, key, value):
|
2010-11-30 23:20:23 +00:00
|
|
|
if key not in settings.CONFIG:
|
2010-08-25 12:55:01 +00:00
|
|
|
raise AttributeError(key)
|
2010-11-30 23:20:23 +00:00
|
|
|
self._backend.set(key, value)
|
2010-08-23 11:06:52 +00:00
|
|
|
|
2010-08-23 15:10:44 +00:00
|
|
|
def __dir__(self):
|
2011-08-29 13:31:44 +00:00
|
|
|
return settings.CONFIG.keys()
|