don't set default values for command line options so we can use paster

one and later our own conf. While I'm here display the address on which
we start to listen so we can get the port when using port=0.
This commit is contained in:
Benoit Chesneau 2010-01-27 16:08:08 +01:00
parent 23af620000
commit 57054f1a4c
3 changed files with 18 additions and 3 deletions

View File

@ -63,12 +63,16 @@ def get_app(parser, opts, args):
else:
workers = int(ctx.local_conf.get('workers', 1))
opts.host = opts.host or ctx.local_conf.get('host', '127.0.0.1')
opts.port = opts.port or int(ctx.local_conf.get('port', 8000))
debug = ctx.global_conf.get('debug') == "true"
if debug:
# we force to one worker in debug mode.
workers = 1
opts.workers=workers
app = loadapp(config_url, relative_to=relative_to)
return app

View File

@ -92,6 +92,8 @@ class Arbiter(object):
if i < 5:
self.log.error("Retrying in 1 second.")
time.sleep(1)
if self.LISTENER:
self.log.info("Listen on %s:%s" % self.LISTENER.getsockname())
def init_socket_fromfd(self, fd, address):
sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)

View File

@ -19,9 +19,9 @@ LOG_LEVELS = {
def options():
return [
op.make_option('--host', dest='host', default='127.0.0.1',
op.make_option('--host', dest='host',
help='Host to listen on. [%default]'),
op.make_option('--port', dest='port', default=8000, type='int',
op.make_option('--port', dest='port', type='int',
help='Port to listen on. [%default]'),
op.make_option('--workers', dest='workers', type='int',
help='Number of workers to spawn. [%default]'),
@ -57,8 +57,17 @@ def main(usage, get_app):
workers = opts.workers or 1
if opts.debug:
workers = 1
host = opts.host or '127.0.0.1'
port = opts.port
if port is None:
if ':' in host:
host, port = host.split(':', 1)
port = int(port)
else:
port = 8000
arbiter = Arbiter((opts.host, opts.port), workers, app,
arbiter = Arbiter((host,port), workers, app,
opts.debug)
arbiter.run()