mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
Fix for django-jsonfield to work on Django 1.4.1 (default with Ubuntu 12.10, fix for AC-222), update settings to provide more information when unable to load local/global settings file.
This commit is contained in:
parent
4c2af3a879
commit
92bfddb834
@ -33,7 +33,7 @@ def find_commands(management_dir):
|
||||
pass
|
||||
return commands
|
||||
|
||||
def manage():
|
||||
def prepare_env():
|
||||
# Update the default settings environment variable based on current mode.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE)
|
||||
# Add local site-packages directory to path.
|
||||
@ -48,6 +48,20 @@ def manage():
|
||||
# Monkeypatch Django find_commands to also work with .pyc files.
|
||||
import django.core.management
|
||||
django.core.management.find_commands = find_commands
|
||||
# Fixup sys.modules reference to django.utils.six to allow jsonfield to
|
||||
# work when using Django 1.4.
|
||||
import django.utils
|
||||
try:
|
||||
import django.utils.six
|
||||
except ImportError:
|
||||
import six
|
||||
sys.modules['django.utils.six'] = sys.modules['six']
|
||||
django.utils.six = sys.modules['django.utils.six']
|
||||
from django.utils import six
|
||||
|
||||
def manage():
|
||||
# Prepare the AWX environment.
|
||||
prepare_env()
|
||||
# Now run the command (or display the version).
|
||||
from django.core.management import execute_from_command_line
|
||||
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'):
|
||||
|
@ -16,5 +16,8 @@ try:
|
||||
class dummymodule(str):
|
||||
__file__ = property(lambda self: self)
|
||||
sys.modules['local_settings'] = dummymodule(local_settings_file)
|
||||
except IOError:
|
||||
pass
|
||||
except IOError, e:
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
if os.path.exists(settings_file):
|
||||
msg = 'Unable to load %s: %s' % (local_settings_file, str(e))
|
||||
raise ImproperlyConfigured(msg)
|
||||
|
@ -33,10 +33,13 @@ settings_file = os.environ.get('AWX_SETTINGS_FILE',
|
||||
'/etc/awx/settings.py')
|
||||
try:
|
||||
execfile(settings_file)
|
||||
except IOError:
|
||||
except IOError, e:
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
msg = 'No AWX configuration found at %s.' % settings_file
|
||||
if 'AWX_SETTINGS_FILE' not in os.environ:
|
||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to specify'
|
||||
msg += ' an alternate path.'
|
||||
if not os.path.exists(settings_file):
|
||||
msg = 'No AWX configuration found at %s.' % settings_file
|
||||
if 'AWX_SETTINGS_FILE' not in os.environ:
|
||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
||||
msg += 'specify an alternate path.'
|
||||
else:
|
||||
msg = 'Unable to load %s: %s' % (settings_file, str(e))
|
||||
raise ImproperlyConfigured(msg)
|
||||
|
22
awx/wsgi.py
22
awx/wsgi.py
@ -10,25 +10,9 @@ For more information on this file, see
|
||||
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from awx import MODE
|
||||
from distutils.sysconfig import get_python_lib
|
||||
|
||||
# Update the default settings environment variable based on current mode.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE)
|
||||
|
||||
# Add local site-packages directory to path.
|
||||
local_site_packages = os.path.join(os.path.dirname(__file__), 'lib',
|
||||
'site-packages')
|
||||
sys.path.insert(0, local_site_packages)
|
||||
|
||||
# Hide DeprecationWarnings when running in production. Need to first load
|
||||
# settings to apply our filter after Django's own warnings filter.
|
||||
from django.conf import settings
|
||||
if not settings.DEBUG:
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
# Prepare the AWX environment.
|
||||
from awx import prepare_env
|
||||
prepare_env()
|
||||
|
||||
# Return the default Django WSGI application.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
Loading…
Reference in New Issue
Block a user