[PATCH 3 of 8] extensions: split retrieval of the extensions file paths
Cédric Duval
cedricduval at free.fr
Sat Jul 4 15:05:09 CDT 2009
# HG changeset patch
# User Cédric Duval <cedricduval at free.fr>
# Date 1246737838 -7200
# Node ID 9ed801746dffaa8093991c959436bd2f34ead2bb
# Parent fcb323504f182c854d1704367c745494abd59fae
extensions: split retrieval of the extensions file paths
Function returning the paths of extensions, meant to be later
moved into extdoc.
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -118,6 +118,24 @@
setattr(container, funcname, wrap)
return origfn
+def extfiles(path):
+ '''return a dict of {name: filename} for all extensions in the given path'''
+ try: # might not be a filesystem path
+ list = os.listdir(path)
+ except OSError:
+ return {}
+
+ exts = {}
+ abspath = os.path.abspath(path)
+ for e in list:
+ if e.endswith('.py') and e != '__init__.py':
+ exts[e.rsplit('.', 1)[0]] = os.path.join(abspath, e)
+ else:
+ path = os.path.join(abspath, e, '__init__.py')
+ if os.path.exists(path):
+ exts[e] = path
+ return exts
+
def disabled():
'''find disabled extensions
returns a dict of {name: desc}, and the max name length'''
@@ -135,27 +153,8 @@
def extractdoc(extpath):
'''extract descriptions from extensions in extpath
returns a dict of {name: desc}'''
-
- try: # might not be a filesystem path
- files = os.listdir(extpath)
- except OSError:
- return {}
-
exts = {}
- for e in files:
-
- 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 not os.path.exists(path):
- continue
-
- if name in exts or name == '__init__':
- continue
-
+ for name, path in extfiles(extpath).iteritems():
try:
file = open(path)
except IOError:
More information about the Mercurial-devel
mailing list