Mercurial > hg-stable
changeset 603:bc5d058e65e9
[PATCH] Get "hg serve" to print the URL being served
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[PATCH] Get "hg serve" to print the URL being served
From: Bryan O'Sullivan <bos@serpentine.com>
If invoked with verbosity, print the URL at which we are serving.
Useful if you bind to any port with "-p 0", and need to know what port
the server is listening on.
manifest hash: d317225606fbd2ec5819e1f266575b0485dfba79
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCyL9hywK+sNU5EO8RAjFQAJoDBRl5VoGIklxA1PdFGCt8Jb3iMQCeILeD
XAwnnSCy/IQ/MDfYf6z7oWI=
=FNVC
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 03 Jul 2005 20:47:29 -0800 |
parents | 56d81b303656 |
children | 40a66d464ac2 |
files | mercurial/commands.py mercurial/hgweb.py |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sun Jul 03 20:33:35 2005 -0800 +++ b/mercurial/commands.py Sun Jul 03 20:47:29 2005 -0800 @@ -8,7 +8,7 @@ import os, re, sys, signal import fancyopts, ui, hg, util from demandload import * -demandload(globals(), "mdiff time hgweb traceback random signal errno version") +demandload(globals(), "mdiff time hgweb traceback random signal socket errno version") class UnknownCommand(Exception): pass @@ -793,8 +793,21 @@ def serve(ui, repo, **opts): """export the repository via HTTP""" - hgweb.server(repo.root, opts["name"], opts["templates"], - opts["address"], opts["port"]) + httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], + opts["address"], opts["port"]) + if ui.verbose: + addr, port = httpd.socket.getsockname() + if addr == '0.0.0.0': + addr = socket.gethostname() + else: + try: + addr = socket.gethostbyaddr(addr)[0] + except: pass + if port != 80: + ui.status('listening on http://%s:%d/\n' % (addr, port)) + else: + ui.status('listening on http://%s/\n' % addr) + httpd.serve_forever() def status(ui, repo): '''show changed files in the working directory
--- a/mercurial/hgweb.py Sun Jul 03 20:33:35 2005 -0800 +++ b/mercurial/hgweb.py Sun Jul 03 20:47:29 2005 -0800 @@ -694,7 +694,7 @@ else: write(self.t("error")) -def server(path, name, templates, address, port): +def create_server(path, name, templates, address, port): import BaseHTTPServer import sys, os @@ -759,5 +759,8 @@ sys.argv, sys.stdin, sys.stdout, sys.stderr = save hg = hgweb(path, name, templates) - httpd = BaseHTTPServer.HTTPServer((address, port), hgwebhandler) + return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) + +def server(path, name, templates, address, port): + httpd = create_server(path, name, templates, address, port) httpd.serve_forever()