Mercurial > hg
changeset 987:bfe12654764d
hgweb: change startup argument processing
- allow passing a repo object instead of a path
(if we get a string, we construct a repo object)
- hg serve: pass options via repo.ui.setconfig
- add --style option
- get default name from repo.root rather than getcwd()
- remove template argument to hgweb()
- reduce create_server from 8 args to 1
author | mpm@selenic.com |
---|---|
date | Sun, 21 Aug 2005 15:56:14 -0700 |
parents | 2810c625ca98 |
children | a66e249d77ae |
files | mercurial/commands.py mercurial/hgweb.py |
diffstat | 2 files changed, 27 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sun Aug 21 15:00:02 2005 -0700 +++ b/mercurial/commands.py Sun Aug 21 15:56:14 2005 -0700 @@ -1117,9 +1117,13 @@ r = repo.addchangegroup(fin) respond("") - httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], - opts["address"], opts["port"], opts["ipv6"], - opts['accesslog'], opts['errorlog']) + optlist = "name templates style address port ipv6 accesslog errorlog" + for o in optlist.split(): + if opts[o]: + ui.setconfig("web", o, opts[o]) + + httpd = hgweb.create_server(repo) + if ui.verbose: addr, port = httpd.socket.getsockname() if addr == '0.0.0.0': @@ -1402,7 +1406,8 @@ ('a', 'address', '', 'interface address'), ('n', 'name', "", 'repository name'), ('', 'stdio', None, 'for remote clients'), - ('t', 'templates', "", 'template map'), + ('t', 'templates', "", 'template directory'), + ('', 'style', "", 'template style'), ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')], "hg serve [OPTION]..."), "^status":
--- a/mercurial/hgweb.py Sun Aug 21 15:00:02 2005 -0700 +++ b/mercurial/hgweb.py Sun Aug 21 15:56:14 2005 -0700 @@ -138,19 +138,21 @@ } class hgweb: + def __init__(self, repo, name=None): + if type(repo) == type(""): + self.repo = repository(ui(), repo) + else: + self.repo = repo - def __init__(self, path, name=None, templates=""): - self.templates = templates - self.reponame = name - self.path = path self.mtime = -1 - self.viewonly = 0 + self.reponame = name or self.repo.ui.config("web", "name", + self.repo.root) def refresh(self): - s = os.stat(os.path.join(self.path, ".hg", "00changelog.i")) + s = os.stat(os.path.join(self.repo.root, ".hg", "00changelog.i")) if s.st_mtime != self.mtime: self.mtime = s.st_mtime - self.repo = repository(ui(), self.path) + self.repo = repository(self.repo.ui, self.repo.root) self.maxchanges = self.repo.ui.config("web", "maxchanges", 10) self.maxfiles = self.repo.ui.config("web", "maxchanges", 10) self.allowpull = self.repo.ui.configbool("web", "allowpull", True) @@ -623,8 +625,7 @@ self.refresh() args = cgi.parse() - t = self.templates or self.repo.ui.config("web", "templates", - templatepath()) + t = self.repo.ui.config("web", "templates", templatepath()) m = os.path.join(t, "map") style = self.repo.ui.config("web", "style", "") if args.has_key('style'): @@ -640,11 +641,9 @@ if "?" in uri: uri = uri.split("?")[0] url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) - name = self.reponame or self.repo.ui.config("web", "name", os.getcwd()) - self.t = templater(m, common_filters, {"url":url, - "repo":name, + "repo":self.reponame, "header":header, "footer":footer, }) @@ -729,27 +728,18 @@ else: write(self.t("error")) -def create_server(path, name, templates, address, port, use_ipv6 = False, - accesslog = sys.stdout, errorlog = sys.stderr): +def create_server(repo): def openlog(opt, default): if opt and opt != '-': return open(opt, 'w') return default - u = ui() - repo = repository(u, path) - if not address: - address = u.config("web", "address", "") - if not port: - port = int(u.config("web", "port", 8000)) - if not use_ipv6: - use_ipv6 = u.configbool("web", "ipv6") - - accesslog = openlog(accesslog or u.config("web", "accesslog", "-"), - sys.stdout) - errorlog = openlog(errorlog or u.config("web", "errorlog", "-"), - sys.stderr) + address = repo.ui.config("web", "address", "") + port = int(repo.ui.config("web", "port", 8000)) + use_ipv6 = repo.ui.configbool("web", "ipv6") + accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) + errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) import BaseHTTPServer @@ -830,7 +820,7 @@ finally: sys.argv, sys.stdin, sys.stdout, sys.stderr = save - hg = hgweb(path, name, templates) + hg = hgweb(repo) if use_ipv6: return IPv6HTTPServer((address, port), hgwebhandler) else: