Show More
@@ -1,111 +1,116 b'' | |||||
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, revset, fileset, templatekw, templatefilters, filemerge |
|
10 | import extensions, revset, fileset, templatekw, templatefilters, filemerge | |
11 | import util |
|
11 | import util | |
12 |
|
12 | |||
13 | def listexts(header, exts, indent=1): |
|
13 | def listexts(header, exts, indent=1): | |
14 | '''return a text listing of the given extensions''' |
|
14 | '''return a text listing of the given extensions''' | |
15 | if not exts: |
|
15 | if not exts: | |
16 | return '' |
|
16 | return '' | |
17 | maxlength = max(len(e) for e in exts) |
|
17 | maxlength = max(len(e) for e in exts) | |
18 | result = '\n%s\n\n' % header |
|
18 | result = '\n%s\n\n' % header | |
19 | for name, desc in sorted(exts.iteritems()): |
|
19 | for name, desc in sorted(exts.iteritems()): | |
20 | result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2, |
|
20 | result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2, | |
21 | ':%s:' % name, desc) |
|
21 | ':%s:' % name, desc) | |
22 | return result |
|
22 | return result | |
23 |
|
23 | |||
24 | def extshelp(): |
|
24 | def extshelp(): | |
25 | doc = loaddoc('extensions')() |
|
25 | doc = loaddoc('extensions')() | |
26 | doc += listexts(_('enabled extensions:'), extensions.enabled()) |
|
26 | doc += listexts(_('enabled extensions:'), extensions.enabled()) | |
27 | doc += listexts(_('disabled extensions:'), extensions.disabled()) |
|
27 | doc += listexts(_('disabled extensions:'), extensions.disabled()) | |
28 | return doc |
|
28 | return doc | |
29 |
|
29 | |||
30 | def loaddoc(topic): |
|
30 | def loaddoc(topic): | |
31 | """Return a delayed loader for help/topic.txt.""" |
|
31 | """Return a delayed loader for help/topic.txt.""" | |
32 |
|
32 | |||
33 | def loader(): |
|
33 | def loader(): | |
34 | if util.mainfrozen(): |
|
34 | if util.mainfrozen(): | |
35 | module = sys.executable |
|
35 | module = sys.executable | |
36 | else: |
|
36 | else: | |
37 | module = __file__ |
|
37 | module = __file__ | |
38 | base = os.path.dirname(module) |
|
38 | base = os.path.dirname(module) | |
39 |
|
39 | |||
40 | for dir in ('.', '..'): |
|
40 | for dir in ('.', '..'): | |
41 | docdir = os.path.join(base, dir, 'help') |
|
41 | docdir = os.path.join(base, dir, 'help') | |
42 | if os.path.isdir(docdir): |
|
42 | if os.path.isdir(docdir): | |
43 | break |
|
43 | break | |
44 |
|
44 | |||
45 | path = os.path.join(docdir, topic + ".txt") |
|
45 | path = os.path.join(docdir, topic + ".txt") | |
46 | doc = gettext(util.readfile(path)) |
|
46 | doc = gettext(util.readfile(path)) | |
47 | for rewriter in helphooks.get(topic, []): |
|
47 | for rewriter in helphooks.get(topic, []): | |
48 | doc = rewriter(topic, doc) |
|
48 | doc = rewriter(topic, doc) | |
49 | return doc |
|
49 | return doc | |
50 |
|
50 | |||
51 | return loader |
|
51 | return loader | |
52 |
|
52 | |||
53 | helptable = sorted([ |
|
53 | helptable = sorted([ | |
54 | (["config", "hgrc"], _("Configuration Files"), loaddoc('config')), |
|
54 | (["config", "hgrc"], _("Configuration Files"), loaddoc('config')), | |
55 | (["dates"], _("Date Formats"), loaddoc('dates')), |
|
55 | (["dates"], _("Date Formats"), loaddoc('dates')), | |
56 | (["patterns"], _("File Name Patterns"), loaddoc('patterns')), |
|
56 | (["patterns"], _("File Name Patterns"), loaddoc('patterns')), | |
57 | (['environment', 'env'], _('Environment Variables'), |
|
57 | (['environment', 'env'], _('Environment Variables'), | |
58 | loaddoc('environment')), |
|
58 | loaddoc('environment')), | |
59 | (['revs', 'revisions'], _('Specifying Single Revisions'), |
|
59 | (['revs', 'revisions'], _('Specifying Single Revisions'), | |
60 | loaddoc('revisions')), |
|
60 | loaddoc('revisions')), | |
61 | (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), |
|
61 | (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), | |
62 | loaddoc('multirevs')), |
|
62 | loaddoc('multirevs')), | |
63 | (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')), |
|
63 | (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')), | |
64 | (['fileset', 'filesets'], _("Specifying File Sets"), loaddoc('filesets')), |
|
64 | (['fileset', 'filesets'], _("Specifying File Sets"), loaddoc('filesets')), | |
65 | (['diffs'], _('Diff Formats'), loaddoc('diffs')), |
|
65 | (['diffs'], _('Diff Formats'), loaddoc('diffs')), | |
66 | (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')), |
|
66 | (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')), | |
67 | (['templating', 'templates'], _('Template Usage'), |
|
67 | (['templating', 'templates'], _('Template Usage'), | |
68 | loaddoc('templates')), |
|
68 | loaddoc('templates')), | |
69 | (['urls'], _('URL Paths'), loaddoc('urls')), |
|
69 | (['urls'], _('URL Paths'), loaddoc('urls')), | |
70 | (["extensions"], _("Using additional features"), extshelp), |
|
70 | (["extensions"], _("Using additional features"), extshelp), | |
71 | (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')), |
|
71 | (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')), | |
72 | (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')), |
|
72 | (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')), | |
73 | (["glossary"], _("Glossary"), loaddoc('glossary')), |
|
73 | (["glossary"], _("Glossary"), loaddoc('glossary')), | |
74 | (["hgignore", "ignore"], _("syntax for Mercurial ignore files"), |
|
74 | (["hgignore", "ignore"], _("syntax for Mercurial ignore files"), | |
75 | loaddoc('hgignore')), |
|
75 | loaddoc('hgignore')), | |
76 | (["phases"], _("Working with Phases"), loaddoc('phases')), |
|
76 | (["phases"], _("Working with Phases"), loaddoc('phases')), | |
77 | ]) |
|
77 | ]) | |
78 |
|
78 | |||
79 | # Map topics to lists of callable taking the current topic help and |
|
79 | # Map topics to lists of callable taking the current topic help and | |
80 | # returning the updated version |
|
80 | # returning the updated version | |
81 | helphooks = {} |
|
81 | helphooks = {} | |
82 |
|
82 | |||
83 | def addtopichook(topic, rewriter): |
|
83 | def addtopichook(topic, rewriter): | |
84 | helphooks.setdefault(topic, []).append(rewriter) |
|
84 | helphooks.setdefault(topic, []).append(rewriter) | |
85 |
|
85 | |||
86 | def makeitemsdoc(topic, doc, marker, items): |
|
86 | def makeitemsdoc(topic, doc, marker, items): | |
87 | """Extract docstring from the items key to function mapping, build a |
|
87 | """Extract docstring from the items key to function mapping, build a | |
88 | .single documentation block and use it to overwrite the marker in doc |
|
88 | .single documentation block and use it to overwrite the marker in doc | |
89 | """ |
|
89 | """ | |
90 | entries = [] |
|
90 | entries = [] | |
91 | for name in sorted(items): |
|
91 | for name in sorted(items): | |
92 | text = (items[name].__doc__ or '').rstrip() |
|
92 | text = (items[name].__doc__ or '').rstrip() | |
93 | if not text: |
|
93 | if not text: | |
94 | continue |
|
94 | continue | |
95 | text = gettext(text) |
|
95 | text = gettext(text) | |
96 | lines = text.splitlines() |
|
96 | lines = text.splitlines() | |
97 | lines[1:] = [(' ' + l.strip()) for l in lines[1:]] |
|
97 | doclines = [(lines[0])] | |
98 | entries.append('\n'.join(lines)) |
|
98 | for l in lines[1:]: | |
|
99 | # Stop once we find some Python doctest | |||
|
100 | if l.strip().startswith('>>>'): | |||
|
101 | break | |||
|
102 | doclines.append(' ' + l.strip()) | |||
|
103 | entries.append('\n'.join(doclines)) | |||
99 | entries = '\n\n'.join(entries) |
|
104 | entries = '\n\n'.join(entries) | |
100 | return doc.replace(marker, entries) |
|
105 | return doc.replace(marker, entries) | |
101 |
|
106 | |||
102 | def addtopicsymbols(topic, marker, symbols): |
|
107 | def addtopicsymbols(topic, marker, symbols): | |
103 | def add(topic, doc): |
|
108 | def add(topic, doc): | |
104 | return makeitemsdoc(topic, doc, marker, symbols) |
|
109 | return makeitemsdoc(topic, doc, marker, symbols) | |
105 | addtopichook(topic, add) |
|
110 | addtopichook(topic, add) | |
106 |
|
111 | |||
107 | addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols) |
|
112 | addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols) | |
108 | addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals) |
|
113 | addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals) | |
109 | addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols) |
|
114 | addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols) | |
110 | addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords) |
|
115 | addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords) | |
111 | addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) |
|
116 | addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) |
General Comments 0
You need to be logged in to leave comments.
Login now