diff options
author | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-11 19:17:17 +0000 |
---|---|---|
committer | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-11 19:17:17 +0000 |
commit | f254781274f35c485befb4f6acedb8fb8d1f797b (patch) | |
tree | 81f82e11fce6aa27abf9853cf9e183d40d593cc5 /libbe/plugin.py | |
parent | 20a48a1ad3f720d915084d6d139b3790cd4630eb (diff) | |
download | bugseverywhere-f254781274f35c485befb4f6acedb8fb8d1f797b.tar.gz |
Implemented plugin system for viewing commands
Diffstat (limited to 'libbe/plugin.py')
-rw-r--r-- | libbe/plugin.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libbe/plugin.py b/libbe/plugin.py new file mode 100644 index 0000000..2dedac4 --- /dev/null +++ b/libbe/plugin.py @@ -0,0 +1,25 @@ +import os +import os.path +import sys +def my_import(mod_name): + module = __import__(mod_name) + components = mod_name.split('.') + for comp in components[1:]: + module = getattr(module, comp) + return module + +def iter_plugins(prefix): + modfiles = os.listdir(os.path.join(sys.path[0], prefix)) + modfiles.sort() + for modfile in modfiles: + if modfile.endswith(".py") and modfile != "__init__.py": + yield modfile[:-3], my_import(prefix+"."+modfile[:-3]) + + +def get_plugin(prefix, name): + dirprefix = '/'.join(prefix.split('.')) + command_path = os.path.join(sys.path[0], dirprefix, name+".py") + if os.path.isfile(command_path): + return my_import(prefix + "." + name) + return None + |