-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_parser.py
More file actions
27 lines (21 loc) · 921 Bytes
/
settings_parser.py
File metadata and controls
27 lines (21 loc) · 921 Bytes
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
# settings_parser.py
"""
A generic way to parse a module with globals and return
an object with those globals as attributes.
"""
#from ...settings import settings
class SettingsParser(object):
"""Parse a module and turn globals into attributes"""
def __init__(self, settings_module=None):
"""
Turn globals from a module into object attributes
settings_module: tuple, (relative module path, module name)
path should be relative to this file
"""
# check if settings_module was defined, define default
if not settings_module:
settings_module = ('...settings', 'settings')
exec 'from ' + settings_module[0] + ' import ' + settings_module[1] + ' as settings'
for key,value in settings.__dict__.iteritems():
if not key.startswith('__'):
self.__dict__[key] = value