Test adding of toggle actions
[gregoa/zavai.git] / zavai / plugins.py
1 #!/usr/bin/env python
2 #
3 #  File: plugins.py
4
5 #  Copyright (C) 2008 Christopher R. Gabriel <cgabriel@truelite.it> 
6
7 #  This program is free software; you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2 of the License, or
10 #  (at your option) any later version.
11
12
13 import os
14 import os.path
15 import imp
16 import sys
17
18 def load_plugins(pluginpath=None, nick="octofuss"):
19         """return a list of all available plugins
20         in the given directory"""
21
22         if not pluginpath:
23                 pluginpath = os.environ.get(nick.upper() + "_PLUGINS", "plugins")
24
25         # if the plugin path need to be auto-discovered
26         # starting from a specified module
27         #pluginpath = os.path.join(os.path.dirname(imp.find_module("octofussd")[1]), "extensions/")
28         #pluginpath = "."
29         pluginfiles = [fname[:-3] for fname in os.listdir(pluginpath) if fname.endswith(".py") and not fname.startswith(".") and not fname.endswith("~")]
30
31         for fname in pluginfiles:
32                 oldpath = sys.path
33                 try:
34                         sys.path.append(os.path.abspath(pluginpath))
35                         res = imp.load_source(fname, os.path.join(pluginpath, fname) + ".py")
36                 finally:
37                         sys.path = oldpath
38                 yield res
39