diff options
author | Joel Andres Granados <jgranado@redhat.com> | 2008-02-20 12:40:45 +0100 |
---|---|---|
committer | Joel Andres Granados <jgranado@redhat.com> | 2008-02-20 12:40:45 +0100 |
commit | d617db6660cf5a3e7d6ae6270a00a317dadd5180 (patch) | |
tree | 4d72ee752e298b60ac3ffcd6b552e7d6b5aac534 /pyfirstaidkit/plugins.py | |
parent | 92cd3738523c90ff1464e0f3de9d064d0ac3132e (diff) | |
download | firstaidkit-d617db6660cf5a3e7d6ae6270a00a317dadd5180.tar.gz firstaidkit-d617db6660cf5a3e7d6ae6270a00a317dadd5180.tar.xz firstaidkit-d617db6660cf5a3e7d6ae6270a00a317dadd5180.zip |
Allow to look for plugins in multiple places.
Diffstat (limited to 'pyfirstaidkit/plugins.py')
-rw-r--r-- | pyfirstaidkit/plugins.py | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py index bf54c9f..f1dcf61 100644 --- a/pyfirstaidkit/plugins.py +++ b/pyfirstaidkit/plugins.py @@ -335,41 +335,42 @@ class PluginSystem(object): """Encapsulate all plugin detection and import stuff""" def __init__(self, reporting, dependencies, config = Config): - self._path = Config.plugin.path + self._paths = Config.plugin.paths.split(',') self._reporting = reporting self._deps = dependencies self._plugins = {} - #create list of potential modules in the path - importlist = set() - for f in os.listdir(self._path): - fullpath = os.path.join(self._path, f) - Logger.debug("Processing file: %s", f) - if os.path.isdir(fullpath) and os.path.isfile(os.path.join(self._path, f, "__init__.py")): - importlist.add(f) - Logger.debug("Adding python module (directory): %s", f) - elif os.path.isfile(fullpath) and (f[-3:]==".so" or f[-3:]==".py"): - importlist.add(f[:-3]) - Logger.debug("Adding python module (file): %s", f) - elif os.path.isfile(fullpath) and (f[-4:]==".pyc" or f[-4:]==".pyo"): - importlist.add(f[:-4]) - Logger.debug("Adding python module (compiled): %s", f) - - #try to import the modules as FirstAidKit.plugins.modulename - for m in importlist: - if m in Config.plugin._list("disabled"): - continue - - imp.acquire_lock() - try: - Logger.debug("Importing module %s from %s", m, self._path) - moduleinfo = imp.find_module(m, [self._path]) - module = imp.load_module(".".join([FirstAidKit.__name__, m]), *moduleinfo) - Logger.debug("... OK") - finally: - imp.release_lock() - - self._plugins[m] = module + for path in self._paths: + #create list of potential modules in the path + importlist = set() + for f in os.listdir(path): + fullpath = os.path.join(path, f) + Logger.debug("Processing file: %s", f) + if os.path.isdir(fullpath) and os.path.isfile(os.path.join(path, f, "__init__.py")): + importlist.add(f) + Logger.debug("Adding python module (directory): %s", f) + elif os.path.isfile(fullpath) and (f[-3:]==".so" or f[-3:]==".py"): + importlist.add(f[:-3]) + Logger.debug("Adding python module (file): %s", f) + elif os.path.isfile(fullpath) and (f[-4:]==".pyc" or f[-4:]==".pyo"): + importlist.add(f[:-4]) + Logger.debug("Adding python module (compiled): %s", f) + + #try to import the modules as FirstAidKit.plugins.modulename + for m in importlist: + if m in Config.plugin._list("disabled"): + continue + + imp.acquire_lock() + try: + Logger.debug("Importing module %s from %s", m, path) + moduleinfo = imp.find_module(m, [path]) + module = imp.load_module(".".join([FirstAidKit.__name__, m]), *moduleinfo) + Logger.debug("... OK") + finally: + imp.release_lock() + + self._plugins[m] = module def list(self): """Return the list of imported plugins""" |