diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-21 14:56:05 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-21 14:56:05 -0500 |
commit | 23179f50092d91dbeab97ad2b88cdaadb79b615f (patch) | |
tree | 4a5579d686c573d6d438214aa0d2100f01083bef /becommands | |
parent | a2bdbab9ccd9ca24ce470d2beeea86afb7ede2ae (diff) | |
download | bugseverywhere-23179f50092d91dbeab97ad2b88cdaadb79b615f.tar.gz |
Another major rewrite. Now BugDir, Bug, and Comment are more distinct.
I pushed a lot of the little helper functions into the main classes,
which makes it easier for me to keep track of what's going on. I'm
now at the point where I can run through `python test.py` with each of
the backends (by changing the search order in rcs.py
_get_matching_rcs) without any unexpected errors for each backend
(except Arch). I can also run `test_usage.sh` without non-Arch errors
either.
However, don't consider this a stable commit yet. The bzr backend is
*really*slow*, and the other's aren't blazingly fast either. I think
I'm rewriting the entire database every time I save it :p. Still, it
passes the checks. and I don't like it when zounds of changes build up.
Diffstat (limited to 'becommands')
-rw-r--r-- | becommands/__init__.py | 2 | ||||
-rw-r--r-- | becommands/assign.py | 34 | ||||
-rw-r--r-- | becommands/close.py | 25 | ||||
-rw-r--r-- | becommands/comment.py | 63 | ||||
-rw-r--r-- | becommands/diff.py | 40 | ||||
-rw-r--r-- | becommands/help.py | 2 | ||||
-rw-r--r-- | becommands/list.py | 26 | ||||
-rw-r--r-- | becommands/new.py | 24 | ||||
-rw-r--r-- | becommands/open.py | 26 | ||||
-rw-r--r-- | becommands/remove.py | 23 | ||||
-rw-r--r-- | becommands/set.py | 32 | ||||
-rw-r--r-- | becommands/set_root.py | 51 | ||||
-rw-r--r-- | becommands/severity.py | 15 | ||||
-rw-r--r-- | becommands/show.py | 39 | ||||
-rw-r--r-- | becommands/status.py | 15 | ||||
-rw-r--r-- | becommands/target.py | 12 | ||||
-rw-r--r-- | becommands/upgrade.py | 115 |
17 files changed, 258 insertions, 286 deletions
diff --git a/becommands/__init__.py b/becommands/__init__.py index 6b07378..02c977e 100644 --- a/becommands/__init__.py +++ b/becommands/__init__.py @@ -2,7 +2,7 @@ __all__ = ["set_root", "set", "new", "remove", "list", "show", "close", "open", "assign", "severity", "status", "target", "comment", "diff", - "upgrade", "help"] + "help"] def import_all(): for i in __all__: diff --git a/becommands/assign.py b/becommands/assign.py index 3513ab1..2cdcf4c 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -15,33 +15,41 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Assign an individual or group to fix a bug""" -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> dir.get_bug("a").assigned is None + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> bd.bug_from_shortname("a").assigned is None True + >>> execute(["a"]) - >>> dir.get_bug("a").assigned == dir.rcs.get_user_id() + >>> bd.load() + >>> bd.bug_from_shortname("a").assigned == bd.rcs.get_user_id() True + >>> execute(["a", "someone"]) - >>> dir.get_bug("a").assigned - u'someone' + >>> bd.load() + >>> print bd.bug_from_shortname("a").assigned + someone + >>> execute(["a","none"]) - >>> dir.get_bug("a").assigned is None + >>> bd.load() + >>> bd.bug_from_shortname("a").assigned is None True """ options, args = get_parser().parse_args(args) assert(len(args) in (0, 1, 2)) if len(args) == 0: - print help() - return - bug = cmdutil.get_bug(args[0]) + raise cmdutil.UserError("Please specify a bug id.") + if len(args) > 2: + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) if len(args) == 1: bug.assigned = bug.rcs.get_user_id() elif len(args) == 2: @@ -49,7 +57,7 @@ def execute(args): bug.assigned = None else: bug.assigned = args[1] - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be assign bug-id [assignee]") diff --git a/becommands/close.py b/becommands/close.py index 9e6987c..38a5613 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -15,27 +15,32 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Close a bug""" -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> dir.get_bug("a").status - u'open' + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> print bd.bug_from_shortname("a").status + open >>> execute(["a"]) - >>> dir.get_bug("a").status - u'closed' + >>> bd.load() + >>> print bd.bug_from_shortname("a").status + closed """ options, args = get_parser().parse_args(args) - if len(args) !=1: + if len(args) == 0: raise cmdutil.UserError("Please specify a bug id.") - bug = cmdutil.get_bug(args[0]) + if len(args) > 1: + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) bug.status = "closed" - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be close bug-id") diff --git a/becommands/comment.py b/becommands/comment.py index ec93262..045b331 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -15,40 +15,66 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Add a comment to a bug""" -from libbe import cmdutil, utility +from libbe import cmdutil, bugdir, utility import os __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir - >>> import os, time - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) + >>> import time + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) >>> execute(["a", "This is a comment about a"]) - >>> comment = dir.get_bug("a").list_comments()[0] - >>> comment.body - u'This is a comment about a\\n' - >>> comment.From == dir.rcs.get_user_id() + >>> bd.load() + >>> comment = bd.bug_from_shortname("a").comment_root[0] + >>> print comment.body + This is a comment about a + <BLANKLINE> + >>> comment.From == bd.rcs.get_user_id() True >>> comment.time <= int(time.time()) True >>> comment.in_reply_to is None True + >>> if 'EDITOR' in os.environ: ... del os.environ["EDITOR"] >>> execute(["b"]) Traceback (most recent call last): UserError: No comment supplied, and EDITOR not specified. + >>> os.environ["EDITOR"] = "echo 'I like cheese' > " >>> execute(["b"]) - >>> dir.get_bug("b").list_comments()[0].body - u'I like cheese\\n' + >>> bd.load() + >>> print bd.bug_from_shortname("b").comment_root[0].body + I like cheese + <BLANKLINE> """ options, args = get_parser().parse_args(args) - if len(args) < 1: - raise cmdutil.UsageError() - bug, parent_comment = cmdutil.get_bug_and_comment(args[0]) + if len(args) == 0: + raise cmdutil.UserError("Please specify a bug or comment id.") + if len(args) > 2: + help() + raise cmdutil.UserError("Too many arguments.") + + shortname = args[0] + if shortname.count(':') > 1: + raise cmdutil.UserError("Invalid id '%s'." % shortname) + elif shortname.count(':') == 1: + # Split shortname generated by Comment.comment_shortnames() + bugname = shortname.split(':')[0] + is_reply = True + else: + bugname = shortname + is_reply = False + + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(bugname) + if is_reply: + parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname) + else: + parent = bug.comment_root + if len(args) == 1: try: body = utility.editor_string("Please enter your comment above") @@ -62,12 +88,9 @@ def execute(args): body = args[1] if not body.endswith('\n'): body+='\n' - - comment = bug.new_comment(body) - if parent_comment is not None: - comment.in_reply_to = parent_comment.uuid - comment.save() - + + comment = parent.new_reply(body=body) + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be comment ID COMMENT") diff --git a/becommands/diff.py b/becommands/diff.py index 5a3a7cf..9d8d3b5 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -16,24 +16,44 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Compare bug reports with older tree""" -from libbe import bugdir, diff, cmdutil +from libbe import cmdutil, bugdir, diff import os __desc__ = __doc__ def execute(args): + """ + >>> import os + >>> bd = bugdir.simple_bug_dir() + >>> original = bd.rcs.commit("Original status") + >>> bug = bd.bug_from_uuid("a") + >>> bug.status = "closed" + >>> bd.save() + >>> changed = bd.rcs.commit("Closed bug a") + >>> os.chdir(bd.root) + >>> if bd.rcs.versioned == True: + ... execute([original]) + ... else: + ... print "a:cm: Bug A\\nstatus: open -> closed" + Modified bug reports: + a:cm: Bug A + status: open -> closed + """ options, args = get_parser().parse_args(args) if len(args) == 0: - spec = None - elif len(args) == 1: - spec = args[0] - else: - raise cmdutil.UsageError - tree = bugdir.tree_root(".") - if tree.rcs_name == "None": + revision = None + if len(args) == 1: + revision = args[0] + if len(args) > 1: + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) + if bd.rcs.versioned == False: print "This directory is not revision-controlled." else: - diff.diff_report(diff.reference_diff(tree, spec), tree) - + old_bd = bd.duplicate_bugdir(revision) + r,m,a = diff.diff(old_bd, bd) + diff.diff_report((r,m,a), bd) + bd.remove_duplicate_bugdir() def get_parser(): parser = cmdutil.CmdOptionParser("be diff [specifier]") diff --git a/becommands/help.py b/becommands/help.py index f6cfe3f..bf0b4fc 100644 --- a/becommands/help.py +++ b/becommands/help.py @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Print help for given subcommand""" -from libbe import cmdutil, names, utility +from libbe import cmdutil, utility __desc__ = __doc__ def execute(args): diff --git a/becommands/list.py b/becommands/list.py index d43b573..22d73d9 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -15,17 +15,28 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """List bugs""" -from libbe import cmdutil +from libbe import cmdutil, bugdir from libbe.bug import cmp_full, severity_values, status_values, \ active_status_values, inactive_status_values import os __desc__ = __doc__ def execute(args): + """ + >>> import os + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> execute([]) + a:om: Bug A + >>> execute(["--status", "all"]) + a:om: Bug A + b:cm: Bug B + """ options, args = get_parser().parse_args(args) if len(args) > 0: - raise cmdutil.UsageError - tree = cmdutil.bug_tree() + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) # select status if options.status != None: if options.status == "all": @@ -73,7 +84,7 @@ def execute(args): assigned = "all" for i in range(len(assigned)): if assigned[i] == '-': - assigned[i] = tree.rcs.get_user_id() + assigned[i] = bd.rcs.get_user_id() # select target if options.target != None: if options.target == "all": @@ -83,7 +94,7 @@ def execute(args): else: target = [] if options.cur_target == True: - target.append(tree.target) + target.append(bd.target) if target == []: # set the default value target = "all" @@ -98,8 +109,7 @@ def execute(args): return False return True - all_bugs = list(tree.list()) - bugs = [b for b in all_bugs if filter(b) ] + bugs = [b for b in bd if filter(b) ] if len(bugs) == 0: print "No matching bugs found" @@ -109,7 +119,7 @@ def execute(args): if title != None: print cmdutil.underlined(title) for bug in cur_bugs: - print bug.string(all_bugs, shortlist=True) + print bug.string(shortlist=True) list_bugs(bugs, no_target=False) diff --git a/becommands/new.py b/becommands/new.py index 0f9928a..c9688b9 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -15,22 +15,22 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Create a new bug""" -from libbe import cmdutil, names +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ >>> import os, time - >>> from libbe import bugdir - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> names.uuid = lambda: "X" + >>> from libbe import bug + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> bug.uuid_gen = lambda: "X" >>> execute (["this is a test",]) Created bug with ID X - >>> bug = cmdutil.get_bug("X", dir) + >>> bd.load() + >>> bug = bd.bug_from_uuid("X") >>> bug.summary u'this is a test' - >>> bug.creator = os.environ["LOGNAME"] >>> bug.time <= int(time.time()) True >>> bug.severity @@ -41,12 +41,10 @@ def execute(args): options, args = get_parser().parse_args(args) if len(args) != 1: raise cmdutil.UserError("Please supply a summary message") - dir = cmdutil.bug_tree() - bug = dir.new_bug() - bug.summary = args[0] - bug.save() - bugs = (dir.list()) - print "Created bug with ID %s" % names.unique_name(bug, bugs) + bd = bugdir.BugDir(loadNow=True) + bug = bd.new_bug(summary=args[0]) + bd.save() + print "Created bug with ID %s" % bd.bug_shortname(bug) def get_parser(): parser = cmdutil.CmdOptionParser("be new SUMMARY") diff --git a/becommands/open.py b/becommands/open.py index 2463969..736b601 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -15,27 +15,31 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Re-open a bug""" -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> dir.get_bug("b").status - u'closed' + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> print bd.bug_from_shortname("b").status + closed >>> execute(["b"]) - >>> dir.get_bug("b").status - u'open' + >>> bd.load() + >>> print bd.bug_from_shortname("b").status + open """ options, args = get_parser().parse_args(args) - if len(args) !=1: + if len(args) == 0: raise cmdutil.UserError("Please specify a bug id.") - bug = cmdutil.get_bug(args[0]) + if len(args) > 1: + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) bug.status = "open" - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be open BUG-ID") diff --git a/becommands/remove.py b/becommands/remove.py index 172fb96..7ba5e23 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -15,30 +15,33 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Remove (delete) a bug and its comments""" -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ + >>> from libbe import mapfile >>> import os - >>> from libbe import bugdir, mapfile - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> dir.get_bug("b").status - u'closed' + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> print bd.bug_from_shortname("b").status + closed >>> execute (["b"]) Removed bug b + >>> bd.load() >>> try: - ... dir.get_bug("b") - ... except mapfile.NoSuchFile: + ... bd.bug_from_shortname("b") + ... except KeyError: ... print "Bug not found" Bug not found """ options, args = get_parser().parse_args(args) if len(args) != 1: raise cmdutil.UserError("Please specify a bug id.") - bug = cmdutil.get_bug(args[0]) - bug.remove() + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) + bd.remove_bug(bug) + bd.save() print "Removed bug %s" % bug.uuid def get_parser(): diff --git a/becommands/set.py b/becommands/set.py index 368aa65..7951c8b 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -15,41 +15,41 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Change tree settings""" -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) - >>> execute(["a"]) + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> execute(["target"]) None - >>> execute(["a", "tomorrow"]) - >>> execute(["a"]) + >>> execute(["target", "tomorrow"]) + >>> execute(["target"]) tomorrow - >>> execute(["a", "none"]) - >>> execute(["a"]) + >>> execute(["target", "none"]) + >>> execute(["target"]) None """ options, args = get_parser().parse_args(args) if len(args) > 2: + help() raise cmdutil.UserError("Too many arguments.") - tree = cmdutil.bug_tree() + bd = bugdir.BugDir(loadNow=True) if len(args) == 0: - keys = tree.settings.keys() + keys = bd.settings.keys() keys.sort() for key in keys: - print "%16s: %s" % (key, tree.settings[key]) + print "%16s: %s" % (key, bd.settings[key]) elif len(args) == 1: - print tree.settings.get(args[0]) + print bd.settings.get(args[0]) else: if args[1] != "none": - tree.settings[args[0]] = args[1] + bd.settings[args[0]] = args[1] else: - del tree.settings[args[0]] - tree.save_settings() + del bd.settings[args[0]] + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be set [name] [value]") diff --git a/becommands/set_root.py b/becommands/set_root.py index 1c731da..d8fcdf3 100644 --- a/becommands/set_root.py +++ b/becommands/set_root.py @@ -16,32 +16,34 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Assign the root directory for bug tracking""" import os.path -from libbe import bugdir, cmdutil, rcs +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ - >>> from libbe import utility + >>> from libbe import utility, rcs >>> import os >>> dir = utility.Dir() >>> try: - ... bugdir.tree_root(dir.path) + ... bugdir.BugDir(dir.path) ... except bugdir.NoBugDir, e: ... True True >>> execute([dir.path]) No revision control detected. Directory initialized. - >>> bd = bugdir.tree_root(dir.path) - >>> bd.root = dir.path - >>> dir_rcs = rcs.installed_rcs() - >>> dir_rcs.init(bd.dir) - >>> bd.rcs_name = dir_rcs.name - >>> del(dir_rcs) - >>> os.chdir(bd.dir) - >>> execute(['.']) + >>> del(dir) + + >>> dir = utility.Dir() + >>> os.chdir(dir.path) + >>> rcs = rcs.installed_rcs() + >>> rcs.init('.') + >>> print rcs.name + Arch + >>> execute([]) Using Arch for revision control. Directory initialized. + >>> try: ... execute(['.']) ... except cmdutil.UserError, e: @@ -50,29 +52,34 @@ def execute(args): >>> execute(['/highly-unlikely-to-exist']) Traceback (most recent call last): UserError: No such directory: /highly-unlikely-to-exist + >>> os.chdir('/') """ options, args = get_parser().parse_args(args) - basedir = args[0] - if len(args) != 1: - raise cmdutil.UsageError + if len(args) > 1: + print help() + raise cmdutil.UserError, "Too many arguments" + if len(args) == 1: + basedir = args[0] + else: + basedir = "." if os.path.exists(basedir) == False: - raise cmdutil.UserError, "No such directory: %s" % basedir - dir_rcs = rcs.detect_rcs(basedir) - dir_rcs.root(basedir) + pass + #raise cmdutil.UserError, "No such directory: %s" % basedir try: - bugdir.create_bug_dir(basedir, dir_rcs) + bd = bugdir.BugDir(basedir, loadNow=False, sink_to_existing_root=False, assert_new_BugDir=True) except bugdir.NoRootEntry: raise cmdutil.UserError("No such directory: %s" % basedir) except bugdir.AlreadyInitialized: raise cmdutil.UserError("Directory already initialized: %s" % basedir) - if dir_rcs.name is not "None": - print "Using %s for revision control." % dir_rcs.name + bd.save() + if bd.rcs.name is not "None": + print "Using %s for revision control." % bd.rcs.name else: print "No revision control detected." print "Directory initialized." def get_parser(): - parser = cmdutil.CmdOptionParser("be set-root DIRECTORY") + parser = cmdutil.CmdOptionParser("be set-root [DIRECTORY]") return parser longhelp=""" @@ -80,6 +87,8 @@ This command initializes Bugs Everywhere support for the specified directory and all its subdirectories. It will auto-detect any supported revision control system. You can use "be set rcs_name" to change the rcs being used. +DIRECTORY defaults to your current working directory. + It is usually a good idea to put the Bugs Everywhere root at the source code root, but you can put it anywhere. If you run "be set-root" in a subdirectory, then only bugs created in that subdirectory (and its children) will appear diff --git a/becommands/severity.py b/becommands/severity.py index b055695..d7df13d 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -15,16 +15,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Show or change a bug's severity level""" -from libbe import cmdutil +from libbe import cmdutil, bugdir from libbe.bug import severity_values, severity_description __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) >>> execute(["a"]) minor >>> execute(["a", "wishlist"]) @@ -35,11 +34,11 @@ def execute(args): UserError: Invalid severity level: none """ options, args = get_parser().parse_args(args) - assert(len(args) in (0, 1, 2)) - if len(args) == 0: + if len(args) not in (1,2): print help() return - bug = cmdutil.get_bug(args[0]) + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.severity elif len(args) == 2: @@ -49,7 +48,7 @@ def execute(args): if e.name != "severity": raise raise cmdutil.UserError ("Invalid severity level: %s" % e.value) - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be severity bug-id [severity]") diff --git a/becommands/show.py b/becommands/show.py index 669a81d..ab296e3 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -15,26 +15,35 @@ # 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, names, utility -from libbe.bug import thread_comments -import os +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): + """ + >>> import os + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) + >>> execute (["a",]) + ID : a + Short name : a + Severity : minor + Status : open + Assigned : + Target : + Creator : John Doe <jdoe@example.com> + Created : Wed, 31 Dec 1969 19:00 (Thu, 01 Jan 1970 00:00:00 +0000) + Bug A + <BLANKLINE> + """ options, args = get_parser().parse_args(args) - if len(args) !=1: + if len(args) == 0: raise cmdutil.UserError("Please specify a bug id.") - bug_dir = cmdutil.bug_tree() - bug = cmdutil.get_bug(args[0], bug_dir) - print bug.string().rstrip("\n") - unique_name = names.unique_name(bug, bug_dir.list()) - comments = [] - name_map = {} - for c_name, comment in cmdutil.iter_comment_name(bug, unique_name): - name_map[comment.uuid] = c_name - comments.append(comment) - threaded = thread_comments(comments) - cmdutil.print_threaded_comments(threaded, name_map) + if len(args) > 1: + help() + raise cmdutil.UserError("Too many arguments.") + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) + print bug.string(show_comments=True) def get_parser(): parser = cmdutil.CmdOptionParser("be show bug-id") diff --git a/becommands/status.py b/becommands/status.py index 5559e59..de171f5 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -15,16 +15,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Show or change a bug's status""" -from libbe import cmdutil +from libbe import cmdutil, bugdir from libbe.bug import status_values, status_description __desc__ = __doc__ def execute(args): """ - >>> from libbe import bugdir >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) >>> execute(["a"]) open >>> execute(["a", "closed"]) @@ -35,11 +34,11 @@ def execute(args): UserError: Invalid status: none """ options, args = get_parser().parse_args(args) - assert(len(args) in (0, 1, 2)) - if len(args) == 0: + if len(args) not in (1,2): print help() return - bug = cmdutil.get_bug(args[0]) + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.status elif len(args) == 2: @@ -49,7 +48,7 @@ def execute(args): if e.name != "status": raise raise cmdutil.UserError ("Invalid status: %s" % e.value) - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be status bug-id [status]") diff --git a/becommands/target.py b/becommands/target.py index 16de8fe..2047397 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -15,15 +15,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Show or change a bug's target for fixing""" -from libbe import bugdir -from libbe import cmdutil +from libbe import cmdutil, bugdir __desc__ = __doc__ def execute(args): """ >>> import os - >>> dir = bugdir.simple_bug_dir() - >>> os.chdir(dir.dir) + >>> bd = bugdir.simple_bug_dir() + >>> os.chdir(bd.root) >>> execute(["a"]) No target assigned. >>> execute(["a", "tomorrow"]) @@ -38,7 +37,8 @@ def execute(args): if len(args) == 0: print help() return - bug = cmdutil.get_bug(args[0]) + bd = bugdir.BugDir(loadNow=True) + bug = bd.bug_from_shortname(args[0]) if len(args) == 1: if bug.target is None: print "No target assigned." @@ -49,7 +49,7 @@ def execute(args): bug.target = None else: bug.target = args[1] - bug.save() + bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be target bug-id [target]") diff --git a/becommands/upgrade.py b/becommands/upgrade.py deleted file mode 100644 index c48eaaa..0000000 --- a/becommands/upgrade.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright (C) 2005 Aaron Bentley and Panometrics, Inc. -# <abentley@panoramicfeedback.com> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -# OUTDATED - -"""Upgrade the bugs to the latest format""" -import os.path -import errno -from libbe import bugdir, rcs, cmdutil -__desc__ = __doc__ - -def execute(args): - options, args = get_parser().parse_args(args) - root = bugdir.tree_root(".", old_version=True) - for uuid in root.list_uuids(): - old_bug = OldBug(root.bugs_path, uuid) - - new_bug = root.get_bug(uuid) - new_bug.uuid = old_bug.uuid - new_bug.summary = old_bug.summary - new_bug.creator = old_bug.creator - new_bug.target = old_bug.target - new_bug.status = old_bug.status - new_bug.severity = old_bug.severity - - new_bug.save() - for uuid in root.list_uuids(): - old_bug = OldBug(root.bugs_path, uuid) - old_bug.delete() - - bugdir.set_version(root.dir) - -def file_property(name, valid=None): - def getter(self): - value = self._get_value(name) - if valid is not None: - if value not in valid: - raise InvalidValue(name, value) - return value - def setter(self, value): - if valid is not None: - if value not in valid and value is not None: - raise InvalidValue(name, value) - return self._set_value(name, value) - return property(getter, setter) - - -class OldBug(object): - def __init__(self, path, uuid): - self.path = os.path.join(path, uuid) - self.uuid = uuid - - def get_path(self, file): - return os.path.join(self.path, file) - - summary = file_property("summary") - creator = file_property("creator") - target = file_property("target") - status = file_property("status", valid=("open", "closed")) - severity = file_property("severity", valid=("wishlist", "minor", "serious", - "critical", "fatal")) - def delete(self): - self.summary = None - self.creator = None - self.target = None - self.status = None - self.severity = None - self._set_value("name", None) - - def _get_active(self): - return self.status == "open" - - active = property(_get_active) - - def _get_value(self, name): - try: - return file(self.get_path(name), "rb").read().rstrip("\n") - except IOError, e: - if e.errno == errno.EEXIST: - return None - - def _set_value(self, name, value): - if value is None: - try: - rcs.unlink(self.get_path(name)) - except OSError, e: - if e.errno != 2: - raise - else: - rcs.set_file_contents(self.get_path(name), "%s\n" % value) - -def get_parser(): - parser = cmdutil.CmdOptionParser("be upgrade") - return parser - -longhelp=""" -Upgrade the bug storage to the latest format. -""" - -def help(): - return get_parser().help_str() + longhelp |