From: Aaron Bentley Date: Fri, 18 Mar 2005 15:14:25 +0000 (+0000) Subject: Used cmdutil tree_root wrapper to avoid tracebacks on wrong tree X-Git-Tag: 1.0.0~342 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d7d616e4f8b885f55f8052e5eb22f3cec7ddbee4;p=be.git Used cmdutil tree_root wrapper to avoid tracebacks on wrong tree --- diff --git a/becommands/list.py b/becommands/list.py index e89195b..5bd54a2 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -11,7 +11,7 @@ def execute(args): if bug.severity not in severity: return False return True - all_bugs = list(bugdir.tree_root(os.getcwd()).list()) + all_bugs = list(cmdutil.bug_tree().list()) bugs = [b for b in all_bugs if filter(b) ] if len(bugs) == 0: print "No matching bugs found" diff --git a/becommands/new.py b/becommands/new.py index e36bc84..7c3a952 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -3,7 +3,7 @@ from libbe import bugdir, cmdutil, names def execute(args): if len(args) != 1: raise cmdutil.UserError("Please supply a summary message") - dir = bugdir.tree_root(".") + dir = cmdutil.bug_tree() bug = dir.new_bug() bug.creator = names.creator() bug.severity = "minor" diff --git a/becommands/show.py b/becommands/show.py index cd74eae..3d1c9ed 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -3,7 +3,7 @@ from libbe import bugdir, cmdutil import os def execute(args): - bug_dir = bugdir.tree_root(os.getcwd()) + bug_dir = cmdutil.bug_tree() if len(args) !=1: raise cmdutil.UserError("Please specify a bug id.") print cmdutil.bug_summary(cmdutil.get_bug(args[0], bug_dir), diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index ab0e8be..b550eb0 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -1,5 +1,7 @@ import bugdir import plugin +import os + def unique_name(bug, bugs): chars = 1 for some_bug in bugs: @@ -90,6 +92,27 @@ def underlined(instring): return "%s\n%s" % (instring, "="*len(instring)) + +def bug_tree(dir=None): + """Retrieve the bug tree specified by the user. If no directory is + specified, the current working directory is used. + + :param dir: The directory to search for the bug tree in. + + >>> bug_tree() is not None + True + >>> bug_tree("/") + Traceback (most recent call last): + UserErrorWrap: The directory "/" has no bug directory. + """ + if dir is None: + dir = os.getcwd() + try: + return bugdir.tree_root(dir) + except bugdir.NoBugDir, e: + raise UserErrorWrap(e) + + def _test(): import doctest import sys