2006-12-06 01:06:13 +03:00
|
|
|
# help.py - help data for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2006 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-12-06 01:06:13 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
from i18n import gettext, _
|
|
|
|
import sys, os
|
2009-10-31 18:56:58 +03:00
|
|
|
import extensions
|
2009-06-20 22:55:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
def moduledoc(file):
|
2009-06-21 19:52:30 +04:00
|
|
|
'''return the top-level python documentation for the given file
|
|
|
|
|
2010-01-25 09:05:27 +03:00
|
|
|
Loosely inspired by pydoc.source_synopsis(), but rewritten to
|
|
|
|
handle triple quotes and to return the whole text instead of just
|
|
|
|
the synopsis'''
|
2009-06-20 22:55:43 +04:00
|
|
|
result = []
|
|
|
|
|
|
|
|
line = file.readline()
|
|
|
|
while line[:1] == '#' or not line.strip():
|
|
|
|
line = file.readline()
|
2010-01-25 09:05:27 +03:00
|
|
|
if not line:
|
|
|
|
break
|
2009-06-20 22:55:43 +04:00
|
|
|
|
|
|
|
start = line[:3]
|
2010-09-24 21:46:54 +04:00
|
|
|
if start == '"""' or start == "'''":
|
2009-06-20 22:55:43 +04:00
|
|
|
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)
|
|
|
|
|
2010-02-07 16:01:43 +03:00
|
|
|
def listexts(header, exts, maxlength, indent=1):
|
2009-06-21 19:52:30 +04:00
|
|
|
'''return a text listing of the given extensions'''
|
|
|
|
if not exts:
|
|
|
|
return ''
|
2009-08-03 02:01:50 +04:00
|
|
|
result = '\n%s\n\n' % header
|
2009-06-21 19:52:30 +04:00
|
|
|
for name, desc in sorted(exts.iteritems()):
|
2010-02-07 16:01:43 +03:00
|
|
|
result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
|
|
|
|
':%s:' % name, desc)
|
2009-06-20 22:55:49 +04:00
|
|
|
return result
|
|
|
|
|
2009-06-21 19:52:30 +04:00
|
|
|
def extshelp():
|
2009-10-04 11:59:13 +04:00
|
|
|
doc = loaddoc('extensions')()
|
2009-06-20 22:55:43 +04:00
|
|
|
|
2009-06-21 18:32:00 +04:00
|
|
|
exts, maxlength = extensions.enabled()
|
2009-06-21 19:52:30 +04:00
|
|
|
doc += listexts(_('enabled extensions:'), exts, maxlength)
|
2009-06-20 22:55:49 +04:00
|
|
|
|
2009-06-21 18:32:00 +04:00
|
|
|
exts, maxlength = extensions.disabled()
|
2009-06-21 19:52:30 +04:00
|
|
|
doc += listexts(_('disabled extensions:'), exts, maxlength)
|
2009-06-20 22:55:43 +04:00
|
|
|
|
|
|
|
return doc
|
2008-09-09 23:32:39 +04:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
def loaddoc(topic):
|
|
|
|
"""Return a delayed loader for help/topic.txt."""
|
2007-12-05 14:40:01 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
def loader():
|
|
|
|
if hasattr(sys, 'frozen'):
|
|
|
|
module = sys.executable
|
|
|
|
else:
|
|
|
|
module = __file__
|
|
|
|
base = os.path.dirname(module)
|
2006-12-06 01:31:08 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
for dir in ('.', '..'):
|
|
|
|
docdir = os.path.join(base, dir, 'help')
|
|
|
|
if os.path.isdir(docdir):
|
|
|
|
break
|
2009-01-22 21:02:50 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
path = os.path.join(docdir, topic + ".txt")
|
2010-10-23 21:21:49 +04:00
|
|
|
doc = gettext(open(path).read())
|
|
|
|
for rewriter in helphooks.get(topic, []):
|
|
|
|
doc = rewriter(topic, doc)
|
|
|
|
return doc
|
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
return loader
|
2009-01-22 21:02:50 +03:00
|
|
|
|
2010-07-22 23:43:45 +04:00
|
|
|
helptable = [
|
2010-09-02 14:53:28 +04:00
|
|
|
(["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(["dates"], _("Date Formats"), loaddoc('dates')),
|
|
|
|
(["patterns"], _("File Name Patterns"), loaddoc('patterns')),
|
2010-01-25 09:05:27 +03:00
|
|
|
(['environment', 'env'], _('Environment Variables'),
|
|
|
|
loaddoc('environment')),
|
|
|
|
(['revs', 'revisions'], _('Specifying Single Revisions'),
|
|
|
|
loaddoc('revisions')),
|
|
|
|
(['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
|
|
|
|
loaddoc('multirevs')),
|
2010-10-23 19:45:49 +04:00
|
|
|
(['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['diffs'], _('Diff Formats'), loaddoc('diffs')),
|
2010-10-20 18:54:34 +04:00
|
|
|
(['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')),
|
2010-01-25 09:05:27 +03:00
|
|
|
(['templating', 'templates'], _('Template Usage'),
|
|
|
|
loaddoc('templates')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['urls'], _('URL Paths'), loaddoc('urls')),
|
2009-06-21 19:52:30 +04:00
|
|
|
(["extensions"], _("Using additional features"), extshelp),
|
2010-10-24 21:28:44 +04:00
|
|
|
(["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')),
|
2010-04-26 20:03:40 +04:00
|
|
|
(["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
|
2010-06-16 13:50:22 +04:00
|
|
|
(["glossary"], _("Glossary"), loaddoc('glossary')),
|
2010-07-22 23:43:45 +04:00
|
|
|
]
|
2010-10-23 21:21:49 +04:00
|
|
|
|
|
|
|
# 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)
|