Mercurial > hg-stable
changeset 27138:ea8e27e6098d
hgweb: move httpservice object from commands module
This avoids the deep import of hgweb.server at the commands module.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 31 Oct 2015 21:57:45 +0900 |
parents | 25e4b2f000c5 |
children | d73f23344dc7 |
files | mercurial/commands.py mercurial/hgweb/__init__.py |
diffstat | 2 files changed, 49 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Wed Nov 25 14:25:33 2015 -0800 +++ b/mercurial/commands.py Sat Oct 31 21:57:45 2015 +0900 @@ -15,7 +15,6 @@ import archival, changegroup, cmdutil, hbisect import sshserver, hgweb import extensions -from hgweb import server as hgweb_server import merge as mergemod import minirst, revset, fileset import dagparser, context, simplemerge, graphmod, copies @@ -6001,52 +6000,9 @@ o = repo app = hgweb.hgweb(o, baseui=baseui) - service = httpservice(ui, app, opts) + service = hgweb.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)) - self.ui.flush() # avoid buffering of status message - - def run(self): - self.httpd.serve_forever() - - @command('^status|st', [('A', 'all', None, _('show status of all files')), ('m', 'modified', None, _('show only modified files')),
--- a/mercurial/hgweb/__init__.py Wed Nov 25 14:25:33 2015 -0800 +++ b/mercurial/hgweb/__init__.py Sat Oct 31 21:57:45 2015 +0900 @@ -10,9 +10,16 @@ import os +from ..i18n import _ + +from .. import ( + util, +) + from . import ( hgweb_mod, hgwebdir_mod, + server, ) def hgweb(config, name=None, baseui=None): @@ -35,3 +42,44 @@ def hgwebdir(config, baseui=None): return hgwebdir_mod.hgwebdir(config, baseui=baseui) +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 = 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)) + self.ui.flush() # avoid buffering of status message + + def run(self): + self.httpd.serve_forever()