AC-752 Update settings to support enabling celeryd using rabbitmq on upgrade, also support config files in /etc/awx/conf.d/.

This commit is contained in:
Chris Church
2014-01-02 11:19:07 -05:00
parent a4098a6df7
commit fc6ec26ebe
5 changed files with 117 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ django-auth-ldap==1.1.6 (django_auth_ldap/*)
django-celery==3.1.1 (djcelery/*)
django-extensions==1.2.5 (django_extensions/*)
django-jsonfield==0.9.11 (jsonfield/*)
django-split-settings==0.1.1 (split_settings/*)
django-taggit==0.10 (taggit/*)
djangorestframework==2.3.8 (rest_framework/*)
httplib2==0.8 (httplib2/*)

View File

@@ -0,0 +1 @@
__version__ = '0.1.1'

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
import glob
import os
import sys
import types
class optional(str):
"""Wrap a file path with this class to mark it as optional.
Optional paths don't raise an IOError if file is not found.
"""
pass
def include(*args, **kwargs):
"""Used for including Django project settings from multiple files.
Note: Expects to get ``scope=locals()`` as a keyword argument.
Usage::
from split_settings.tools import optional, include
include(
'components/base.py',
'components/database.py',
optional('local_settings.py'),
scope=locals()
)
Parameters:
*args: File paths (``glob``-compatible wildcards can be used)
scope: The context for the settings, should always be ``locals()``
Raises:
IOError: if a required settings file is not found
"""
scope = kwargs.pop("scope")
including_file = scope.get('__included_file__',
scope['__file__'].rstrip('c'))
confpath = os.path.dirname(including_file)
for conffile in args:
saved_included_file = scope.get('__included_file__')
pattern = os.path.join(confpath, conffile)
# find files per pattern, raise an error if not found (unless file is
# optional)
files_to_include = glob.glob(pattern)
if not files_to_include and not isinstance(conffile, optional):
raise IOError('No such file: %s' % pattern)
for included_file in files_to_include:
scope['__included_file__'] = included_file
execfile(included_file, {}, scope)
# add dummy modules to sys.modules to make runserver autoreload
# work with settings components
modulename = ('_split_settings.%s'
% conffile[:conffile.rfind('.')].replace('/', '.'))
module = types.ModuleType(modulename)
module.__file__ = included_file
sys.modules[modulename] = module
if saved_included_file:
scope['__included_file__'] = saved_included_file
elif '__included_file__' in scope:
del scope['__included_file__']