aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/plugins/__init__.py
blob: 1eeb3bbd2675689381cc88c58085a5db762f075f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os

loaded = {}

def load():
    # based on smart's plugin system 
    pluginsdir = os.path.dirname(__file__)
    for entry in os.listdir(pluginsdir):
        if entry != "__init__.py" and entry.endswith(".py"):
            name = entry[:-3]
            loaded[name] = __import__("MgaRepo.plugins."+name, {}, {},
                    [name])
        elif os.path.isdir(entry):
            initfile = os.path.join(entry, "__init__.py")
            if os.path.isfile(initfile):
                loaded[entry] = __import__("MgaRepo.plugins."+entry, {}, {},
                        [entry])

def list():
    return loaded.keys()

def help(name):
    from MgaRepo import Error
    try:
        return loaded[name].__doc__
    except KeyError:
        raise Error, "plugin %s not found" % name