# HG changeset patch # User Matt Mackall # Date 1163446017 21600 # Node ID dc3504af7722a6c52f4d33a78093215f3021af6c # Parent 44e75d9fa654c3c8f490df3d9bb4d9432a2cd39f hgweb: internalize some socket details diff -r 44e75d9fa654 -r dc3504af7722 mercurial/commands.py --- a/mercurial/commands.py Mon Nov 13 13:26:57 2006 -0600 +++ b/mercurial/commands.py Mon Nov 13 13:26:57 2006 -0600 @@ -11,7 +11,7 @@ demandload(globals(), "os re sys signal shutil imp urllib pdb shlex") demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") demandload(globals(), "difflib patch tempfile time") -demandload(globals(), "traceback errno socket version atexit sets bz2") +demandload(globals(), "traceback errno version atexit sets bz2") demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") class UnknownCommand(Exception): @@ -2531,24 +2531,14 @@ os.read(rfd, 1) os._exit(0) - try: - httpd = hgweb.server.create_server(ui, repo) - except socket.error, inst: - raise util.Abort(_('cannot start server: %s') % inst.args[1]) + httpd = hgweb.server.create_server(ui, repo) if ui.verbose: - addr, port = httpd.socket.getsockname() - if addr == '0.0.0.0': - addr = socket.gethostname() + if httpd.port != 80: + ui.status(_('listening at http://%s:%d/\n') % + (httpd.addr, httpd.port)) else: - try: - addr = socket.gethostbyaddr(addr)[0] - except socket.error: - pass - if port != 80: - ui.status(_('listening at http://%s:%d/\n') % (addr, port)) - else: - ui.status(_('listening at http://%s/\n') % addr) + ui.status(_('listening at http://%s/\n') % httpd.addr) if opts['pid_file']: fp = open(opts['pid_file'], 'w') diff -r 44e75d9fa654 -r dc3504af7722 mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py Mon Nov 13 13:26:57 2006 -0600 +++ b/mercurial/hgweb/server.py Mon Nov 13 13:26:57 2006 -0600 @@ -200,6 +200,16 @@ self.reqmaker = wsgiapplication(self.make_handler) self.daemon_threads = True + addr, port = self.socket.getsockname() + if addr == '0.0.0.0': + addr = socket.gethostname() + else: + try: + addr = socket.gethostbyaddr(addr)[0] + except socket.error: + pass + self.addr, self.port = addr, port + def make_handler(self): if self.webdir_conf: hgwebobj = self.webdirmaker(self.webdir_conf) @@ -219,7 +229,10 @@ raise hg.RepoError(_('IPv6 not available on this system')) super(IPv6HTTPServer, self).__init__(*args, **kwargs) - if use_ipv6: - return IPv6HTTPServer((address, port), _hgwebhandler) - else: - return MercurialHTTPServer((address, port), _hgwebhandler) + try: + if use_ipv6: + return IPv6HTTPServer((address, port), _hgwebhandler) + else: + return MercurialHTTPServer((address, port), _hgwebhandler) + except socket.error, inst: + raise util.Abort(_('cannot start server: %s') % inst.args[1])