make sure address is a bytestring. While I'm here fix django

run_gunicorn command to use Config and set logger
This commit is contained in:
Benoit Chesneau 2010-02-17 09:42:32 +01:00
parent d92b669117
commit 51a58e58c5
4 changed files with 26 additions and 18 deletions

View File

@ -100,7 +100,7 @@ class Config(object):
def address(self): def address(self):
if not self.conf['bind']: if not self.conf['bind']:
raise RuntimeError("Listener address is not set") raise RuntimeError("Listener address is not set")
return util.parse_address(self.conf['bind']) return util.parse_address(util.to_bytestring(self.conf['bind']))
def _hook(self, hookname, *args): def _hook(self, hookname, *args):
hook = self.conf.get(hookname) hook = self.conf.get(hookname)

View File

@ -155,7 +155,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
""" """
bind_addr = util.parse_address(host, port) bind_addr = util.parse_address(util.to_bytestring(host), port)
# set others options # set others options
debug = kwargs.get('debug') debug = kwargs.get('debug')

View File

@ -16,8 +16,9 @@ from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from gunicorn.arbiter import Arbiter from gunicorn.arbiter import Arbiter
from gunicorn.main import daemonize, UMASK, set_owner_process from gunicorn.config import Config
from gunicorn.util import parse_address from gunicorn.main import daemonize, UMASK, set_owner_process, configure_logging
from gunicorn.util import parse_address, to_bytestring
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
@ -46,24 +47,21 @@ class Command(BaseCommand):
if args: if args:
raise CommandError('Usage is runserver %s' % self.args) raise CommandError('Usage is runserver %s' % self.args)
bind = addrport or '127.0.0.1'
addr = parse_address(bind) options['bind'] = addrport or '127.0.0.1'
conf = Config(options)
admin_media_path = options.get('admin_media_path', '') admin_media_path = options.get('admin_media_path', '')
workers = int(options.get('workers', '1'))
daemon = options.get('daemon')
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
pidfile = options.get('pidfile', None)
umask = options.get('umask', UMASK)
print "Validating models..." print "Validating models..."
self.validate(display_num_errors=True) self.validate(display_num_errors=True)
print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
if isinstance(addr, basestring): if isinstance(conf.address, basestring):
print "Development server is running at unix:/%s" % addr print "Development server is running at unix:/%s" % conf.address
else: else:
print "Development server is running at http://%s:%s/" % addr print "Development server is running at http://%s:%s/" % conf.address
print "Quit the server with %s." % quit_command print "Quit the server with %s." % quit_command
# django.core.management.base forces the locale to en-us. # django.core.management.base forces the locale to en-us.
@ -71,13 +69,14 @@ class Command(BaseCommand):
try: try:
handler = AdminMediaHandler(WSGIHandler(), admin_media_path) handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
arbiter = Arbiter(addr, workers, handler, arbiter = Arbiter(conf.address, conf.workers, handler,
pidfile=pidfile) pidfile=conf['pidfile'], config=conf)
if daemon: if conf['daemon']:
daemonize(umask) daemonize(conf['umask'])
else: else:
os.setpgrp() os.setpgrp()
set_owner_process(options.get("user"), options.get("group")) set_owner_process(conf["user"], conf["group"])
configure_logging(conf)
arbiter.run() arbiter.run()
except WSGIServerException, e: except WSGIServerException, e:
# Use helpful error messages instead of ugly tracebacks. # Use helpful error messages instead of ugly tracebacks.

View File

@ -163,3 +163,12 @@ def http_date(timestamp=None):
day, monthname[month], year, day, monthname[month], year,
hh, mm, ss) hh, mm, ss)
return s return s
def to_bytestring(s):
""" convert to bytestring an unicode """
if not isinstance(s, basestring):
return s
if isinstance(s, unicode):
return s.encode('utf-8')
else:
return s