Fix CI system to work on both Python 2 and 3 (#225)

* Use old style middleware settings for Python 2.

* Make entrypoint python2 and 3 compatible.

* Fix python command to test for mysql server.

* Bettery docker-entrypoint to work with Python 2 & 3

* Add missing braces.
This commit is contained in:
Abhilash Raj
2018-03-09 23:13:57 -08:00
committed by GitHub
parent 14d8e8071c
commit d26c402617
2 changed files with 19 additions and 3 deletions

View File

@@ -16,7 +16,15 @@ function wait_for_postgres () {
function wait_for_mysql () {
# Check if MySQL is up and accepting connections.
HOSTNAME=$(python -c "from urllib.parse import urlparse; o = urlparse('$DATABASE_URL'); print(o.hostname);")
HOSTNAME=$(python <<EOF
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
o = urlparse('$DATABASE_URL')
print(o.hostname)
EOF
)
until mysqladmin ping --host "$HOSTNAME" --silent; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 1

View File

@@ -29,6 +29,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
import os
import socket
import dj_database_url
import sys
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -99,8 +100,7 @@ INSTALLED_APPS = (
'allauth.socialaccount.providers.google',
)
MIDDLEWARE = (
_MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@@ -114,6 +114,14 @@ MIDDLEWARE = (
'postorius.middleware.PostoriusMiddleware',
)
# Use old-style Middleware class in Python 2 and released versions of
# Django-mailman3 don't support new style middlewares.
if sys.version_info < (3, 0):
MIDDLEWARE_CLASSES = _MIDDLEWARE
else:
MIDDLEWARE = _MIDDLEWARE
ROOT_URLCONF = 'urls'