# HG changeset patch # User Mads Kiilerich # Date 1381372356 -7200 # Node ID e48c70451afcba7f2a27fae1c7d827638f1e372b # Parent ae65192fd6b4abef0ab0c5fa169540cc2344a71f commands: refactor 'serve', extract the http service class diff -r ae65192fd6b4 -r e48c70451afc mercurial/commands.py --- a/mercurial/commands.py Thu Oct 10 04:28:44 2013 +0200 +++ b/mercurial/commands.py Thu Oct 10 04:32:36 2013 +0200 @@ -5183,47 +5183,51 @@ o = repo app = hgweb.hgweb(o, baseui=baseui) - - class service(object): - def init(self): - util.setsignalhandler() - self.httpd = hgweb_server.create_server(ui, app) - - if opts['port'] and not ui.verbose: - return - - if self.httpd.prefix: - prefix = self.httpd.prefix.strip('/') + '/' - else: - prefix = '' - - port = ':%d' % self.httpd.port - if port == ':80': - port = '' - - bindaddr = self.httpd.addr - if bindaddr == '0.0.0.0': - bindaddr = '*' - elif ':' in bindaddr: # IPv6 - bindaddr = '[%s]' % bindaddr - - fqaddr = self.httpd.fqaddr - if ':' in fqaddr: - fqaddr = '[%s]' % fqaddr - if opts['port']: - write = ui.status - else: - write = ui.write - write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % - (fqaddr, port, prefix, bindaddr, self.httpd.port)) - - def run(self): - self.httpd.serve_forever() - - service = service() - + service = httpservice(ui, app, opts) cmdutil.service(opts, initfn=service.init, runfn=service.run) +class httpservice(object): + def __init__(self, ui, app, opts): + self.ui = ui + self.app = app + self.opts = opts + + def init(self): + util.setsignalhandler() + self.httpd = hgweb_server.create_server(self.ui, self.app) + + if self.opts['port'] and not self.ui.verbose: + return + + if self.httpd.prefix: + prefix = self.httpd.prefix.strip('/') + '/' + else: + prefix = '' + + port = ':%d' % self.httpd.port + if port == ':80': + port = '' + + bindaddr = self.httpd.addr + if bindaddr == '0.0.0.0': + bindaddr = '*' + elif ':' in bindaddr: # IPv6 + bindaddr = '[%s]' % bindaddr + + fqaddr = self.httpd.fqaddr + if ':' in fqaddr: + fqaddr = '[%s]' % fqaddr + if self.opts['port']: + write = self.ui.status + else: + write = self.ui.write + write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % + (fqaddr, port, prefix, bindaddr, self.httpd.port)) + + def run(self): + self.httpd.serve_forever() + + @command('showconfig|debugconfig', [('u', 'untrusted', None, _('show untrusted configuration options'))], _('[-u] [NAME]...'))