##// END OF EJS Templates
merge: add ancestor to the update function...
merge: add ancestor to the update function This makes it easier to do rebase-like operations.

File last commit:

r13593:cc4721ed default
r13874:9d67277c default
Show More
help.py
133 lines | 4.2 KiB | text/x-python | PythonLexer
Matt Mackall
Add basic support for help topics and a dates topic
r3795 # help.py - help data for mercurial
#
# Copyright 2006 Matt Mackall <mpm@selenic.com>
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Matt Mackall
Add basic support for help topics and a dates topic
r3795
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 from i18n import gettext, _
import sys, os
Benoit Boissinot
remove unused imports
r9678 import extensions
Cédric Duval
help: adding a new help topic about extensions...
r8863
def moduledoc(file):
Cédric Duval
help: more improvements for the extensions topic...
r8879 '''return the top-level python documentation for the given file
Matt Mackall
many, many trivial check-code fixups
r10282 Loosely inspired by pydoc.source_synopsis(), but rewritten to
handle triple quotes and to return the whole text instead of just
the synopsis'''
Cédric Duval
help: adding a new help topic about extensions...
r8863 result = []
line = file.readline()
while line[:1] == '#' or not line.strip():
line = file.readline()
Matt Mackall
many, many trivial check-code fixups
r10282 if not line:
break
Cédric Duval
help: adding a new help topic about extensions...
r8863
start = line[:3]
Matt Mackall
backout most of 4f8067c94729
r12401 if start == '"""' or start == "'''":
Cédric Duval
help: adding a new help topic about extensions...
r8863 line = line[3:]
while line:
if line.rstrip().endswith(start):
line = line.split(start)[0]
if line:
result.append(line)
break
elif not line:
return None # unmatched delimiter
result.append(line)
line = file.readline()
else:
return None
return ''.join(result)
Brodie Rao
dispatch: provide help for disabled extensions and commands...
r10364 def listexts(header, exts, maxlength, indent=1):
Cédric Duval
help: more improvements for the extensions topic...
r8879 '''return a text listing of the given extensions'''
if not exts:
return ''
result = '\n%s\n\n' % header
for name, desc in sorted(exts.iteritems()):
Brodie Rao
dispatch: provide help for disabled extensions and commands...
r10364 result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
':%s:' % name, desc)
Cédric Duval
help: refactor extensions listing, and show enabled ones in the dedicated topic
r8864 return result
Cédric Duval
help: more improvements for the extensions topic...
r8879 def extshelp():
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 doc = loaddoc('extensions')()
Cédric Duval
help: adding a new help topic about extensions...
r8863
Cédric Duval
extensions: move extensions listing functions from mercurial.help...
r8871 exts, maxlength = extensions.enabled()
Cédric Duval
help: more improvements for the extensions topic...
r8879 doc += listexts(_('enabled extensions:'), exts, maxlength)
Cédric Duval
help: refactor extensions listing, and show enabled ones in the dedicated topic
r8864
Cédric Duval
extensions: move extensions listing functions from mercurial.help...
r8871 exts, maxlength = extensions.disabled()
Cédric Duval
help: more improvements for the extensions topic...
r8879 doc += listexts(_('disabled extensions:'), exts, maxlength)
Cédric Duval
help: adding a new help topic about extensions...
r8863
return doc
Martin Geisler
i18n: mark help strings for translation...
r7013
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 def loaddoc(topic):
"""Return a delayed loader for help/topic.txt."""
Matt Mackall
move environment topic
r3798
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 def loader():
if hasattr(sys, 'frozen'):
module = sys.executable
else:
module = __file__
base = os.path.dirname(module)
Dirkjan Ochtman
help: add a topic on git diffs (issue1352)
r7293
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 for dir in ('.', '..'):
docdir = os.path.join(base, dir, 'help')
if os.path.isdir(docdir):
break
Alexander Solovyov
help: add a topic about some of the templating features
r7677
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 path = os.path.join(docdir, topic + ".txt")
Patrick Mezard
help: add topic rewriting hooks...
r12820 doc = gettext(open(path).read())
for rewriter in helphooks.get(topic, []):
doc = rewriter(topic, doc)
return doc
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 return loader
Alexander Solovyov
help: add a topic about some of the templating features
r7677
Martin Geisler
help: make helptable a list instead of a tuple...
r11657 helptable = [
Martin Geisler
help: make "hg help hgrc" an alias for "hg help config"
r12145 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 (["dates"], _("Date Formats"), loaddoc('dates')),
(["patterns"], _("File Name Patterns"), loaddoc('patterns')),
Matt Mackall
many, many trivial check-code fixups
r10282 (['environment', 'env'], _('Environment Variables'),
loaddoc('environment')),
(['revs', 'revisions'], _('Specifying Single Revisions'),
loaddoc('revisions')),
(['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
loaddoc('multirevs')),
Martin Geisler
help: add "revset" alias for "revsets" help topic
r12818 (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')),
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 (['diffs'], _('Diff Formats'), loaddoc('diffs')),
Erik Zielke
help: help topic for merge tools...
r12771 (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')),
Matt Mackall
many, many trivial check-code fixups
r10282 (['templating', 'templates'], _('Template Usage'),
loaddoc('templates')),
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 (['urls'], _('URL Paths'), loaddoc('urls')),
Cédric Duval
help: more improvements for the extensions topic...
r8879 (["extensions"], _("Using additional features"), extshelp),
Patrick Mezard
Add subrepos help topic...
r12828 (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')),
Matt Mackall
help: add some help for hgweb.config files
r10999 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
Faheem Mitha
help: add "glossary" topic...
r11356 (["glossary"], _("Glossary"), loaddoc('glossary')),
Martin Geisler
help: make helptable a list instead of a tuple...
r11657 ]
Patrick Mezard
help: add topic rewriting hooks...
r12820
# Map topics to lists of callable taking the current topic help and
# returning the updated version
helphooks = {
}
def addtopichook(topic, rewriter):
helphooks.setdefault(topic, []).append(rewriter)
Patrick Mezard
help: extract items doc generation function
r13593
def makeitemsdoc(topic, doc, marker, items):
"""Extract docstring from the items key to function mapping, build a
.single documentation block and use it to overwrite the marker in doc
"""
entries = []
for name in sorted(items):
text = (items[name].__doc__ or '').rstrip()
if not text:
continue
text = gettext(text)
lines = text.splitlines()
lines[1:] = [(' ' + l.strip()) for l in lines[1:]]
entries.append('\n'.join(lines))
entries = '\n\n'.join(entries)
return doc.replace(marker, entries)