aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
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 /libbe
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.
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bug.py25
-rw-r--r--libbe/cmdutil.py44
-rw-r--r--libbe/names.py18
-rw-r--r--libbe/plugin.py1
4 files changed, 49 insertions, 39 deletions
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()