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