comparison mercurial/commands.py @ 605:8e82fd763be2

[PATCH] Get "hg serve" to optionally log accesses and errors to files -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PATCH] Get "hg serve" to optionally log accesses and errors to files From: Bryan O'Sullivan <bos@serpentine.com> Get "hg serve" to log accesses and errors to files. manifest hash: 573ef524d84cc7d2777f5fd982f2ef47f4bcf668 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCyMA5ywK+sNU5EO8RAp1eAJoD6Qqy6XcGInzZKdo0Qp7gLttYzACfRywL fSGapmCAIaZPoBvoxXTk8Zo= =ZicU -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sun, 03 Jul 2005 20:51:05 -0800
parents 40a66d464ac2
children 94744f6fe0e7
comparison
equal deleted inserted replaced
604:40a66d464ac2 605:8e82fd763be2
792 """print the root (top) of the current working dir""" 792 """print the root (top) of the current working dir"""
793 ui.write(repo.root + "\n") 793 ui.write(repo.root + "\n")
794 794
795 def serve(ui, repo, **opts): 795 def serve(ui, repo, **opts):
796 """export the repository via HTTP""" 796 """export the repository via HTTP"""
797 def openlog(opt, default):
798 if opts[opt] and opts[opt] != '-': return open(opts[opt], 'w')
799 else: return default
797 httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], 800 httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"],
798 opts["address"], opts["port"]) 801 opts["address"], opts["port"],
802 openlog('accesslog', sys.stdout),
803 openlog('errorlog', sys.stderr))
799 if ui.verbose: 804 if ui.verbose:
800 addr, port = httpd.socket.getsockname() 805 addr, port = httpd.socket.getsockname()
801 if addr == '0.0.0.0': 806 if addr == '0.0.0.0':
802 addr = socket.gethostname() 807 addr = socket.gethostname()
803 else: 808 else:
804 try: 809 try:
805 addr = socket.gethostbyaddr(addr)[0] 810 addr = socket.gethostbyaddr(addr)[0]
806 except: pass 811 except: pass
807 if port != 80: 812 if port != 80:
808 ui.status('listening on http://%s:%d/\n' % (addr, port)) 813 ui.status('listening at http://%s:%d/\n' % (addr, port))
809 else: 814 else:
810 ui.status('listening on http://%s/\n' % addr) 815 ui.status('listening at http://%s/\n' % addr)
811 httpd.serve_forever() 816 httpd.serve_forever()
812 817
813 def status(ui, repo): 818 def status(ui, repo):
814 '''show changed files in the working directory 819 '''show changed files in the working directory
815 820
971 "^revert": (revert, 976 "^revert": (revert,
972 [("n", "nonrecursive", None, "don't recurse into subdirs"), 977 [("n", "nonrecursive", None, "don't recurse into subdirs"),
973 ("r", "rev", "", "revision")], 978 ("r", "rev", "", "revision")],
974 "hg revert [files|dirs]"), 979 "hg revert [files|dirs]"),
975 "root": (root, [], "hg root"), 980 "root": (root, [], "hg root"),
976 "^serve": (serve, [('p', 'port', 8000, 'listen port'), 981 "^serve": (serve, [('A', 'accesslog', '', 'access log file'),
977 ('a', 'address', '', 'interface address'), 982 ('E', 'errorlog', '', 'error log file'),
978 ('n', 'name', os.getcwd(), 'repository name'), 983 ('p', 'port', 8000, 'listen port'),
979 ('t', 'templates', "", 'template map')], 984 ('a', 'address', '', 'interface address'),
985 ('n', 'name', os.getcwd(), 'repository name'),
986 ('t', 'templates', "", 'template map')],
980 "hg serve [options]"), 987 "hg serve [options]"),
981 "^status": (status, [], 'hg status'), 988 "^status": (status, [], 'hg status'),
982 "tag": (tag, [('t', 'text', "", 'commit text'), 989 "tag": (tag, [('t', 'text', "", 'commit text'),
983 ('d', 'date', "", 'date code'), 990 ('d', 'date', "", 'date code'),
984 ('u', 'user', "", 'user')], 991 ('u', 'user', "", 'user')],