Of chickens, eggs, and shadows thereof

Cedric Duval cedricduval at free.fr
Fri Jun 19 14:34:19 CDT 2009


Cedric Duval wrote:
>  3/ list the extensions not enabled but which are available from
>     the standard lookup path, along with their short headline

Here is a proof of concept for a listing of all available (and loadable)
extensions. Comments on the approach and the code much welcome.

-- 
Cédric


#!/usr/bin/env python

import os, imp

# get a dir list from the default lookup path, stripped from any file suffix
dir = imp.find_module('hgext')[1]
list = [ i.rsplit('.')[0] for i in os.listdir(dir) ]

# remove duplicates and sort
names = []
[ names.append(i) for i in list if not names.count(i) ]
names.sort()

# for each name, try to extract its documentation
# and print the extension name along with its headline
maxlength = len(max(names, key=len))
for n in names:
    fd, fpath, desc = imp.find_module(n, [dir])
    try:
        mod = imp.load_module(n, fd, fpath, desc)
    except KeyboardInterrupt:
        raise
    except Exception:
        continue # could not be loaded, skipping

    doc = mod.__doc__
    if doc is None:
        continue

    print '%s   %s' % (n.ljust(maxlength), doc.splitlines()[0])


More information about the Mercurial-devel mailing list