mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 19:51:08 -03:30
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:
@@ -33,7 +33,7 @@ def find_commands(management_dir):
|
|||||||
pass
|
pass
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
def manage():
|
def prepare_env():
|
||||||
# Update the default settings environment variable based on current mode.
|
# Update the default settings environment variable based on current mode.
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE)
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE)
|
||||||
# Add local site-packages directory to path.
|
# Add local site-packages directory to path.
|
||||||
@@ -48,6 +48,20 @@ def manage():
|
|||||||
# Monkeypatch Django find_commands to also work with .pyc files.
|
# Monkeypatch Django find_commands to also work with .pyc files.
|
||||||
import django.core.management
|
import django.core.management
|
||||||
django.core.management.find_commands = find_commands
|
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).
|
# Now run the command (or display the version).
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'):
|
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'):
|
||||||
|
|||||||
@@ -16,5 +16,8 @@ try:
|
|||||||
class dummymodule(str):
|
class dummymodule(str):
|
||||||
__file__ = property(lambda self: self)
|
__file__ = property(lambda self: self)
|
||||||
sys.modules['local_settings'] = dummymodule(local_settings_file)
|
sys.modules['local_settings'] = dummymodule(local_settings_file)
|
||||||
except IOError:
|
except IOError, e:
|
||||||
pass
|
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')
|
'/etc/awx/settings.py')
|
||||||
try:
|
try:
|
||||||
execfile(settings_file)
|
execfile(settings_file)
|
||||||
except IOError:
|
except IOError, e:
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
msg = 'No AWX configuration found at %s.' % settings_file
|
if not os.path.exists(settings_file):
|
||||||
if 'AWX_SETTINGS_FILE' not in os.environ:
|
msg = 'No AWX configuration found at %s.' % settings_file
|
||||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to specify'
|
if 'AWX_SETTINGS_FILE' not in os.environ:
|
||||||
msg += ' an alternate path.'
|
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)
|
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/
|
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
# Prepare the AWX environment.
|
||||||
import sys
|
from awx import prepare_env
|
||||||
import warnings
|
prepare_env()
|
||||||
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)
|
|
||||||
|
|
||||||
# Return the default Django WSGI application.
|
# Return the default Django WSGI application.
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|||||||
Reference in New Issue
Block a user