comparison mercurial/extensions.py @ 8872:d0c0013f8713

extensions: simplify by selecting primary hgext
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sun, 21 Jun 2009 16:35:44 +0200
parents 20a25042fadc
children e4e22a310b62
comparison
equal deleted inserted replaced
8871:20a25042fadc 8872:d0c0013f8713
132 return dirs 132 return dirs
133 133
134 def disabled(): 134 def disabled():
135 '''find disabled extensions from hgext 135 '''find disabled extensions from hgext
136 returns a dict of {name: desc}, and the max name length''' 136 returns a dict of {name: desc}, and the max name length'''
137
138 import hgext
139 extpath = os.path.dirname(os.path.abspath(hgext.__file__))
140
137 exts = {} 141 exts = {}
138 maxlength = 0 142 maxlength = 0
139 for dir in filter(os.path.isdir, 143 for e in os.listdir(extpath):
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 144
149 if name in exts or name == '__init__' or not os.path.exists(path): 145 if e.endswith('.py'):
150 continue 146 name = e.rsplit('.', 1)[0]
147 path = os.path.join(extpath, e)
148 else:
149 name = e
150 path = os.path.join(extpath, e, '__init__.py')
151 151
152 try: 152 if name in exts or name == '__init__' or not os.path.exists(path):
153 find(name) 153 continue
154 except KeyError:
155 pass
156 else:
157 continue # enabled extension
158 154
159 try: 155 try:
160 file = open(path) 156 find(name)
161 except IOError: 157 except KeyError:
162 continue 158 pass
163 else: 159 else:
164 doc = help.moduledoc(file) 160 continue # enabled extension
165 file.close()
166 161
167 if doc: # extracting localized synopsis 162 try:
168 exts[name] = gettext(doc).splitlines()[0] 163 file = open(path)
169 else: 164 except IOError:
170 exts[name] = _('(no help text available)') 165 continue
171 if len(name) > maxlength: 166 else:
172 maxlength = len(name) 167 doc = help.moduledoc(file)
168 file.close()
169
170 if doc: # extracting localized synopsis
171 exts[name] = gettext(doc).splitlines()[0]
172 else:
173 exts[name] = _('(no help text available)')
174
175 if len(name) > maxlength:
176 maxlength = len(name)
173 177
174 return exts, maxlength 178 return exts, maxlength
175 179
176 def enabled(): 180 def enabled():
177 '''return a dict of {name: desc} of extensions, and the max name length''' 181 '''return a dict of {name: desc} of extensions, and the max name length'''