mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Remove archaic monkey patches (#15338)
This commit is contained in:
@@ -61,23 +61,6 @@ else:
|
|||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
|
|
||||||
def find_commands(management_dir):
|
|
||||||
# Modified version of function from django/core/management/__init__.py.
|
|
||||||
command_dir = os.path.join(management_dir, 'commands')
|
|
||||||
commands = []
|
|
||||||
try:
|
|
||||||
for f in os.listdir(command_dir):
|
|
||||||
if f.startswith('_'):
|
|
||||||
continue
|
|
||||||
elif f.endswith('.py') and f[:-3] not in commands:
|
|
||||||
commands.append(f[:-3])
|
|
||||||
elif f.endswith('.pyc') and f[:-4] not in commands: # pragma: no cover
|
|
||||||
commands.append(f[:-4])
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
return commands
|
|
||||||
|
|
||||||
|
|
||||||
def oauth2_getattribute(self, attr):
|
def oauth2_getattribute(self, attr):
|
||||||
# Custom method to override
|
# Custom method to override
|
||||||
# oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__
|
# oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__
|
||||||
@@ -106,10 +89,6 @@ def prepare_env():
|
|||||||
|
|
||||||
if not settings.DEBUG: # pragma: no cover
|
if not settings.DEBUG: # pragma: no cover
|
||||||
warnings.simplefilter('ignore', DeprecationWarning)
|
warnings.simplefilter('ignore', DeprecationWarning)
|
||||||
# Monkeypatch Django find_commands to also work with .pyc files.
|
|
||||||
import django.core.management
|
|
||||||
|
|
||||||
django.core.management.find_commands = find_commands
|
|
||||||
|
|
||||||
# Monkeypatch Oauth2 toolkit settings class to check for settings
|
# Monkeypatch Oauth2 toolkit settings class to check for settings
|
||||||
# in django.conf settings each time, not just once during import
|
# in django.conf settings each time, not just once during import
|
||||||
@@ -117,35 +96,6 @@ def prepare_env():
|
|||||||
|
|
||||||
oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__ = oauth2_getattribute
|
oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__ = oauth2_getattribute
|
||||||
|
|
||||||
# Use the AWX_TEST_DATABASE_* environment variables to specify the test
|
|
||||||
# database settings to use when management command is run as an external
|
|
||||||
# program via unit tests.
|
|
||||||
for opt in ('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'): # pragma: no cover
|
|
||||||
if os.environ.get('AWX_TEST_DATABASE_%s' % opt, None):
|
|
||||||
settings.DATABASES['default'][opt] = os.environ['AWX_TEST_DATABASE_%s' % opt]
|
|
||||||
# Disable capturing all SQL queries in memory when in DEBUG mode.
|
|
||||||
if settings.DEBUG and not getattr(settings, 'SQL_DEBUG', True):
|
|
||||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
|
||||||
from django.db.backends.utils import CursorWrapper
|
|
||||||
|
|
||||||
BaseDatabaseWrapper.make_debug_cursor = lambda self, cursor: CursorWrapper(cursor, self)
|
|
||||||
|
|
||||||
# Use the default devserver addr/port defined in settings for runserver.
|
|
||||||
default_addr = getattr(settings, 'DEVSERVER_DEFAULT_ADDR', '127.0.0.1')
|
|
||||||
default_port = getattr(settings, 'DEVSERVER_DEFAULT_PORT', 8000)
|
|
||||||
from django.core.management.commands import runserver as core_runserver
|
|
||||||
|
|
||||||
original_handle = core_runserver.Command.handle
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
if not options.get('addrport'):
|
|
||||||
options['addrport'] = '%s:%d' % (default_addr, int(default_port))
|
|
||||||
elif options.get('addrport').isdigit():
|
|
||||||
options['addrport'] = '%s:%d' % (default_addr, int(options['addrport']))
|
|
||||||
return original_handle(self, *args, **options)
|
|
||||||
|
|
||||||
core_runserver.Command.handle = handle
|
|
||||||
|
|
||||||
|
|
||||||
def manage():
|
def manage():
|
||||||
# Prepare the AWX environment.
|
# Prepare the AWX environment.
|
||||||
|
|||||||
Reference in New Issue
Block a user