Rename Django project to zproject.

This includes a hack to preserve humbug/backends.py as a symlink, so
that we don't need to regenerate all our old sessions.

(imported from commit b7918988b31c71ec01bbdc270db7017d4069221d)
This commit is contained in:
Tim Abbott 2013-08-06 16:51:47 -04:00
parent 44057cb31b
commit 7b9305b06f
20 changed files with 86 additions and 85 deletions

View File

@ -1,60 +0,0 @@
from zerver.models import UserProfile, get_user_profile_by_id, \
get_user_profile_by_email
from openid.consumer.consumer import SUCCESS
class EmailAuthBackend(object):
"""
Email Authentication Backend
Allows a user to sign in using an email/password pair rather than
a username/password pair.
"""
def authenticate(self, username=None, password=None):
""" Authenticate a user based on email address as the user name. """
if username is None or password is None:
# Return immediately. Otherwise we will look for a SQL row with
# NULL username. While that's probably harmless, it's needless
# exposure.
return None
try:
user_profile = get_user_profile_by_email(username)
if user_profile.check_password(password):
return user_profile
except UserProfile.DoesNotExist:
return None
def get_user(self, user_profile_id):
""" Get a UserProfile object from the user_profile_id. """
try:
return get_user_profile_by_id(user_profile_id)
except UserProfile.DoesNotExist:
return None
# Adapted from http://djangosnippets.org/snippets/2183/ by user Hangya (September 1, 2010)
class GoogleBackend(object):
def authenticate(self, openid_response):
if openid_response is None:
return None
if openid_response.status != SUCCESS:
return None
google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
try:
user_profile = get_user_profile_by_email(google_email)
except UserProfile.DoesNotExist:
# create a new user, or send a message to admins, etc.
return None
return user_profile
def get_user(self, user_profile_id):
""" Get a UserProfile object from the user_profile_id. """
try:
return get_user_profile_by_id(user_profile_id)
except UserProfile.DoesNotExist:
return None

1
humbug/backends.py Symbolic link
View File

@ -0,0 +1 @@
../zproject/backends.py

View File

@ -7,7 +7,7 @@ if __name__ == "__main__":
if "--no-traceback" not in sys.argv and len(sys.argv) > 1: if "--no-traceback" not in sys.argv and len(sys.argv) > 1:
sys.argv.append("--traceback") sys.argv.append("--traceback")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "humbug.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings")
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

View File

@ -11,7 +11,7 @@ import datetime
import os import os
import sys import sys
os.environ['DJANGO_SETTINGS_MODULE'] = "humbug.settings" os.environ['DJANGO_SETTINGS_MODULE'] = "zproject.settings"
sys.path.append('/home/humbug/humbug-deployments/current') sys.path.append('/home/humbug/humbug-deployments/current')
sys.path.append('/home/humbug/humbug-deployments/current/zerver') sys.path.append('/home/humbug/humbug-deployments/current/zerver')

View File

@ -30,7 +30,7 @@ node_modules
""".split() """.split()
exclude_files = """ exclude_files = """
humbug/test_settings.py zproject/test_settings.py
tools/jslint/jslint.js tools/jslint/jslint.js
""".split() """.split()

View File

@ -19,7 +19,7 @@ prev_deploy = options.prev_deploy
# We have to pull out JS_SPECS, defined in our settings file, so we know what # We have to pull out JS_SPECS, defined in our settings file, so we know what
# JavaScript source files to minify (and what output files to create). # JavaScript source files to minify (and what output files to create).
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'humbug.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings from django.conf import settings
os.chdir(settings.DEPLOY_ROOT) os.chdir(settings.DEPLOY_ROOT)

View File

@ -33,7 +33,7 @@ base_port = 9991
manage_args = '' manage_args = ''
if options.test: if options.test:
base_port = 9981 base_port = 9981
manage_args = '--settings=humbug.test_settings' manage_args = '--settings=zproject.test_settings'
proxy_port = base_port proxy_port = base_port
django_port = base_port+1 django_port = base_port+1

View File

@ -13,4 +13,4 @@ cd "$(dirname "$0")"/..
./zerver/tests/generate-fixtures ./zerver/tests/generate-fixtures
# "-u" uses unbuffered IO, which is important when wrapping it in # "-u" uses unbuffered IO, which is important when wrapping it in
# something like subprocess (as tools/review does) # something like subprocess (as tools/review does)
/usr/bin/env python -u ./manage.py test "$target" --settings=humbug.test_settings "$@" /usr/bin/env python -u ./manage.py test "$target" --settings=zproject.test_settings "$@"

View File

@ -11,7 +11,7 @@ import sys
# We need settings so we can figure out where the prod-static directory is. # We need settings so we can figure out where the prod-static directory is.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'humbug.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings from django.conf import settings
parser = optparse.OptionParser() parser = optparse.OptionParser()

View File

@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.contrib.auth.forms import SetPasswordForm from django.contrib.auth.forms import SetPasswordForm
from humbug import settings from zproject import settings
from zerver.models import Realm, get_user_profile_by_email, UserProfile from zerver.models import Realm, get_user_profile_by_email, UserProfile
from zerver.lib.actions import do_change_password from zerver.lib.actions import do_change_password

View File

@ -18,7 +18,7 @@ from zerver.lib.utils import statsd
# out from bots without having to import pika code all over our codebase. # out from bots without having to import pika code all over our codebase.
class SimpleQueueClient(object): class SimpleQueueClient(object):
def __init__(self): def __init__(self):
self.log = logging.getLogger('humbug.queue') self.log = logging.getLogger('zulip.queue')
self.queues = set() self.queues = set()
self.channel = None self.channel = None
self.consumers = defaultdict(set) self.consumers = defaultdict(set)

View File

@ -11,7 +11,7 @@ from zerver.exceptions import RateLimited
import logging import logging
import time import time
logger = logging.getLogger('humbug.requests') logger = logging.getLogger('zulip.requests')
def async_request_stop(request): def async_request_stop(request):
request._time_stopped = time.time() request._time_stopped = time.time()

View File

@ -41,7 +41,7 @@ def bail(msg):
try: try:
settings.TEST_SUITE settings.TEST_SUITE
except: except:
bail('Test suite only runs correctly with --settings=humbug.test_settings') bail('Test suite only runs correctly with --settings=zproject.test_settings')
# Even though we don't use pygments directly in this file, we need # Even though we don't use pygments directly in this file, we need
# this import. # this import.

View File

@ -4,7 +4,7 @@ function migration_status {
./manage.py migrate --list | sed 's/*/ /' > "$1" ./manage.py migrate --list | sed 's/*/ /' > "$1"
} }
template_grep_error_code=$(echo "SELECT 1 from pg_database WHERE datname='humbug_test_template';" | python manage.py dbshell --settings=humbug.test_settings | grep -q "1 row"; echo $?) template_grep_error_code=$(echo "SELECT 1 from pg_database WHERE datname='humbug_test_template';" | python manage.py dbshell --settings=zproject.test_settings | grep -q "1 row"; echo $?)
if [ $template_grep_error_code == "0" ]; then if [ $template_grep_error_code == "0" ]; then
migration_status zerver/fixtures/available-migrations migration_status zerver/fixtures/available-migrations
@ -26,15 +26,15 @@ mkdir -p zerver/fixtures
rm -f zerver/lib/time.pyc rm -f zerver/lib/time.pyc
echo "DROP SCHEMA humbug CASCADE; CREATE SCHEMA humbug;" | python manage.py dbshell --settings=humbug.test_settings echo "DROP SCHEMA humbug CASCADE; CREATE SCHEMA humbug;" | python manage.py dbshell --settings=zproject.test_settings
python manage.py syncdb --noinput --settings=humbug.test_settings python manage.py syncdb --noinput --settings=zproject.test_settings
python manage.py migrate --settings=humbug.test_settings --all python manage.py migrate --settings=zproject.test_settings --all
migration_status "zerver/fixtures/migration-status" migration_status "zerver/fixtures/migration-status"
# This next line can be simplified to "-n0" once we fix our app with 0 messages. # This next line can be simplified to "-n0" once we fix our app with 0 messages.
python manage.py populate_db --settings=humbug.test_settings --test-suite -n2 \ python manage.py populate_db --settings=zproject.test_settings --test-suite -n2 \
--threads=1 --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0 --threads=1 --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0
python manage.py dumpdata --settings=humbug.test_settings \ python manage.py dumpdata --settings=zproject.test_settings \
zerver.UserProfile zerver.Stream zerver.Recipient \ zerver.UserProfile zerver.Stream zerver.Recipient \
zerver.Subscription zerver.Message zerver.Huddle zerver.Realm \ zerver.Subscription zerver.Message zerver.Huddle zerver.Realm \
zerver.UserMessage zerver.Client \ zerver.UserMessage zerver.Client \

