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 | |
parent | 20a48a1ad3f720d915084d6d139b3790cd4630eb (diff) | |
download | bugseverywhere-f254781274f35c485befb4f6acedb8fb8d1f797b.tar.gz |
Implemented plugin system for viewing commands
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/cmdutil.py | 9 | ||||
-rw-r--r-- | libbe/plugin.py | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 2afd53c..77f0dfb 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -1,4 +1,5 @@ import bugdir +import plugin def unique_name(bug, bugs): chars = 1 for some_bug in bugs: @@ -49,3 +50,11 @@ def bug_summary(bug, bugs): (unique_name(bug, bugs), bug.severity, target, bug.creator, bug.summary) +def iter_commands(): + return plugin.iter_plugins("becommands") + +def execute(cmd, args): + return plugin.get_plugin("becommands", cmd).execute(args) + +def help(cmd, args): + return plugin.get_plugin("becommands", cmd).help() 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 + |