Implemented plugin system for viewing commands
authorAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 19:17:17 +0000 (19:17 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 19:17:17 +0000 (19:17 +0000)
be
becommands/close.py
becommands/list.py
becommands/new.py
becommands/open.py
becommands/set_root.py
becommands/show.py
libbe/cmdutil.py
libbe/plugin.py [new file with mode: 0644]

diff --git a/be b/be
index 3aa8d383061a8bce85502ed56b8c365c23cbcec9..3c6c36dbfd411ba264df6821f6862ef79df59c2d 100755 (executable)
--- 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:
index 184e2e17c673df0d7a88ac27dba1c3e95ee44bc7..11c5c7443d414d8bc6062eeeb308cb80b6745c8b 100644 (file)
@@ -1,3 +1,4 @@
+"""Close a bug"""
 from libbe import cmdutil
 def execute(args):
     assert(len(args) == 1)
index b6086293b49ce0bd4566ac6d57d8114832b35734..d4b9142658175e519e845497dffee3b37d20ea83 100644 (file)
@@ -1,3 +1,4 @@
+"""List bugs"""
 from libbe import bugdir, cmdutil
 import os
 def execute(args):
index 2e78524b268d79c28261f49aa1c15d5fccb6df1e..284f730dea13db7d8307e09432af651df4e79a34 100644 (file)
@@ -1,3 +1,4 @@
+"""Create a new bug"""
 from libbe import bugdir, cmdutil, names
 def execute(args):
     if len(args) != 1:
index db8903517086e52fc448d90222656a0c8c72a07f..e6ff51e5c0dff00303652902996c0ccfd243af25 100644 (file)
@@ -1,3 +1,4 @@
+"""Re-open a bug"""
 from libbe import cmdutil
 def execute(args):
     assert(len(args) == 1)
index bf1d4953ab995e8b86269c18ae71dd31725f4aa5..0775da3891263397c55870b771281fa6729d2d6b 100644 (file)
@@ -1,3 +1,4 @@
+"""Assign the root directory for bug tracking"""
 from libbe import bugdir, cmdutil
 
 def execute(args):
index 8b383861e035a46e72c56ee915bc71a4924ec049..cd74eae789ca559355c0f75d72a1a02e1362679f 100644 (file)
@@ -1,3 +1,4 @@
+"""Show a particular bug"""
 from libbe import bugdir, cmdutil
 import os
 
index 2afd53cc0dd87458ebff3f220385707be45cf9ff..77f0dfbe9b3b316e224fad5eb6f0a6828b5de20a 100644 (file)
@@ -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 (file)
index 0000000..2dedac4
--- /dev/null
@@ -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