Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/webcommands.py @ 12666:ead4e21f49f1
web: add a help view for getting hg help output
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 09 Oct 2010 12:27:14 -0500 |
parents | 516b000fbb7e |
children | 0ac7c5c8121a |
comparison
equal
deleted
inserted
replaced
12665:cf24b6b5517c | 12666:ead4e21f49f1 |
---|---|
11 from mercurial.node import short, hex | 11 from mercurial.node import short, hex |
12 from mercurial.util import binary | 12 from mercurial.util import binary |
13 from common import paritygen, staticfile, get_contact, ErrorResponse | 13 from common import paritygen, staticfile, get_contact, ErrorResponse |
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND | 14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
15 from mercurial import graphmod | 15 from mercurial import graphmod |
16 from mercurial import help as helpmod | |
17 from mercurial import ui | |
18 from mercurial.i18n import _ | |
16 | 19 |
17 # __all__ is populated with the allowed commands. Be sure to add to it if | 20 # __all__ is populated with the allowed commands. Be sure to add to it if |
18 # you're adding a new command, or the new command won't work. | 21 # you're adding a new command, or the new command won't work. |
19 | 22 |
20 __all__ = [ | 23 __all__ = [ |
21 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', | 24 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
22 'manifest', 'tags', 'branches', 'summary', 'filediff', 'diff', 'annotate', | 25 'manifest', 'tags', 'branches', 'summary', 'filediff', 'diff', 'annotate', |
23 'filelog', 'archive', 'static', 'graph', | 26 'filelog', 'archive', 'static', 'graph', 'help', |
24 ] | 27 ] |
25 | 28 |
26 def log(web, req, tmpl): | 29 def log(web, req, tmpl): |
27 if 'file' in req.form and req.form['file'][0]: | 30 if 'file' in req.form and req.form['file'][0]: |
28 return filelog(web, req, tmpl) | 31 return filelog(web, req, tmpl) |
722 | 725 |
723 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, | 726 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
724 lessvars=lessvars, morevars=morevars, downrev=downrev, | 727 lessvars=lessvars, morevars=morevars, downrev=downrev, |
725 canvasheight=canvasheight, jsdata=data, bg_height=bg_height, | 728 canvasheight=canvasheight, jsdata=data, bg_height=bg_height, |
726 node=revnode_hex, changenav=changenav) | 729 node=revnode_hex, changenav=changenav) |
730 | |
731 def _getdoc(e): | |
732 doc = e[0].__doc__ | |
733 if doc: | |
734 doc = doc.split('\n')[0] | |
735 else: | |
736 doc = _('(no help text available)') | |
737 return doc | |
738 | |
739 def help(web, req, tmpl): | |
740 from mercurial import commands # avoid cycle | |
741 | |
742 topicname = req.form.get('node', [None])[0] | |
743 if not topicname: | |
744 topic = [] | |
745 | |
746 def topics(**map): | |
747 for entries, summary, _ in helpmod.helptable: | |
748 entries = sorted(entries, key=len) | |
749 yield {'topic': entries[-1], 'summary': summary} | |
750 | |
751 early, other = [], [] | |
752 primary = lambda s: s.split('|')[0] | |
753 for c, e in commands.table.iteritems(): | |
754 doc = _getdoc(e) | |
755 if 'DEPRECATED' in doc or c.startswith('debug'): | |
756 continue | |
757 cmd = primary(c) | |
758 if cmd.startswith('^'): | |
759 early.append((cmd[1:], doc)) | |
760 else: | |
761 other.append((cmd, doc)) | |
762 | |
763 early.sort() | |
764 other.sort() | |
765 | |
766 def earlycommands(**map): | |
767 for c, doc in early: | |
768 yield {'topic': c, 'summary': doc} | |
769 | |
770 def othercommands(**map): | |
771 for c, doc in other: | |
772 yield {'topic': c, 'summary': doc} | |
773 | |
774 return tmpl('helptopics', topics=topics, earlycommands=earlycommands, | |
775 othercommands=othercommands, title='Index') | |
776 | |
777 u = ui.ui() | |
778 u.pushbuffer() | |
779 try: | |
780 commands.help_(u, topicname) | |
781 except error.UnknownCommand: | |
782 raise ErrorResponse(HTTP_NOT_FOUND) | |
783 doc = u.popbuffer() | |
784 return tmpl('help', topic=topicname, doc=doc) |