0
zproject/__init__.py Normal file
View File

60
zproject/backends.py Normal file
View File

@ -0,0 +1,60 @@
from zerver.models import UserProfile, get_user_profile_by_id, \
get_user_profile_by_email
from openid.consumer.consumer import SUCCESS
class EmailAuthBackend(object):
"""
Email Authentication Backend
Allows a user to sign in using an email/password pair rather than
a username/password pair.
"""
def authenticate(self, username=None, password=None):
""" Authenticate a user based on email address as the user name. """
if username is None or password is None:
# Return immediately. Otherwise we will look for a SQL row with
# NULL username. While that's probably harmless, it's needless
# exposure.
return None
try:
user_profile = get_user_profile_by_email(username)
if user_profile.check_password(password):
return user_profile
except UserProfile.DoesNotExist:
return None
def get_user(self, user_profile_id):
""" Get a UserProfile object from the user_profile_id. """
try:
return get_user_profile_by_id(user_profile_id)
except UserProfile.DoesNotExist:
return None
# Adapted from http://djangosnippets.org/snippets/2183/ by user Hangya (September 1, 2010)
class GoogleBackend(object):
def authenticate(self, openid_response):
if openid_response is None:
return None
if openid_response.status != SUCCESS:
return None
google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
try:
user_profile = get_user_profile_by_email(google_email)
except UserProfile.DoesNotExist:
# create a new user, or send a message to admins, etc.
return None
return user_profile
def get_user(self, user_profile_id):
""" Get a UserProfile object from the user_profile_id. """
try:
return get_user_profile_by_id(user_profile_id)
except UserProfile.DoesNotExist:
return None

View File

@ -153,8 +153,8 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
) )
AUTHENTICATION_BACKENDS = ('humbug.backends.EmailAuthBackend', AUTHENTICATION_BACKENDS = ('zproject.backends.EmailAuthBackend',
'humbug.backends.GoogleBackend', 'zproject.backends.GoogleBackend',
'guardian.backends.ObjectPermissionBackend') 'guardian.backends.ObjectPermissionBackend')
ANONYMOUS_USER_ID = None ANONYMOUS_USER_ID = None
@ -162,14 +162,14 @@ AUTH_USER_MODEL = "zerver.UserProfile"
TEST_RUNNER = 'zerver.tests.Runner' TEST_RUNNER = 'zerver.tests.Runner'
ROOT_URLCONF = 'humbug.urls' ROOT_URLCONF = 'zproject.urls'
# Python dotted path to the WSGI application used by Django's runserver. # Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'humbug.wsgi.application' WSGI_APPLICATION = 'zproject.wsgi.application'
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.auth',
'humbug.authhack', 'zproject.authhack',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.sites',
@ -532,7 +532,7 @@ LOGGING = {
'level': 'INFO', 'level': 'INFO',
'propagate': False, 'propagate': False,
}, },
'humbug.requests': { 'zulip.requests': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file'],
'level': 'INFO', 'level': 'INFO',
'propagate': False, 'propagate': False,

View File

@ -46,4 +46,4 @@ CACHES['database'] = {
} }
} }
LOGGING['loggers']['humbug.requests']['level'] = 'CRITICAL' LOGGING['loggers']['zulip.requests']['level'] = 'CRITICAL'

View File

@ -15,7 +15,7 @@ framework.
""" """
import os import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "humbug.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION