aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-16 14:12:06 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-16 14:12:06 -0500
commite7c376ed286b3bf741ae9e364eef7dd2114d77c7 (patch)
tree095386a2f4f1d7aac1520b4e9689667decff41cf
parentdbe327909b048e0709b598fd60f02ef53b25a0ea (diff)
downloadbugseverywhere-e7c376ed286b3bf741ae9e364eef7dd2114d77c7.tar.gz
Added 'remove' command to remove bugs. Use __desc__ for command help.
Using the __desc__ reduces documentation duplication. It's also better than using __doc__, because __doc__ could (should?) be more than one-line long, and we just want a short description to jog our memories in the complete command list. Also moved unique_name from cmdutil.py to names.py to avoid the bug->cmdutil->bugdir->bug cyclic include.
-rw-r--r--.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/body1
-rw-r--r--.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/values21
-rwxr-xr-xbe31
-rw-r--r--becommands/__init__.py15
-rw-r--r--becommands/close.py2
-rw-r--r--becommands/comment.py2
-rw-r--r--becommands/diff.py2
-rw-r--r--becommands/help.py3
-rw-r--r--becommands/list.py2
-rw-r--r--becommands/new.py3
-rw-r--r--becommands/open.py2
-rw-r--r--becommands/set.py2
-rw-r--r--becommands/set_root.py1
-rw-r--r--becommands/severity.py1
-rw-r--r--becommands/show.py5
-rw-r--r--becommands/template21
-rw-r--r--becommands/upgrade.py1
-rw-r--r--libbe/bug.py25
-rw-r--r--libbe/cmdutil.py44
-rw-r--r--libbe/names.py18
-rw-r--r--libbe/plugin.py1
21 files changed, 111 insertions, 92 deletions
diff --git a/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/body b/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/body
new file mode 100644
index 0000000..d7a57d9
--- /dev/null
+++ b/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/body
@@ -0,0 +1 @@
+I dunno, bugs everywhere is such a great mental image... ;)
diff --git a/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/values b/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/values
new file mode 100644
index 0000000..cb5a094
--- /dev/null
+++ b/.be/bugs/cf56e648-3b09-4131-8847-02dff12b4db2/comments/f05359f6-1bfc-4aa6-9a6d-673516bc0f94/values
@@ -0,0 +1,21 @@
+
+
+
+Content-type=text/plain
+
+
+
+
+
+
+Date=Sat, 15 Nov 2008 23:56:51 +0000
+
+
+
+
+
+
+From=wking
+
+
+
diff --git a/be b/be
index 9be1804..ea7f65a 100755
--- a/be
+++ b/be
@@ -22,39 +22,16 @@ from libbe.bugdir import tree_root, create_bug_dir
from libbe import names, plugin, cmdutil
import sys
import os
-import becommands.severity
-import becommands.status
-import becommands.list
-import becommands.show
-import becommands.set_root
-import becommands.new
-import becommands.close
-import becommands.open
-__doc__ = """Bugs Everywhere - Distributed bug tracking
-
-Supported becommands
- set-root: assign the root directory for bug tracking
- new: Create a new bug
- list: list bugs
- show: show a particular bug
- close: close a bug
- open: re-open a bug
- severity: %s
- status: %s
-
-Unimplemented becommands
- comment: append a comment to a bug
-""" % (becommands.severity.__desc__,
- becommands.status.__desc__)
-
+import becommands
+__doc__ == cmdutil.help()
if len(sys.argv) == 1 or sys.argv[1] in ('--help', '-h'):
- cmdutil.print_command_list()
+ print cmdutil.help()
else:
try:
try:
- sys.exit(execute(sys.argv[1], sys.argv[2:]))
+ sys.exit(cmdutil.execute(sys.argv[1], sys.argv[2:]))
except KeyError, e:
raise UserError("Unknown command \"%s\"" % e.args[0])
except cmdutil.GetHelp:
diff --git a/becommands/__init__.py b/becommands/__init__.py
index e69de29..6b07378 100644
--- a/becommands/__init__.py
+++ b/becommands/__init__.py
@@ -0,0 +1,15 @@
+"Command plugins for the BugsEverywhere be script."
+
+__all__ = ["set_root", "set", "new", "remove", "list", "show", "close", "open",
+ "assign", "severity", "status", "target", "comment", "diff",
+ "upgrade", "help"]
+
+def import_all():
+ for i in __all__:
+ name = __name__ + "." + i
+ try:
+ __import__(name, globals(), locals(), [])
+ except ImportError:
+ print "Import of %s failed!" % (name,)
+
+import_all()
diff --git a/becommands/close.py b/becommands/close.py
index 52ab735..8e62b90 100644
--- a/becommands/close.py
+++ b/becommands/close.py
@@ -16,6 +16,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Close a bug"""
from libbe import cmdutil
+__desc__ = __doc__
+
def execute(args):
"""
>>> from libbe import tests
diff --git a/becommands/comment.py b/becommands/comment.py
index 50fdc23..5939490 100644
--- a/becommands/comment.py
+++ b/becommands/comment.py
@@ -18,6 +18,8 @@
from libbe import cmdutil, names, utility
from libbe.bug import new_comment
import os
+__desc__ = __doc__
+
def execute(args):
"""
>>> from libbe import tests, names
diff --git a/becommands/diff.py b/becommands/diff.py
index 82ebb2c..5a3a7cf 100644
--- a/becommands/diff.py
+++ b/becommands/diff.py
@@ -18,6 +18,8 @@
"""Compare bug reports with older tree"""
from libbe import bugdir, diff, cmdutil
import os
+__desc__ = __doc__
+
def execute(args):
options, args = get_parser().parse_args(args)
if len(args) == 0:
diff --git a/becommands/help.py b/becommands/help.py
index 45d35ca..f6cfe3f 100644
--- a/becommands/help.py
+++ b/becommands/help.py
@@ -16,6 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Print help for given subcommand"""
from libbe import cmdutil, names, utility
+__desc__ = __doc__
def execute(args):
"""
@@ -25,7 +26,7 @@ def execute(args):
if len(args) > 1:
raise cmdutil.UserError("Too many arguments.")
if len(args) == 0:
- cmdutil.print_command_list()
+ print cmdutil.help()
else:
try:
print cmdutil.help(args[0])
diff --git a/becommands/list.py b/becommands/list.py
index 4514039..59eb8ad 100644
--- a/becommands/list.py
+++ b/becommands/list.py
@@ -19,6 +19,8 @@ from libbe import cmdutil, names
from libbe.bug import cmp_full, severity_values, status_values, \
active_status_values, inactive_status_values
import os
+__desc__ = __doc__
+
def execute(args):
options, args = get_parser().parse_args(args)
if len(args) > 0:
diff --git a/becommands/new.py b/becommands/new.py
index b22dd0a..40ab3f5 100644
--- a/becommands/new.py
+++ b/becommands/new.py
@@ -17,6 +17,7 @@
"""Create a new bug"""
from libbe import cmdutil, names, utility
from libbe.bug import new_bug
+__desc__ = __doc__
def execute(args):
"""
@@ -47,7 +48,7 @@ def execute(args):
bug.summary = args[0]
bug.save()
bugs = (dir.list())
- print "Created bug with ID %s" % cmdutil.unique_name(bug, bugs)
+ print "Created bug with ID %s" % names.unique_name(bug, bugs)
def get_parser():
parser = cmdutil.CmdOptionParser("be new SUMMARY")
diff --git a/becommands/open.py b/becommands/open.py
index f7c23c1..654a1f5 100644
--- a/becommands/open.py
+++ b/becommands/open.py
@@ -16,6 +16,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Re-open a bug"""
from libbe import cmdutil
+__desc__ = __doc__
+
def execute(args):
"""
>>> from libbe import tests
diff --git a/becommands/set.py b/becommands/set.py
index e359df1..8a76133 100644
--- a/becommands/set.py
+++ b/becommands/set.py
@@ -16,6 +16,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Change tree settings"""
from libbe import cmdutil
+__desc__ = __doc__
+
def execute(args):
"""
>>> from libbe import tests
diff --git a/becommands/set_root.py b/becommands/set_root.py
index 2ae7e1a..cc21c31 100644
--- a/becommands/set_root.py
+++ b/becommands/set_root.py
@@ -16,6 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Assign the root directory for bug tracking"""
from libbe import bugdir, cmdutil, rcs
+__desc__ = __doc__
def execute(args):
"""
diff --git a/becommands/severity.py b/becommands/severity.py
index 1a68c31..6845875 100644
--- a/becommands/severity.py
+++ b/becommands/severity.py
@@ -17,7 +17,6 @@
"""Show or change a bug's severity level"""
from libbe import cmdutil
from libbe.bug import severity_values, severity_description
-
__desc__ = __doc__
def execute(args):
diff --git a/becommands/show.py b/becommands/show.py
index 678a607..669a81d 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -15,9 +15,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Show a particular bug"""
-from libbe import cmdutil, utility
+from libbe import cmdutil, names, utility
from libbe.bug import thread_comments
import os
+__desc__ = __doc__
def execute(args):
options, args = get_parser().parse_args(args)
@@ -26,7 +27,7 @@ def execute(args):
bug_dir = cmdutil.bug_tree()
bug = cmdutil.get_bug(args[0], bug_dir)
print bug.string().rstrip("\n")
- unique_name = cmdutil.unique_name(bug, bug_dir.list())
+ unique_name = names.unique_name(bug, bug_dir.list())
comments = []
name_map = {}
for c_name, comment in cmdutil.iter_comment_name(bug, unique_name):
diff --git a/becommands/template b/becommands/template
deleted file mode 100644
index 3c871e6..0000000
--- a/becommands/template
+++ /dev/null
@@ -1,21 +0,0 @@
-"""Short description"""
-from libbe import bugdir, cmdutil, names
-import os
-def execute(args):
- options, args = get_parser().parse_args(args)
- if len(args) > 0:
- raise cmdutil.UsageError
-
-
-def get_parser():
- parser = cmdutil.CmdOptionParser("be list [options]")
-# parser.add_option("-w", "--wishlist", action="store_true", dest="wishlist",
-# help="List bugs with 'wishlist' severity")
- return parser
-
-longhelp="""
-This is for the longwinded description
-"""
-
-def help():
- return get_parser().help_str() + longhelp
diff --git a/becommands/upgrade.py b/becommands/upgrade.py
index f5b12ef..7ed3630 100644
--- a/becommands/upgrade.py
+++ b/becommands/upgrade.py
@@ -18,6 +18,7 @@
import os.path
import errno
from libbe import bugdir, rcs, cmdutil
+__desc__ = __doc__
def execute(args):
options, args = get_parser().parse_args(args)
diff --git a/libbe/bug.py b/libbe/bug.py
index 430a333..a0054ca 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -16,9 +16,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
import os.path
+import shutil
import errno
import names
-import cmdutil
import mapfile
import time
import utility
@@ -116,7 +116,7 @@ class Bug(object):
def string(self, bugs=None, shortlist=False):
if bugs == None:
bugs = list(self.bugdir.list())
- short_name = cmdutil.unique_name(self, bugs)
+ short_name = names.unique_name(self, bugs)
if shortlist == False:
htime = utility.handy_time(self.time)
ftime = utility.time_to_str(self.time)
@@ -136,7 +136,7 @@ class Bug(object):
newinfo.append((k,v))
info = newinfo
longest_key_len = max([len(k) for k,v in info])
- infolines = [" %*s : %s\n" % (longest_key_len,k,v) for k,v in info]
+ infolines = [" %*s : %s\n" %(longest_key_len,k,v) for k,v in info]
return "".join(infolines) + "%s\n" % self.summary
else:
statuschar = self.status[0]
@@ -145,8 +145,11 @@ class Bug(object):
return "%s:%s: %s\n" % (short_name, chars, self.summary)
def __str__(self):
return self.string(shortlist=True)
- def get_path(self, file):
- return os.path.join(self.path, self.uuid, file)
+ def get_path(self, file=None):
+ if file == None:
+ return os.path.join(self.path, self.uuid)
+ else:
+ return os.path.join(self.path, self.uuid, file)
def _get_active(self):
return self.status in active_status_values
@@ -170,7 +173,11 @@ class Bug(object):
map["time"] = utility.time_to_str(self.time)
path = self.get_path("values")
mapfile.map_save(rcs_by_name(self.rcs_name), path, map)
-
+
+ def remove(self):
+ path = self.get_path()
+ shutil.rmtree(path)
+
def _get_rcs(self):
return rcs_by_name(self.rcs_name)
@@ -260,14 +267,14 @@ class Comment(object):
def save(self):
map_file = {"Date": utility.time_to_str(self.time)}
add_headers(self, map_file, ("From", "in_reply_to", "content_type"))
- if not os.path.exists(self.get_path(None)):
- self.bug.rcs.mkdir(self.get_path(None))
+ if not os.path.exists(self.get_path()):
+ self.bug.rcs.mkdir(self.get_path())
mapfile.map_save(self.bug.rcs, self.get_path("values"), map_file)
self.bug.rcs.set_file_contents(self.get_path("body"),
self.body.encode('utf-8'))
- def get_path(self, name):
+ def get_path(self, name=None):
my_dir = os.path.join(self.bug.get_path("comments"), self.uuid)
if name is None:
return my_dir
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index b5a93c7..ace2d81 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -23,24 +23,6 @@ from textwrap import TextWrapper
from StringIO import StringIO
import utility
-def unique_name(bug, bugs):
- """
- Generate short names from uuids. Picks the minimum number of
- characters (>=3) from the beginning of the uuid such that the
- short names are unique.
-
- Obviously, as the number of bugs in the database grows, these
- short names will cease to be unique. The complete uuid should be
- used for long term reference.
- """
- chars = 3
- for some_bug in bugs:
- if bug.uuid == some_bug.uuid:
- continue
- while (bug.uuid[:chars] == some_bug.uuid[:chars]):
- chars+=1
- return bug.uuid[:chars]
-
class UserError(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
@@ -94,9 +76,20 @@ def execute(cmd, args):
encoding = locale.getpreferredencoding() or 'ascii'
return get_command(cmd).execute([a.decode(encoding) for a in args])
-def help(cmd):
- return get_command(cmd).help()
-
+def help(cmd=None):
+ if cmd != None:
+ return get_command(cmd).help()
+ else:
+ cmdlist = []
+ for name, module in iter_commands():
+ cmdlist.append((name, module.__desc__))
+ longest_cmd_len = max([len(name) for name,desc in cmdlist])
+ ret = ["Bugs Everywhere - Distributed bug tracking\n",
+ "Supported commands"]
+ for name, desc in cmdlist:
+ numExtraSpaces = longest_cmd_len-len(name)
+ ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc))
+ return "\n".join(ret)
class GetHelp(Exception):
pass
@@ -205,15 +198,6 @@ def bug_tree(dir=None):
except bugdir.NoBugDir, e:
raise UserErrorWrap(e)
-def print_command_list():
- cmdlist = []
- print """Bugs Everywhere - Distributed bug tracking
-
-Supported commands"""
- for name, module in iter_commands():
- cmdlist.append((name, module.__doc__))
- for name, desc in cmdlist:
- print "be %s\n %s" % (name, desc)
def _test():
import doctest
diff --git a/libbe/names.py b/libbe/names.py
index d2e077a..c86063d 100644
--- a/libbe/names.py
+++ b/libbe/names.py
@@ -35,3 +35,21 @@ def creator():
return os.environ["LOGNAME"]
else:
return os.environ["USERNAME"]
+
+def unique_name(bug, bugs):
+ """
+ Generate short names from uuids. Picks the minimum number of
+ characters (>=3) from the beginning of the uuid such that the
+ short names are unique.
+
+ Obviously, as the number of bugs in the database grows, these
+ short names will cease to be unique. The complete uuid should be
+ used for long term reference.
+ """
+ chars = 3
+ for some_bug in bugs:
+ if bug.uuid == some_bug.uuid:
+ continue
+ while (bug.uuid[:chars] == some_bug.uuid[:chars]):
+ chars+=1
+ return bug.uuid[:chars]
diff --git a/libbe/plugin.py b/libbe/plugin.py
index 4016ca1..9254986 100644
--- a/libbe/plugin.py
+++ b/libbe/plugin.py
@@ -55,6 +55,7 @@ def get_plugin(prefix, name):
plugin_path = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))
if plugin_path not in sys.path:
sys.path.append(plugin_path)
+
def _test():
import doctest
doctest.testmod()