# HG changeset patch # User Dirkjan Ochtman # Date 2009-06-21 14:35:44 # Node ID d0c0013f8713c186c12e8254d89b4725884b05ba # Parent 20a25042fadc83b8ac6a732fad5014e621010be4 extensions: simplify by selecting primary hgext diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -134,42 +134,46 @@ def pathdirs(): def disabled(): '''find disabled extensions from hgext returns a dict of {name: desc}, and the max name length''' + + import hgext + extpath = os.path.dirname(os.path.abspath(hgext.__file__)) + exts = {} maxlength = 0 - for dir in filter(os.path.isdir, - (os.path.join(pd, 'hgext') for pd in pathdirs())): - for e in os.listdir(dir): - if e.endswith('.py'): - name = e.rsplit('.', 1)[0] - path = os.path.join(dir, e) - else: - name = e - path = os.path.join(dir, e, '__init__.py') + for e in os.listdir(extpath): - if name in exts or name == '__init__' or not os.path.exists(path): - continue + if e.endswith('.py'): + name = e.rsplit('.', 1)[0] + path = os.path.join(extpath, e) + else: + name = e + path = os.path.join(extpath, e, '__init__.py') + + if name in exts or name == '__init__' or not os.path.exists(path): + continue - try: - find(name) - except KeyError: - pass - else: - continue # enabled extension + try: + find(name) + except KeyError: + pass + else: + continue # enabled extension - try: - file = open(path) - except IOError: - continue - else: - doc = help.moduledoc(file) - file.close() + try: + file = open(path) + except IOError: + continue + else: + doc = help.moduledoc(file) + file.close() - if doc: # extracting localized synopsis - exts[name] = gettext(doc).splitlines()[0] - else: - exts[name] = _('(no help text available)') - if len(name) > maxlength: - maxlength = len(name) + if doc: # extracting localized synopsis + exts[name] = gettext(doc).splitlines()[0] + else: + exts[name] = _('(no help text available)') + + if len(name) > maxlength: + maxlength = len(name) return exts, maxlength