aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--becommands/assign.py2
-rw-r--r--becommands/close.py2
-rw-r--r--becommands/comment.py6
-rw-r--r--becommands/depend.py4
-rw-r--r--becommands/merge.py4
-rw-r--r--becommands/open.py2
-rw-r--r--becommands/remove.py4
-rw-r--r--becommands/severity.py2
-rw-r--r--becommands/show.py2
-rw-r--r--becommands/status.py2
-rw-r--r--becommands/tag.py2
-rw-r--r--becommands/target.py2
-rw-r--r--libbe/bugdir.py8
-rw-r--r--libbe/cmdutil.py9
14 files changed, 33 insertions, 18 deletions
diff --git a/becommands/assign.py b/becommands/assign.py
index 536bca6..81aac2b 100644
--- a/becommands/assign.py
+++ b/becommands/assign.py
@@ -54,7 +54,7 @@ def execute(args, test=False):
help()
raise cmdutil.UsageError("Too many arguments.")
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 1:
bug.assigned = bd.user_id
elif len(args) == 2:
diff --git a/becommands/close.py b/becommands/close.py
index 0ba8f50..327817a 100644
--- a/becommands/close.py
+++ b/becommands/close.py
@@ -42,7 +42,7 @@ def execute(args, test=False):
if len(args) > 1:
raise cmdutil.UsageError("Too many arguments.")
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
bug.status = "closed"
bd.save()
diff --git a/becommands/comment.py b/becommands/comment.py
index 55b5913..4221ef8 100644
--- a/becommands/comment.py
+++ b/becommands/comment.py
@@ -32,7 +32,7 @@ def execute(args, test=False):
>>> os.chdir(bd.root)
>>> execute(["a", "This is a comment about a"], test=True)
>>> bd._clear_bugs()
- >>> bug = bd.bug_from_shortname("a")
+ >>> bug = cmdutil.bug_from_shortname(bd, "a")
>>> bug.load_comments(load_full=False)
>>> comment = bug.comment_root[0]
>>> print comment.body
@@ -54,7 +54,7 @@ def execute(args, test=False):
>>> os.environ["EDITOR"] = "echo 'I like cheese' > "
>>> execute(["b"], test=True)
>>> bd._clear_bugs()
- >>> bug = bd.bug_from_shortname("b")
+ >>> bug = cmdutil.bug_from_shortname(bd, "b")
>>> bug.load_comments(load_full=False)
>>> comment = bug.comment_root[0]
>>> print comment.body
@@ -82,7 +82,7 @@ def execute(args, test=False):
bd = bugdir.BugDir(from_disk=True,
manipulate_encodings=not test)
- bug = bd.bug_from_shortname(bugname)
+ bug = cmdutil.bug_from_shortname(bd, bugname)
bug.load_comments(load_full=False)
if is_reply:
parent = bug.comment_root.comment_from_shortname(shortname,
diff --git a/becommands/depend.py b/becommands/depend.py
index 4a23b0f..d22ed2d 100644
--- a/becommands/depend.py
+++ b/becommands/depend.py
@@ -48,9 +48,9 @@ def execute(args, test=False):
raise cmdutil.UsageError("Too many arguments.")
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bugA = bd.bug_from_shortname(args[0])
+ bugA = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 2:
- bugB = bd.bug_from_shortname(args[1])
+ bugB = cmdutil.bug_from_shortname(bd, args[1])
estrs = bugA.extra_strings
depend_string = "BLOCKED-BY:%s" % bugB.uuid
if options.remove == True:
diff --git a/becommands/merge.py b/becommands/merge.py
index 4aaefa8..633067c 100644
--- a/becommands/merge.py
+++ b/becommands/merge.py
@@ -134,9 +134,9 @@ def execute(args, test=False):
raise cmdutil.UsageError("Too many arguments.")
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bugA = bd.bug_from_shortname(args[0])
+ bugA = cmdutil.bug_from_shortname(bd, args[0])
bugA.load_comments()
- bugB = bd.bug_from_shortname(args[1])
+ bugB = cmdutil.bug_from_shortname(bd, args[1])
bugB.load_comments()
mergeA = bugA.new_comment("Merged from bug %s" % bugB.uuid)
newCommTree = copy.deepcopy(bugB.comment_root)
diff --git a/becommands/open.py b/becommands/open.py
index 2ef5f43..242ceb2 100644
--- a/becommands/open.py
+++ b/becommands/open.py
@@ -41,7 +41,7 @@ def execute(args, test=False):
if len(args) > 1:
raise cmdutil.UsageError, "Too many arguments."
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
bug.status = "open"
def get_parser():
diff --git a/becommands/remove.py b/becommands/remove.py
index d79a7be..7193119 100644
--- a/becommands/remove.py
+++ b/becommands/remove.py
@@ -30,7 +30,7 @@ def execute(args, test=False):
>>> bd._clear_bugs()
>>> try:
... bd.bug_from_shortname("b")
- ... except KeyError:
+ ... except bugdir.NoBugMatches:
... print "Bug not found"
Bug not found
"""
@@ -41,7 +41,7 @@ def execute(args, test=False):
if len(args) != 1:
raise cmdutil.UsageError, "Please specify a bug id."
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
bd.remove_bug(bug)
print "Removed bug %s" % bug.uuid
diff --git a/becommands/severity.py b/becommands/severity.py
index 65467e3..74f241d 100644
--- a/becommands/severity.py
+++ b/becommands/severity.py
@@ -40,7 +40,7 @@ def execute(args, test=False):
if len(args) not in (1,2):
raise cmdutil.UsageError
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 1:
print bug.severity
elif len(args) == 2:
diff --git a/becommands/show.py b/becommands/show.py
index e43cfb9..6c942fe 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -72,7 +72,7 @@ def execute(args, test=False):
is_comment = False
if is_comment == True and options.comments == False:
continue
- bug = bd.bug_from_shortname(bugname)
+ bug = cmdutil.bug_from_shortname(bd, bugname)
if is_comment == False:
if options.XML:
print bug.xml(show_comments=options.comments)
diff --git a/becommands/status.py b/becommands/status.py
index edc948d..bff0626 100644
--- a/becommands/status.py
+++ b/becommands/status.py
@@ -37,7 +37,7 @@ def execute(args, test=False):
if len(args) not in (1,2):
raise cmdutil.UsageError
bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 1:
print bug.status
else:
diff --git a/becommands/tag.py b/becommands/tag.py
index 216ffbc..08247cd 100644
--- a/becommands/tag.py
+++ b/becommands/tag.py
@@ -92,7 +92,7 @@ def execute(args, test=False):
if len(tags) > 0:
print '\n'.join(tags)
return
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 2:
given_tag = args[1]
estrs = bug.extra_strings
diff --git a/becommands/target.py b/becommands/target.py
index 527b16a..ec10ed6 100644
--- a/becommands/target.py
+++ b/becommands/target.py
@@ -53,7 +53,7 @@ def execute(args, test=False):
if target and isinstance(target,str):
print target
return
- bug = bd.bug_from_shortname(args[0])
+ bug = cmdutil.bug_from_shortname(bd, args[0])
if len(args) == 1:
if bug.target is None:
print "No target assigned."
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index 6e020ee..f7345fd 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -62,6 +62,12 @@ class MultipleBugMatches(ValueError):
self.shortname = shortname
self.matches = matches
+class NoBugMatches(KeyError):
+ def __init__(self, shortname):
+ msg = "No bug matches %s" % shortname
+ KeyError.__init__(self, msg)
+ self.shortname = shortname
+
TREE_VERSION_STRING = "Bugs Everywhere Tree 1 0\n"
@@ -530,7 +536,7 @@ settings easy. Don't set this attribute. Set .rcs instead, and
raise MultipleBugMatches(shortname, matches)
if len(matches) == 1:
return self.bug_from_uuid(matches[0])
- raise KeyError("No bug matches %s" % shortname)
+ raise NoBugMatches(shortname)
def bug_from_uuid(self, uuid):
if not self.has_bug(uuid):
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 853a75a..35d2f9e 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -206,6 +206,15 @@ def underlined(instring):
return "%s\n%s" % (instring, "="*len(instring))
+def bug_from_shortname(bugdir, shortname):
+ """
+ Exception translation for the command-line interface.
+ """
+ try:
+ bug = bugdir.bug_from_shortname(shortname)
+ except (bugdir.MultipleBugMatches, bugdir.NoBugMatches), e:
+ raise UserError(e.message)
+ return bug
def _test():
import doctest