help.py
92 lines
| 2.8 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 | ||
# GNU General Public License version 2, incorporated herein by reference. | ||||
Matt Mackall
|
r3795 | |||
Martin Geisler
|
r9539 | from i18n import gettext, _ | ||
import sys, os | ||||
Martin Geisler
|
r8938 | import extensions, util | ||
Cédric Duval
|
r8863 | |||
def moduledoc(file): | ||||
Cédric Duval
|
r8879 | '''return the top-level python documentation for the given file | ||
Loosely inspired by pydoc.source_synopsis(), but rewritten to handle \''' | ||||
as well as """ and to return the whole text instead of just the synopsis''' | ||||
Cédric Duval
|
r8863 | result = [] | ||
line = file.readline() | ||||
while line[:1] == '#' or not line.strip(): | ||||
line = file.readline() | ||||
if not line: break | ||||
start = line[:3] | ||||
if start == '"""' or start == "'''": | ||||
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) | ||||
Cédric Duval
|
r8879 | def listexts(header, exts, maxlength): | ||
'''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()): | ||||
Martin Geisler
|
r9295 | result += ' %-*s %s\n' % (maxlength + 2, ':%s:' % name, desc) | ||
Cédric Duval
|
r8864 | return result | ||
Cédric Duval
|
r8879 | def extshelp(): | ||
Martin Geisler
|
r9539 | doc = loaddoc('extensions')() | ||
Cédric Duval
|
r8863 | |||
Cédric Duval
|
r8871 | exts, maxlength = extensions.enabled() | ||
Cédric Duval
|
r8879 | doc += listexts(_('enabled extensions:'), exts, maxlength) | ||
Cédric Duval
|
r8864 | |||
Cédric Duval
|
r8871 | exts, maxlength = extensions.disabled() | ||
Cédric Duval
|
r8879 | doc += listexts(_('disabled extensions:'), exts, maxlength) | ||
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(): | ||
if hasattr(sys, 'frozen'): | ||||
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") | ||
return gettext(open(path).read()) | ||||
return loader | ||||
Alexander Solovyov
|
r7677 | |||
Martin Geisler
|
r9539 | helptable = ( | ||
(["dates"], _("Date Formats"), loaddoc('dates')), | ||||
(["patterns"], _("File Name Patterns"), loaddoc('patterns')), | ||||
(['environment', 'env'], _('Environment Variables'), loaddoc('environment')), | ||||
(['revs', 'revisions'], _('Specifying Single Revisions'), loaddoc('revisions')), | ||||
(['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), loaddoc('multirevs')), | ||||
(['diffs'], _('Diff Formats'), loaddoc('diffs')), | ||||
(['templating', 'templates'], _('Template Usage'), loaddoc('templates')), | ||||
(['urls'], _('URL Paths'), loaddoc('urls')), | ||||
Cédric Duval
|
r8879 | (["extensions"], _("Using additional features"), extshelp), | ||
Johannes Stezenbach
|
r6654 | ) | ||