mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
adapt django command to new config stuff.
This commit is contained in:
parent
036f8b50d9
commit
c01123eb06
@ -6,7 +6,8 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import django.core.handlers.wsgi
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
import django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
||||
|
||||
from gunicorn import util
|
||||
from gunicorn.app.base import Application
|
||||
@ -43,4 +44,28 @@ class DjangoApplication(Application):
|
||||
|
||||
def load(self):
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = self.settings_modname
|
||||
return django.core.handlers.wsgi.WSGIHandler()
|
||||
return WSGIHandler()
|
||||
|
||||
class DjangoApplicationCommand(Application):
|
||||
|
||||
def __init__(self, cfg, admin_media_path):
|
||||
self.cfg = cfg
|
||||
self.admin_media_path = admin_media_path
|
||||
self.configure_logging()
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
return AdminMediaHandler(WSGIHandler(), self.admin_media_path)
|
||||
except WSGIServerException, e:
|
||||
# Use helpful error messages instead of ugly tracebacks.
|
||||
ERRORS = {
|
||||
13: "You don't have permission to access that port.",
|
||||
98: "That port is already in use.",
|
||||
99: "That IP address can't be assigned-to.",
|
||||
}
|
||||
try:
|
||||
error_text = ERRORS[e.args[0].args[0]]
|
||||
except (AttributeError, KeyError):
|
||||
error_text = str(e)
|
||||
sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
|
||||
sys.exit(1)
|
||||
@ -12,12 +12,9 @@ import django
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.conf import settings
|
||||
from django.utils import translation
|
||||
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
|
||||
from gunicorn.arbiter import Arbiter
|
||||
|
||||
from gunicorn.config import Config
|
||||
from gunicorn.main import daemonize, configure_logging
|
||||
from gunicorn.app.djangoapp import DjangoApplicationCommand
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
@ -56,7 +53,7 @@ class Command(BaseCommand):
|
||||
options['bind'] = addrport or '127.0.0.1'
|
||||
|
||||
options['default_proc_name'] =settings.SETTINGS_MODULE
|
||||
conf = Config(options, options.get('gconfig'))
|
||||
cfg = Config(options, options.get('gconfig'))
|
||||
|
||||
admin_media_path = options.get('admin_media_path', '')
|
||||
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
|
||||
@ -65,31 +62,9 @@ class Command(BaseCommand):
|
||||
self.validate(display_num_errors=True)
|
||||
print "\nDjango version %s, using settings %r" % (django.get_version(),
|
||||
settings.SETTINGS_MODULE)
|
||||
print "Development server is running at %s" % str(conf.address)
|
||||
print "Development server is running at %s" % str(cfg.address)
|
||||
print "Quit the server with %s." % quit_command
|
||||
|
||||
# django.core.management.base forces the locale to en-us.
|
||||
translation.activate(settings.LANGUAGE_CODE)
|
||||
|
||||
try:
|
||||
handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
|
||||
arbiter = Arbiter(conf, handler)
|
||||
if conf['daemon']:
|
||||
daemonize()
|
||||
else:
|
||||
os.setpgrp()
|
||||
configure_logging(conf)
|
||||
arbiter.run()
|
||||
except WSGIServerException, e:
|
||||
# Use helpful error messages instead of ugly tracebacks.
|
||||
ERRORS = {
|
||||
13: "You don't have permission to access that port.",
|
||||
98: "That port is already in use.",
|
||||
99: "That IP address can't be assigned-to.",
|
||||
}
|
||||
try:
|
||||
error_text = ERRORS[e.args[0].args[0]]
|
||||
except (AttributeError, KeyError):
|
||||
error_text = str(e)
|
||||
sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
|
||||
sys.exit(1)
|
||||
DjangoApplicationCommand(cfg, admin_media_path).run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user