Show More
@@ -1484,7 +1484,7 b' def help_(ui, name=None, with_version=Fa' | |||
|
1484 | 1484 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
1485 | 1485 | |
|
1486 | 1486 | if name != 'shortlist': |
|
1487 |
exts, maxlength = |
|
|
1487 | exts, maxlength = extensions.enabled() | |
|
1488 | 1488 | ui.write(help.extensionslisting(_('enabled extensions:'), |
|
1489 | 1489 | exts, maxlength)) |
|
1490 | 1490 |
@@ -5,9 +5,9 b'' | |||
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | import imp, os | |
|
9 | import util, cmdutil | |
|
10 | from i18n import _ | |
|
8 | import imp, os, sys | |
|
9 | import util, cmdutil, help | |
|
10 | from i18n import _, gettext | |
|
11 | 11 | |
|
12 | 12 | _extensions = {} |
|
13 | 13 | _order = [] |
@@ -117,3 +117,75 b' def wrapfunction(container, funcname, wr' | |||
|
117 | 117 | origfn = getattr(container, funcname) |
|
118 | 118 | setattr(container, funcname, wrap) |
|
119 | 119 | return origfn |
|
120 | ||
|
121 | def pathdirs(): | |
|
122 | '''convert sys.path into a list of absolute, existing, unique paths | |
|
123 | (taken from pydoc)''' | |
|
124 | dirs = [] | |
|
125 | normdirs = [] | |
|
126 | for dir in sys.path: | |
|
127 | dir = os.path.abspath(dir or '.') | |
|
128 | normdir = os.path.normcase(dir) | |
|
129 | if normdir not in normdirs and os.path.isdir(dir): | |
|
130 | dirs.append(dir) | |
|
131 | normdirs.append(normdir) | |
|
132 | return dirs | |
|
133 | ||
|
134 | def disabled(): | |
|
135 | '''find disabled extensions from hgext | |
|
136 | returns a dict of {name: desc}, and the max name length''' | |
|
137 | exts = {} | |
|
138 | maxlength = 0 | |
|
139 | for dir in filter(os.path.isdir, | |
|
140 | (os.path.join(pd, 'hgext') for pd in pathdirs())): | |
|
141 | for e in os.listdir(dir): | |
|
142 | if e.endswith('.py'): | |
|
143 | name = e.rsplit('.', 1)[0] | |
|
144 | path = os.path.join(dir, e) | |
|
145 | else: | |
|
146 | name = e | |
|
147 | path = os.path.join(dir, e, '__init__.py') | |
|
148 | ||
|
149 | if name in exts or name == '__init__' or not os.path.exists(path): | |
|
150 | continue | |
|
151 | ||
|
152 | try: | |
|
153 | find(name) | |
|
154 | except KeyError: | |
|
155 | pass | |
|
156 | else: | |
|
157 | continue # enabled extension | |
|
158 | ||
|
159 | try: | |
|
160 | file = open(path) | |
|
161 | except IOError: | |
|
162 | continue | |
|
163 | else: | |
|
164 | doc = help.moduledoc(file) | |
|
165 | file.close() | |
|
166 | ||
|
167 | if doc: # extracting localized synopsis | |
|
168 | exts[name] = gettext(doc).splitlines()[0] | |
|
169 | else: | |
|
170 | exts[name] = _('(no help text available)') | |
|
171 | if len(name) > maxlength: | |
|
172 | maxlength = len(name) | |
|
173 | ||
|
174 | return exts, maxlength | |
|
175 | ||
|
176 | def enabled(): | |
|
177 | '''return a dict of {name: desc} of extensions, and the max name length''' | |
|
178 | ||
|
179 | if not enabled: | |
|
180 | return {}, 0 | |
|
181 | ||
|
182 | exts = {} | |
|
183 | maxlength = 0 | |
|
184 | exthelps = [] | |
|
185 | for ename, ext in extensions(): | |
|
186 | doc = (gettext(ext.__doc__) or _('(no help text available)')) | |
|
187 | ename = ename.split('.')[-1] | |
|
188 | maxlength = max(len(ename), maxlength) | |
|
189 | exts[ename] = doc.splitlines(0)[0].strip() | |
|
190 | ||
|
191 | return exts, maxlength |
@@ -5,24 +5,10 b'' | |||
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | import os, sys | |
|
9 | from i18n import _, gettext | |
|
8 | from i18n import _ | |
|
10 | 9 | import extensions |
|
11 | 10 | |
|
12 | 11 | |
|
13 | # borrowed from pydoc | |
|
14 | def pathdirs(): | |
|
15 | '''Convert sys.path into a list of absolute, existing, unique paths.''' | |
|
16 | dirs = [] | |
|
17 | normdirs = [] | |
|
18 | for dir in sys.path: | |
|
19 | dir = os.path.abspath(dir or '.') | |
|
20 | normdir = os.path.normcase(dir) | |
|
21 | if normdir not in normdirs and os.path.isdir(dir): | |
|
22 | dirs.append(dir) | |
|
23 | normdirs.append(normdir) | |
|
24 | return dirs | |
|
25 | ||
|
26 | 12 | # loosely inspired by pydoc.source_synopsis() |
|
27 | 13 | # rewritten to handle ''' as well as """ |
|
28 | 14 | # and to return the whole text instead of just the synopsis |
@@ -53,67 +39,6 b' def moduledoc(file):' | |||
|
53 | 39 | |
|
54 | 40 | return ''.join(result) |
|
55 | 41 | |
|
56 | def additionalextensions(): | |
|
57 | '''Find the extensions shipped with Mercurial but not enabled | |
|
58 | ||
|
59 | Returns extensions names and descriptions, and the max name length | |
|
60 | ''' | |
|
61 | exts = {} | |
|
62 | maxlength = 0 | |
|
63 | ||
|
64 | for dir in filter(os.path.isdir, | |
|
65 | (os.path.join(pd, 'hgext') for pd in pathdirs())): | |
|
66 | for e in os.listdir(dir): | |
|
67 | if e.endswith('.py'): | |
|
68 | name = e.rsplit('.', 1)[0] | |
|
69 | path = os.path.join(dir, e) | |
|
70 | else: | |
|
71 | name = e | |
|
72 | path = os.path.join(dir, e, '__init__.py') | |
|
73 | ||
|
74 | if name in exts or name == '__init__' or not os.path.exists(path): | |
|
75 | continue | |
|
76 | ||
|
77 | try: | |
|
78 | extensions.find(name) | |
|
79 | except KeyError: | |
|
80 | pass | |
|
81 | else: | |
|
82 | continue # enabled extension | |
|
83 | ||
|
84 | try: | |
|
85 | file = open(path) | |
|
86 | except IOError: | |
|
87 | continue | |
|
88 | else: | |
|
89 | doc = moduledoc(file) | |
|
90 | file.close() | |
|
91 | ||
|
92 | if doc: # extracting localized synopsis | |
|
93 | exts[name] = gettext(doc).splitlines()[0] | |
|
94 | else: | |
|
95 | exts[name] = _('(no help text available)') | |
|
96 | if len(name) > maxlength: | |
|
97 | maxlength = len(name) | |
|
98 | ||
|
99 | return exts, maxlength | |
|
100 | ||
|
101 | def enabledextensions(): | |
|
102 | '''Return the list of enabled extensions, and max name length''' | |
|
103 | enabled = list(extensions.extensions()) | |
|
104 | exts = {} | |
|
105 | maxlength = 0 | |
|
106 | ||
|
107 | if enabled: | |
|
108 | exthelps = [] | |
|
109 | for ename, ext in enabled: | |
|
110 | doc = (gettext(ext.__doc__) or _('(no help text available)')) | |
|
111 | ename = ename.split('.')[-1] | |
|
112 | maxlength = max(len(ename), maxlength) | |
|
113 | exts[ename] = doc.splitlines(0)[0].strip() | |
|
114 | ||
|
115 | return exts, maxlength | |
|
116 | ||
|
117 | 42 | def extensionslisting(header, exts, maxlength): |
|
118 | 43 | '''Return a text listing of the given extensions''' |
|
119 | 44 | result = '' |
@@ -160,10 +85,10 b' def topicextensions():' | |||
|
160 | 85 | hgext.baz = ! |
|
161 | 86 | ''') |
|
162 | 87 | |
|
163 |
exts, maxlength = |
|
|
88 | exts, maxlength = extensions.enabled() | |
|
164 | 89 | doc += extensionslisting(_('enabled extensions:'), exts, maxlength) |
|
165 | 90 | |
|
166 |
exts, maxlength = |
|
|
91 | exts, maxlength = extensions.disabled() | |
|
167 | 92 | doc += extensionslisting(_('non-enabled extensions:'), exts, maxlength) |
|
168 | 93 | |
|
169 | 94 | return doc |
General Comments 0
You need to be logged in to leave comments.
Login now