help.py
116 lines
| 4.2 KiB
| text/x-python
|
PythonLexer
/ mercurial / help.py
Matt Mackall
|
r3795 | # help.py - help data for mercurial | ||
# | ||||
# Copyright 2006 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
Matt Mackall
|
r3795 | |||
Martin Geisler
|
r9539 | from i18n import gettext, _ | ||
import sys, os | ||||
FUJIWARA Katsunori
|
r16126 | import extensions, revset, fileset, templatekw, templatefilters, filemerge | ||
Dan Villiom Podlaski Christiansen
|
r14168 | import util | ||
Cédric Duval
|
r8863 | |||
Matt Mackall
|
r14316 | def listexts(header, exts, indent=1): | ||
Cédric Duval
|
r8879 | '''return a text listing of the given extensions''' | ||
if not exts: | ||||
return '' | ||||
Matt Mackall
|
r14316 | maxlength = max(len(e) for e in exts) | ||
Cédric Duval
|
r8879 | result = '\n%s\n\n' % header | ||
for name, desc in sorted(exts.iteritems()): | ||||
Brodie Rao
|
r10364 | result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2, | ||
':%s:' % name, desc) | ||||
Cédric Duval
|
r8864 | return result | ||
Cédric Duval
|
r8879 | def extshelp(): | ||
Martin Geisler
|
r9539 | doc = loaddoc('extensions')() | ||
Matt Mackall
|
r14316 | doc += listexts(_('enabled extensions:'), extensions.enabled()) | ||
doc += listexts(_('disabled extensions:'), extensions.disabled()) | ||||
Cédric Duval
|
r8863 | return doc | ||
Martin Geisler
|
r7013 | |||
Martin Geisler
|
r9539 | def loaddoc(topic): | ||
"""Return a delayed loader for help/topic.txt.""" | ||||
Matt Mackall
|
r3798 | |||
Martin Geisler
|
r9539 | def loader(): | ||
Augie Fackler
|
r14941 | if util.mainfrozen(): | ||
Martin Geisler
|
r9539 | module = sys.executable | ||
else: | ||||
module = __file__ | ||||
base = os.path.dirname(module) | ||||
Dirkjan Ochtman
|
r7293 | |||
Martin Geisler
|
r9539 | for dir in ('.', '..'): | ||
docdir = os.path.join(base, dir, 'help') | ||||
if os.path.isdir(docdir): | ||||
break | ||||
Alexander Solovyov
|
r7677 | |||
Martin Geisler
|
r9539 | path = os.path.join(docdir, topic + ".txt") | ||
Dan Villiom Podlaski Christiansen
|
r14168 | doc = gettext(util.readfile(path)) | ||
Patrick Mezard
|
r12820 | for rewriter in helphooks.get(topic, []): | ||
doc = rewriter(topic, doc) | ||||
return doc | ||||
Martin Geisler
|
r9539 | return loader | ||
Alexander Solovyov
|
r7677 | |||
Yun Lee
|
r13888 | helptable = sorted([ | ||
Martin Geisler
|
r12145 | (["config", "hgrc"], _("Configuration Files"), loaddoc('config')), | ||
Martin Geisler
|
r9539 | (["dates"], _("Date Formats"), loaddoc('dates')), | ||
(["patterns"], _("File Name Patterns"), loaddoc('patterns')), | ||||
Matt Mackall
|
r10282 | (['environment', 'env'], _('Environment Variables'), | ||
loaddoc('environment')), | ||||
(['revs', 'revisions'], _('Specifying Single Revisions'), | ||||
loaddoc('revisions')), | ||||
(['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), | ||||
loaddoc('multirevs')), | ||||
Martin Geisler
|
r12818 | (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')), | ||
Matt Mackall
|
r14686 | (['fileset', 'filesets'], _("Specifying File Sets"), loaddoc('filesets')), | ||
Martin Geisler
|
r9539 | (['diffs'], _('Diff Formats'), loaddoc('diffs')), | ||
Erik Zielke
|
r12771 | (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')), | ||
Matt Mackall
|
r10282 | (['templating', 'templates'], _('Template Usage'), | ||
loaddoc('templates')), | ||||
Martin Geisler
|
r9539 | (['urls'], _('URL Paths'), loaddoc('urls')), | ||
Cédric Duval
|
r8879 | (["extensions"], _("Using additional features"), extshelp), | ||
Yun Lee
|
r14044 | (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')), | ||
(["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')), | ||||
(["glossary"], _("Glossary"), loaddoc('glossary')), | ||||
(["hgignore", "ignore"], _("syntax for Mercurial ignore files"), | ||||
loaddoc('hgignore')), | ||||
Matt Mackall
|
r15996 | (["phases"], _("Working with Phases"), loaddoc('phases')), | ||
Yun Lee
|
r13888 | ]) | ||
Patrick Mezard
|
r12820 | |||
# Map topics to lists of callable taking the current topic help and | ||||
# returning the updated version | ||||
Matt Mackall
|
r14318 | helphooks = {} | ||
Patrick Mezard
|
r12820 | |||
def addtopichook(topic, rewriter): | ||||
helphooks.setdefault(topic, []).append(rewriter) | ||||
Patrick Mezard
|
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() | ||||
"Yann E. MORIN"
|
r16250 | doclines = [(lines[0])] | ||
for l in lines[1:]: | ||||
# Stop once we find some Python doctest | ||||
if l.strip().startswith('>>>'): | ||||
break | ||||
doclines.append(' ' + l.strip()) | ||||
entries.append('\n'.join(doclines)) | ||||
Patrick Mezard
|
r13593 | entries = '\n\n'.join(entries) | ||
return doc.replace(marker, entries) | ||||
Matt Mackall
|
r14318 | |||
def addtopicsymbols(topic, marker, symbols): | ||||
def add(topic, doc): | ||||
return makeitemsdoc(topic, doc, marker, symbols) | ||||
addtopichook(topic, add) | ||||
Matt Mackall
|
r14686 | addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols) | ||
FUJIWARA Katsunori
|
r16126 | addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals) | ||
Matt Mackall
|
r14318 | addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols) | ||
addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords) | ||||
addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) | ||||