aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2005-03-11 19:17:17 +0000
committerAaron Bentley <abentley@panoramicfeedback.com>2005-03-11 19:17:17 +0000
commitf254781274f35c485befb4f6acedb8fb8d1f797b (patch)
tree81f82e11fce6aa27abf9853cf9e183d40d593cc5
parent20a48a1ad3f720d915084d6d139b3790cd4630eb (diff)
downloadbugseverywhere-f254781274f35c485befb4f6acedb8fb8d1f797b.tar.gz
Implemented plugin system for viewing commands
-rwxr-xr-xbe11
-rw-r--r--becommands/close.py1
-rw-r--r--becommands/list.py1
-rw-r--r--becommands/new.py1
-rw-r--r--becommands/open.py1
-rw-r--r--becommands/set_root.py1
-rw-r--r--becommands/show.py1
-rw-r--r--libbe/cmdutil.py9
-rw-r--r--libbe/plugin.py25
9 files changed, 49 insertions, 2 deletions
diff --git a/be b/be
index 3aa8d38..3c6c36d 100755
--- a/be
+++ b/be
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from libbe.cmdutil import *
from libbe.bugdir import tree_root, create_bug_dir
-from libbe import names
+from libbe import names, plugin, cmdutil
import sys
import os
import becommands.severity
@@ -29,7 +29,14 @@ Unimplemented becommands
if len(sys.argv) == 1:
- print __doc__
+ cmdlist = []
+ print """Bugs Everywhere - Distributed bug tracking
+
+Supported commands"""
+ for name, module in cmdutil.iter_commands():
+ cmdlist.append((name, module.__doc__))
+ for name, desc in cmdlist:
+ print "%s: %s" % (name, desc)
else:
try:
try:
diff --git a/becommands/close.py b/becommands/close.py
index 184e2e1..11c5c74 100644
--- a/becommands/close.py
+++ b/becommands/close.py
@@ -1,3 +1,4 @@
+"""Close a bug"""
from libbe import cmdutil
def execute(args):
assert(len(args) == 1)
diff --git a/becommands/list.py b/becommands/list.py
index b608629..d4b9142 100644
--- a/becommands/list.py
+++ b/becommands/list.py
@@ -1,3 +1,4 @@
+"""List bugs"""
from libbe import bugdir, cmdutil
import os
def execute(args):
diff --git a/becommands/new.py b/becommands/new.py
index 2e78524..284f730 100644
--- a/becommands/new.py
+++ b/becommands/new.py
@@ -1,3 +1,4 @@
+"""Create a new bug"""
from libbe import bugdir, cmdutil, names
def execute(args):
if len(args) != 1:
diff --git a/becommands/open.py b/becommands/open.py
index db89035..e6ff51e 100644
--- a/becommands/open.py
+++ b/becommands/open.py
@@ -1,3 +1,4 @@
+"""Re-open a bug"""
from libbe import cmdutil
def execute(args):
assert(len(args) == 1)
diff --git a/becommands/set_root.py b/becommands/set_root.py
index bf1d495..0775da3 100644
--- a/becommands/set_root.py
+++ b/becommands/set_root.py
@@ -1,3 +1,4 @@
+"""Assign the root directory for bug tracking"""
from libbe import bugdir, cmdutil
def execute(args):
diff --git a/becommands/show.py b/becommands/show.py
index 8b38386..cd74eae 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -1,3 +1,4 @@
+"""Show a particular bug"""
from libbe import bugdir, cmdutil
import os
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
+