aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/plugin.py')
-rw-r--r--libbe/plugin.py25
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
+