##// END OF EJS Templates
merge with stable
Martin Geisler -
r12152:e59156a1 merge default
parent child Browse files
Show More
@@ -1,103 +1,103 b''
1 1 # help.py - help data for mercurial
2 2 #
3 3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import gettext, _
9 9 import sys, os
10 10 import extensions
11 11
12 12
13 13 def moduledoc(file):
14 14 '''return the top-level python documentation for the given file
15 15
16 16 Loosely inspired by pydoc.source_synopsis(), but rewritten to
17 17 handle triple quotes and to return the whole text instead of just
18 18 the synopsis'''
19 19 result = []
20 20
21 21 line = file.readline()
22 22 while line[:1] == '#' or not line.strip():
23 23 line = file.readline()
24 24 if not line:
25 25 break
26 26
27 27 start = line[:3]
28 28 if start == '"""' or start == "'''":
29 29 line = line[3:]
30 30 while line:
31 31 if line.rstrip().endswith(start):
32 32 line = line.split(start)[0]
33 33 if line:
34 34 result.append(line)
35 35 break
36 36 elif not line:
37 37 return None # unmatched delimiter
38 38 result.append(line)
39 39 line = file.readline()
40 40 else:
41 41 return None
42 42
43 43 return ''.join(result)
44 44
45 45 def listexts(header, exts, maxlength, indent=1):
46 46 '''return a text listing of the given extensions'''
47 47 if not exts:
48 48 return ''
49 49 result = '\n%s\n\n' % header
50 50 for name, desc in sorted(exts.iteritems()):
51 51 result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
52 52 ':%s:' % name, desc)
53 53 return result
54 54
55 55 def extshelp():
56 56 doc = loaddoc('extensions')()
57 57
58 58 exts, maxlength = extensions.enabled()
59 59 doc += listexts(_('enabled extensions:'), exts, maxlength)
60 60
61 61 exts, maxlength = extensions.disabled()
62 62 doc += listexts(_('disabled extensions:'), exts, maxlength)
63 63
64 64 return doc
65 65
66 66 def loaddoc(topic):
67 67 """Return a delayed loader for help/topic.txt."""
68 68
69 69 def loader():
70 70 if hasattr(sys, 'frozen'):
71 71 module = sys.executable
72 72 else:
73 73 module = __file__
74 74 base = os.path.dirname(module)
75 75
76 76 for dir in ('.', '..'):
77 77 docdir = os.path.join(base, dir, 'help')
78 78 if os.path.isdir(docdir):
79 79 break
80 80
81 81 path = os.path.join(docdir, topic + ".txt")
82 82 return gettext(open(path).read())
83 83 return loader
84 84
85 85 helptable = [
86 (["config"], _("Configuration Files"), loaddoc('config')),
86 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
87 87 (["dates"], _("Date Formats"), loaddoc('dates')),
88 88 (["patterns"], _("File Name Patterns"), loaddoc('patterns')),
89 89 (['environment', 'env'], _('Environment Variables'),
90 90 loaddoc('environment')),
91 91 (['revs', 'revisions'], _('Specifying Single Revisions'),
92 92 loaddoc('revisions')),
93 93 (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
94 94 loaddoc('multirevs')),
95 95 (['revsets'], _("Specifying Revision Sets"), loaddoc('revsets')),
96 96 (['diffs'], _('Diff Formats'), loaddoc('diffs')),
97 97 (['templating', 'templates'], _('Template Usage'),
98 98 loaddoc('templates')),
99 99 (['urls'], _('URL Paths'), loaddoc('urls')),
100 100 (["extensions"], _("Using additional features"), extshelp),
101 101 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
102 102 (["glossary"], _("Glossary"), loaddoc('glossary')),
103 103 ]
General Comments 0
You need to be logged in to leave comments. Login now