diff options
Diffstat (limited to 'becommands')
-rw-r--r-- | becommands/assign.py | 25 | ||||
-rw-r--r-- | becommands/close.py | 16 | ||||
-rw-r--r-- | becommands/comment.py | 74 | ||||
-rw-r--r-- | becommands/diff.py | 49 | ||||
-rw-r--r-- | becommands/help.py | 29 | ||||
-rw-r--r-- | becommands/list.py | 88 | ||||
-rw-r--r-- | becommands/merge.py | 164 | ||||
-rw-r--r-- | becommands/new.py | 36 | ||||
-rw-r--r-- | becommands/open.py | 16 | ||||
-rw-r--r-- | becommands/remove.py | 13 | ||||
-rw-r--r-- | becommands/set.py | 64 | ||||
-rw-r--r-- | becommands/set_root.py | 23 | ||||
-rw-r--r-- | becommands/severity.py | 70 | ||||
-rw-r--r-- | becommands/show.py | 29 | ||||
-rw-r--r-- | becommands/status.py | 74 | ||||
-rw-r--r-- | becommands/target.py | 32 |
16 files changed, 601 insertions, 201 deletions
diff --git a/becommands/assign.py b/becommands/assign.py index cb732b3..2f9ff21 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -15,40 +15,43 @@ # 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, bugdir +from libbe import cmdutil, bugdir, settings_object __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> bd.bug_from_shortname("a").assigned is None + >>> bd.bug_from_shortname("a").assigned is settings_object.EMPTY True - >>> execute(["a"]) + >>> execute(["a"], test=True) >>> bd._clear_bugs() >>> bd.bug_from_shortname("a").assigned == bd.user_id True - >>> execute(["a", "someone"]) + >>> execute(["a", "someone"], test=True) >>> bd._clear_bugs() >>> print bd.bug_from_shortname("a").assigned someone - >>> execute(["a","none"]) + >>> execute(["a","none"], test=True) >>> bd._clear_bugs() - >>> bd.bug_from_shortname("a").assigned is None + >>> bd.bug_from_shortname("a").assigned is settings_object.EMPTY True """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) assert(len(args) in (0, 1, 2)) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug id.") + raise cmdutil.UsageError("Please specify a bug id.") if len(args) > 2: help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError("Too many arguments.") + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: bug.assigned = bd.user_id diff --git a/becommands/close.py b/becommands/close.py index 8d2ccdb..d8826b0 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -18,7 +18,7 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> from libbe import bugdir >>> import os @@ -26,18 +26,20 @@ def execute(args): >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("a").status open - >>> execute(["a"]) + >>> execute(["a"], test=True) >>> bd._clear_bugs() >>> print bd.bug_from_shortname("a").status closed """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug id.") + raise cmdutil.UsageError("Please specify a bug id.") if len(args) > 1: - help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError("Too many arguments.") + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(args[0]) bug.status = "closed" bd.save() diff --git a/becommands/comment.py b/becommands/comment.py index 172f818..b15a06e 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -15,19 +15,19 @@ # 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, bugdir, utility +from libbe import cmdutil, bugdir, settings_object, editor import os __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import time >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["a", "This is a comment about a"]) + >>> execute(["a", "This is a comment about a"], test=True) >>> bd._clear_bugs() >>> bug = bd.bug_from_shortname("a") - >>> bug.load_comments() + >>> bug.load_comments(load_full=False) >>> comment = bug.comment_root[0] >>> print comment.body This is a comment about a @@ -36,31 +36,32 @@ def execute(args): True >>> comment.time <= int(time.time()) True - >>> comment.in_reply_to is None + >>> comment.in_reply_to is settings_object.EMPTY True >>> if 'EDITOR' in os.environ: ... del os.environ["EDITOR"] - >>> execute(["b"]) + >>> execute(["b"], test=True) Traceback (most recent call last): UserError: No comment supplied, and EDITOR not specified. >>> os.environ["EDITOR"] = "echo 'I like cheese' > " - >>> execute(["b"]) + >>> execute(["b"], test=True) >>> bd._clear_bugs() >>> bug = bd.bug_from_shortname("b") - >>> bug.load_comments() + >>> bug.load_comments(load_full=False) >>> comment = bug.comment_root[0] >>> print comment.body I like cheese <BLANKLINE> """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug or comment id.") + raise cmdutil.UsageError("Please specify a bug or comment id.") if len(args) > 2: - help() - raise cmdutil.UserError("Too many arguments.") + raise cmdutil.UsageError("Too many arguments.") shortname = args[0] if shortname.count(':') > 1: @@ -73,20 +74,20 @@ def execute(args): bugname = shortname is_reply = False - bd = bugdir.BugDir(from_disk=True) + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(bugname) - bug.load_comments() + bug.load_comments(load_full=False) if is_reply: - parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname) + 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") - except utility.CantFindEditor: - raise cmdutil.UserError( - "No comment supplied, and EDITOR not specified.") + body = editor.editor_string("Please enter your comment above") + except editor.CantFindEditor, e: + raise cmdutil.UserError, "No comment supplied, and EDITOR not specified." if body is None: raise cmdutil.UserError("No comment entered.") body = body.decode('utf-8') @@ -107,8 +108,41 @@ To add a comment to a bug, use the bug ID as the argument. To reply to another comment, specify the comment name (as shown in "be show" output). $EDITOR is used to launch an editor. If unspecified, no comment will be -created.) +created. """ def help(): return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option,value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + for pos,value in enumerate(args): + if value == "--complete": + if pos == 0: # fist positional argument is a bug or comment id + if len(args) >= 2: + partial = args[1].split(':')[0] # take only bugid portion + else: + partial = "" + ids = [] + try: + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=False) + bugs = [] + for uuid in bd.list_uuids(): + if uuid.startswith(partial): + bug = bd.bug_from_uuid(uuid) + if bug.active == True: + bugs.append(bug) + for bug in bugs: + shortname = bd.bug_shortname(bug) + ids.append(shortname) + bug.load_comments(load_full=False) + for id,comment in bug.comment_shortnames(shortname): + ids.append(id) + except bugdir.NoBugDir: + pass + raise cmdutil.GetCompletions(ids) + raise cmdutil.GetCompletions() diff --git a/becommands/diff.py b/becommands/diff.py index 77194ff..c090fa8 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -20,7 +20,7 @@ from libbe import cmdutil, bugdir, diff import os __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() @@ -31,7 +31,7 @@ def execute(args): >>> changed = bd.rcs.commit("Closed bug a") >>> os.chdir(bd.root) >>> if bd.rcs.versioned == True: - ... execute([original]) + ... execute([original], test=True) ... else: ... print "a:cm: Bug A\\nstatus: open -> closed\\n" Modified bug reports: @@ -39,25 +39,52 @@ def execute(args): status: open -> closed <BLANKLINE> """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser) if len(args) == 0: revision = None if len(args) == 1: revision = args[0] if len(args) > 1: - help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError("Too many arguments.") + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) if bd.rcs.versioned == False: print "This directory is not revision-controlled." else: old_bd = bd.duplicate_bugdir(revision) r,m,a = diff.diff(old_bd, bd) - diff.diff_report((r,m,a), bd) + + optbugs = [] + if options.all == True: + options.new = options.modified = options.removed = True + if options.new == True: + optbugs.extend(a) + if options.modified == True: + optbugs.extend([new for old,new in m]) + if options.removed == True: + optbugs.extend(r) + if len(optbugs) > 0: + for bug in optbugs: + print bug.uuid + else : + print diff.diff_report((r,m,a), bd).encode(bd.encoding) bd.remove_duplicate_bugdir() def get_parser(): - parser = cmdutil.CmdOptionParser("be diff [SPECIFIER]") + parser = cmdutil.CmdOptionParser("be diff [options] REVISION") + # boolean options + bools = (("n", "new", "Print UUIDS for new bugs"), + ("m", "modified", "Print UUIDS for modified bugs"), + ("r", "removed", "Print UUIDS for removed bugs"), + ("a", "all", "Print UUIDS for all changed bugs")) + for s in bools: + attr = s[1].replace('-','_') + short = "-%c" % s[0] + long = "--%s" % s[1] + help = s[2] + parser.add_option(short, long, action="store_true", + dest=attr, help=help) return parser longhelp=""" @@ -65,7 +92,11 @@ Uses the RCS to compare the current tree with a previous tree, and prints a pretty report. If specifier is given, it is a specifier for the particular previous tree to use. Specifiers are specific to their RCS. -For Arch: a fully-qualified revision name +For Arch your specifier must be a fully-qualified revision name. + +Besides the standard summary output, you can use the options to output +UUIDS for the different categories. This output can be used as the +input to 'be show' to get and understanding of the current status. """ def help(): diff --git a/becommands/help.py b/becommands/help.py index bf0b4fc..7e0209d 100644 --- a/becommands/help.py +++ b/becommands/help.py @@ -21,20 +21,28 @@ __desc__ = __doc__ def execute(args): """ Print help of specified command. + >>> execute(["help"]) + Usage: be help [COMMAND] + <BLANKLINE> + Options: + -h, --help Print a help message + --complete Print a list of available completions + <BLANKLINE> + Print help for specified command or list of all commands. + <BLANKLINE> """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) > 1: - raise cmdutil.UserError("Too many arguments.") + raise cmdutil.UsageError("Too many arguments.") if len(args) == 0: print cmdutil.help() else: try: print cmdutil.help(args[0]) except AttributeError: - print "No help available" - - return - + print "No help available" def get_parser(): parser = cmdutil.CmdOptionParser("be help [COMMAND]") @@ -46,3 +54,12 @@ Print help for specified command or list of all commands. def help(): return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option, value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + if "--complete" in args: + cmds = [command for command,module in cmdutil.iter_commands()] + raise cmdutil.GetCompletions(cmds) diff --git a/becommands/list.py b/becommands/list.py index 63e1cd6..8c69eaa 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -15,39 +15,39 @@ # 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, bugdir -from libbe.bug import cmp_full, severity_values, status_values, \ - active_status_values, inactive_status_values +from libbe import cmdutil, bugdir, bug import os __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute([]) + >>> execute([], test=True) a:om: Bug A - >>> execute(["--status", "all"]) + >>> execute(["--status", "all"], test=True) a:om: Bug A b:cm: Bug B """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) > 0: - help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError("Too many arguments.") + + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bd.load_all_bugs() # select status if options.status != None: if options.status == "all": - status = status_values + status = bug.status_values else: status = options.status.split(',') else: status = [] if options.active == True: - status.extend(list(active_status_values)) + status.extend(list(bug.active_status_values)) if options.unconfirmed == True: status.append("unconfirmed") if options.open == True: @@ -55,11 +55,11 @@ def execute(args): if options.test == True: status.append("test") if status == []: # set the default value - status = active_status_values + status = bug.active_status_values # select severity if options.severity != None: if options.severity == "all": - severity = severity_values + severity = bug.severity_values else: severity = options.severity.split(',') else: @@ -67,10 +67,10 @@ def execute(args): if options.wishlist == True: severity.extend("wishlist") if options.important == True: - serious = severity_values.index("serious") - severity.append(list(severity_values[serious:])) + serious = bug.severity_values.index("serious") + severity.append(list(bug.severity_values[serious:])) if severity == []: # set the default value - severity = severity_values + severity = bug.severity_values # select assigned if options.assigned != None: if options.assigned == "all": @@ -114,15 +114,18 @@ def execute(args): if len(bugs) == 0: print "No matching bugs found" - def list_bugs(cur_bugs, title=None, no_target=False): - cur_bugs.sort(cmp_full) + def list_bugs(cur_bugs, title=None, just_uuids=False): + cur_bugs.sort(bug.cmp_full) if len(cur_bugs) > 0: if title != None: print cmdutil.underlined(title) - for bug in cur_bugs: - print bug.string(shortlist=True) + for bg in cur_bugs: + if just_uuids: + print bg.uuid + else: + print bg.string(shortlist=True) - list_bugs(bugs, no_target=False) + list_bugs(bugs, just_uuids=options.uuids) def get_parser(): parser = cmdutil.CmdOptionParser("be list [options]") @@ -134,11 +137,12 @@ def get_parser(): help="List options matching ASSIGNED", default=None) parser.add_option("-t", "--target", metavar="TARGET", dest="target", help="List options matching TARGET", default=None) - # boolean shortucts. All of these are special cases of long forms - bools = (("w", "wishlist", "List bugs with 'wishlist' severity"), + # boolean options. All but uuids are special cases of long forms + bools = (("u", "uuids", "Only print the bug UUIDS"), + ("w", "wishlist", "List bugs with 'wishlist' severity"), ("i", "important", "List bugs with >= 'serious' severity"), ("A", "active", "List all active bugs"), - ("u", "unconfirmed", "List unconfirmed bugs"), + ("U", "unconfirmed", "List unconfirmed bugs"), ("o", "open", "List open bugs"), ("T", "test", "List bugs in testing"), ("m", "mine", "List bugs assigned to you"), @@ -152,9 +156,20 @@ def get_parser(): dest=attr, help=help) return parser -longhelp=""" -This command lists bugs. There are several criteria that you can -search by: + +def help(): + longhelp=""" +This command lists bugs. Normally it prints a short string like + 576:om: Allow attachments +Where + 576 the bug id + o the bug status is 'open' (first letter) + m the bug severity is 'minor' (first letter) + Allo... the bug summary string + +You can optionally (-u) print only the bug ids. + +There are several criteria that you can filter by: * status * severity * assigned (who the bug is assigned to) @@ -174,8 +189,17 @@ target In addition, there are some shortcut options that set boolean flags. The boolean options are ignored if the matching string option is used. -""" % (','.join(status_values), - ','.join(severity_values)) - -def help(): +""" % (','.join(bug.status_values), + ','.join(bug.severity_values)) return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option, value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + if option == "status": + raise cmdutil.GetCompletions(bug.status_values) + elif option == "severity": + raise cmdutil.GetCompletions(bug.severity_values) + raise cmdutil.GetCompletions() + if "--complete" in args: + raise cmdutil.GetCompletions() # no positional arguments for list diff --git a/becommands/merge.py b/becommands/merge.py new file mode 100644 index 0000000..927bb63 --- /dev/null +++ b/becommands/merge.py @@ -0,0 +1,164 @@ +# 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 +"""Merge duplicate bugs""" +from libbe import cmdutil, bugdir +import os, copy +__desc__ = __doc__ + +def execute(args, test=False): + """ + >>> from libbe import utility + >>> bd = bugdir.simple_bug_dir() + >>> a = bd.bug_from_shortname("a") + >>> a.comment_root.time = 0 + >>> dummy = a.new_comment("Testing") + >>> dummy.time = 1 + >>> dummy = dummy.new_reply("Testing...") + >>> dummy.time = 2 + >>> b = bd.bug_from_shortname("b") + >>> b.status = "open" + >>> b.comment_root.time = 0 + >>> dummy = b.new_comment("1 2") + >>> dummy.time = 1 + >>> dummy = dummy.new_reply("1 2 3 4") + >>> dummy.time = 2 + >>> bd.save() + >>> os.chdir(bd.root) + >>> execute(["a", "b"], test=True) + Merging bugs a and b + >>> bd._clear_bugs() + >>> a = bd.bug_from_shortname("a") + >>> a.load_comments() + >>> mergeA = a.comment_from_shortname(":3") + >>> mergeA.time = 3 + >>> print a.string(show_comments=True) + ID : a + Short name : a + Severity : minor + Status : open + Assigned : + Target : + Reporter : + Creator : John Doe <jdoe@example.com> + Created : Wed, 31 Dec 1969 19:00 (Thu, 01 Jan 1970 00:00:00 +0000) + Bug A + --------- Comment --------- + Name: a:1 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:01 +0000 + <BLANKLINE> + Testing + --------- Comment --------- + Name: a:2 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:02 +0000 + <BLANKLINE> + Testing... + --------- Comment --------- + Name: a:3 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:03 +0000 + <BLANKLINE> + Merged from bug b + --------- Comment --------- + Name: a:4 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:01 +0000 + <BLANKLINE> + 1 2 + --------- Comment --------- + Name: a:5 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:02 +0000 + <BLANKLINE> + 1 2 3 4 + >>> b = bd.bug_from_shortname("b") + >>> b.load_comments() + >>> mergeB = b.comment_from_shortname(":3") + >>> mergeB.time = 3 + >>> print b.string(show_comments=True) + ID : b + Short name : b + Severity : minor + Status : closed + Assigned : + Target : + Reporter : + Creator : Jane Doe <jdoe@example.com> + Created : Wed, 31 Dec 1969 19:00 (Thu, 01 Jan 1970 00:00:00 +0000) + Bug B + --------- Comment --------- + Name: b:1 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:01 +0000 + <BLANKLINE> + 1 2 + --------- Comment --------- + Name: b:2 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:02 +0000 + <BLANKLINE> + 1 2 3 4 + --------- Comment --------- + Name: b:3 + From: wking <wking@thor.yang.physics.drexel.edu> + Date: Thu, 01 Jan 1970 00:00:03 +0000 + <BLANKLINE> + Merged into bug a + >>> print b.status + closed + """ + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True, + 1: lambda bug : bug.active==True}) + + if len(args) < 2: + raise cmdutil.UsageError("Please specify two bug ids.") + if len(args) > 2: + help() + raise cmdutil.UsageError("Too many arguments.") + + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) + bugA = bd.bug_from_shortname(args[0]) + bugA.load_comments() + bugB = bd.bug_from_shortname(args[1]) + bugB.load_comments() + mergeA = bugA.new_comment("Merged from bug %s" % bugB.uuid) + newCommTree = copy.deepcopy(bugB.comment_root) + for comment in newCommTree.traverse(): + comment.bug = bugA + for comment in newCommTree: + mergeA.add_reply(comment, allow_time_inversion=True) + bugB.new_comment("Merged into bug %s" % bugA.uuid) + bugB.status = "closed" + bd.save() + print "Merging bugs %s and %s" % (bugA.uuid, bugB.uuid) + +def get_parser(): + parser = cmdutil.CmdOptionParser("be merge BUG-ID BUG-ID") + return parser + +longhelp=""" +The second bug (B) is merged into the first (A). This adds merge +comments to both bugs, closes B, and appends B's comment tree to A's +merge comment. +""" + +def help(): + return get_parser().help_str() + longhelp diff --git a/becommands/new.py b/becommands/new.py index caa1549..1c5246c 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -15,39 +15,53 @@ # 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, bugdir +from libbe import cmdutil, bugdir, settings_object __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os, time >>> from libbe import bug >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) >>> bug.uuid_gen = lambda: "X" - >>> execute (["this is a test",]) + >>> execute (["this is a test",], test=True) Created bug with ID X >>> bd.load() >>> bug = bd.bug_from_uuid("X") - >>> bug.summary - u'this is a test' + >>> print bug.summary + this is a test >>> bug.time <= int(time.time()) True - >>> bug.severity - u'minor' - >>> bug.target == None + >>> print bug.severity + minor + >>> bug.target == settings_object.EMPTY True """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser) if len(args) != 1: - raise cmdutil.UserError("Please supply a summary message") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError("Please supply a summary message") + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.new_bug(summary=args[0]) + if options.reporter != None: + bug.reporter = options.reporter + else: + bug.reporter = bug.creator + if options.assigned != None: + bug.assigned = options.assigned + elif bd.default_assignee != settings_object.EMPTY: + bug.assigned = bd.default_assignee bd.save() print "Created bug with ID %s" % bd.bug_shortname(bug) def get_parser(): parser = cmdutil.CmdOptionParser("be new SUMMARY") + parser.add_option("-r", "--reporter", metavar="REPORTER", dest="reporter", + help="The user who reported the bug", default=None) + parser.add_option("-a", "--assigned", metavar="ASSIGNED", dest="assigned", + help="The developer in charge of the bug", default=None) return parser longhelp=""" diff --git a/becommands/open.py b/becommands/open.py index 788a183..7a18fd0 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -18,25 +18,27 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("b").status closed - >>> execute(["b"]) + >>> execute(["b"], test=True) >>> bd._clear_bugs() >>> print bd.bug_from_shortname("b").status open """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==False}) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug id.") + raise cmdutil.UsageError, "Please specify a bug id." if len(args) > 1: - help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError, "Too many arguments." + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(args[0]) bug.status = "open" bd.save() diff --git a/becommands/remove.py b/becommands/remove.py index 8f7c2c6..fa264b8 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -18,7 +18,7 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> from libbe import mapfile >>> import os @@ -26,7 +26,7 @@ def execute(args): >>> os.chdir(bd.root) >>> print bd.bug_from_shortname("b").status closed - >>> execute (["b"]) + >>> execute (["b"], test=True) Removed bug b >>> bd._clear_bugs() >>> try: @@ -35,10 +35,13 @@ def execute(args): ... print "Bug not found" Bug not found """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) if len(args) != 1: - raise cmdutil.UserError("Please specify a bug id.") - bd = bugdir.BugDir(from_disk=True) + 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]) bd.remove_bug(bug) bd.save() diff --git a/becommands/set.py b/becommands/set.py index 287ceb4..b8a125e 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -15,38 +15,60 @@ # 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, bugdir +from libbe import cmdutil, bugdir, settings_object __desc__ = __doc__ -def execute(args): +def _value_string(bd, setting): + val = bd.settings.get(setting, settings_object.EMPTY) + if val == settings_object.EMPTY: + default = getattr(bd, bd._setting_name_to_attr_name(setting)) + if default != settings_object.EMPTY: + val = "None (%s)" % default + else: + val = None + return str(val) + +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["target"]) + >>> execute(["target"], test=True) None - >>> execute(["target", "tomorrow"]) - >>> execute(["target"]) + >>> execute(["target", "tomorrow"], test=True) + >>> execute(["target"], test=True) tomorrow - >>> execute(["target", "none"]) - >>> execute(["target"]) + >>> execute(["target", "none"], test=True) + >>> execute(["target"], test=True) None """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) > 2: - help() - raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError, "Too many arguments" + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) if len(args) == 0: - keys = bd.settings.keys() + keys = bd.settings_properties keys.sort() for key in keys: - print "%16s: %s" % (key, bd.settings[key]) + print "%16s: %s" % (key, _value_string(bd, key)) elif len(args) == 1: - print bd.settings.get(args[0]) + print _value_string(bd, args[0]) else: if args[1] != "none": - bd.settings[args[0]] = args[1] + if args[0] not in bd.settings_properties: + msg = "Invalid setting %s\n" % args[0] + msg += 'Allowed settings:\n ' + msg += '\n '.join(bd.settings_properties) + raise cmdutil.UserError(msg) + old_setting = bd.settings.get(args[0]) + try: + setattr(bd, args[0], args[1]) + except bugdir.InvalidValue, e: + bd.settings[args[0]] = old_setting + bd.save() + raise cmdutil.UserError(e) else: del bd.settings[args[0]] bd.save() @@ -73,3 +95,15 @@ To unset a setting, set it to "none". def help(): return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option, value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + for pos,value in enumerate(args): + if value == "--complete": + if pos == 0: # first positional argument is a setting name + props = bugdir.BugDir.settings_properties + raise cmdutil.GetCompletions(props) + raise cmdutil.GetCompletions() # no positional arguments for list diff --git a/becommands/set_root.py b/becommands/set_root.py index e17bd87..3749e28 100644 --- a/becommands/set_root.py +++ b/becommands/set_root.py @@ -19,7 +19,7 @@ import os.path from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> from libbe import utility, rcs >>> import os @@ -29,7 +29,7 @@ def execute(args): ... except bugdir.NoBugDir, e: ... True True - >>> execute([dir.path]) + >>> execute([dir.path], test=True) No revision control detected. Directory initialized. >>> del(dir) @@ -40,34 +40,33 @@ def execute(args): >>> rcs.init('.') >>> print rcs.name Arch - >>> execute([]) + >>> execute([], test=True) Using Arch for revision control. Directory initialized. >>> rcs.cleanup() >>> try: - ... execute(['.']) + ... execute(['.'], test=True) ... except cmdutil.UserError, e: ... str(e).startswith("Directory already initialized: ") True - >>> execute(['/highly-unlikely-to-exist']) + >>> execute(['/highly-unlikely-to-exist'], test=True) Traceback (most recent call last): UserError: No such directory: /highly-unlikely-to-exist >>> os.chdir('/') """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser) if len(args) > 1: - print help() - raise cmdutil.UserError, "Too many arguments" + raise cmdutil.UsageError if len(args) == 1: basedir = args[0] else: basedir = "." - if os.path.exists(basedir) == False: - pass - #raise cmdutil.UserError, "No such directory: %s" % basedir try: - bd = bugdir.BugDir(basedir, from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True) + bd = bugdir.BugDir(basedir, from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True, + manipulate_encodings=not test) except bugdir.NoRootEntry: raise cmdutil.UserError("No such directory: %s" % basedir) except bugdir.AlreadyInitialized: diff --git a/becommands/severity.py b/becommands/severity.py index 3adefaa..5d27222 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -15,29 +15,29 @@ # 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, bugdir -from libbe.bug import severity_values, severity_description +from libbe import cmdutil, bugdir, bug __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["a"]) + >>> execute(["a"], test=True) minor - >>> execute(["a", "wishlist"]) - >>> execute(["a"]) + >>> execute(["a", "wishlist"], test=True) + >>> execute(["a"], test=True) wishlist - >>> execute(["a", "none"]) + >>> execute(["a", "none"], test=True) Traceback (most recent call last): UserError: Invalid severity level: none """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) not in (1,2): - print help() - return - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.severity @@ -46,7 +46,7 @@ def execute(args): bug.severity = args[1] except ValueError, e: if e.name != "severity": - raise + raise e raise cmdutil.UserError ("Invalid severity level: %s" % e.value) bd.save() @@ -54,7 +54,8 @@ def get_parser(): parser = cmdutil.CmdOptionParser("be severity BUG-ID [SEVERITY]") return parser -longhelp=[""" +def help(): + longhelp=[""" Show or change a bug's severity level. If no severity is specified, the current value is printed. If a severity level @@ -62,13 +63,38 @@ is specified, it will be assigned to the bug. Severity levels are: """] -longest_severity_len = max([len(s) for s in severity_values]) -for severity in severity_values : - description = severity_description[severity] - s = "%*s : %s\n" % (longest_severity_len, severity, description) - longhelp.append(s) -longhelp = ''.join(longhelp) - - -def help(): + try: # See if there are any per-tree severity configurations + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=False) + except bugdir.NoBugDir, e: + pass # No tree, just show the defaults + longest_severity_len = max([len(s) for s in bug.severity_values]) + for severity in bug.severity_values : + description = bug.severity_description[severity] + s = "%*s : %s\n" % (longest_severity_len, severity, description) + longhelp.append(s) + longhelp = ''.join(longhelp) return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option,value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + for pos,value in enumerate(args): + if value == "--complete": + try: # See if there are any per-tree severity configurations + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=False) + except bugdir.NoBugDir: + bd = None + if pos == 0: # fist positional argument is a bug id + ids = [] + if bd != None: + bd.load_all_bugs() + filter = lambda bg : bg.active==True + bugs = [bg for bg in bd if filter(bg)==True] + ids = [bd.bug_shortname(bg) for bg in bugs] + raise cmdutil.GetCompletions(ids) + elif pos == 1: # second positional argument is a severity + raise cmdutil.GetCompletions(bug.severity_values) + raise cmdutil.GetCompletions() diff --git a/becommands/show.py b/becommands/show.py index 1ee354c..7c48257 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -18,33 +18,52 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute (["a",]) + >>> execute (["a",], test=True) ID : a Short name : a Severity : minor Status : open Assigned : Target : + Reporter : Creator : John Doe <jdoe@example.com> Created : Wed, 31 Dec 1969 19:00 (Thu, 01 Jan 1970 00:00:00 +0000) Bug A <BLANKLINE> + >>> execute (["--xml", "a"], test=True) + <bug> + <uuid>a</uuid> + <short-name>a</short-name> + <severity>minor</severity> + <status>open</status> + <assigned><class 'libbe.settings_object.EMPTY'></assigned> + <target><class 'libbe.settings_object.EMPTY'></target> + <reporter><class 'libbe.settings_object.EMPTY'></reporter> + <creator>John Doe <jdoe@example.com></creator> + <created>Wed, 31 Dec 1969 19:00 (Thu, 01 Jan 1970 00:00:00 +0000)</created> + <summary>Bug A</summary> + </bug> """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug id.") - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) for bugid in args: bug = bd.bug_from_shortname(bugid) if options.dumpXML: print bug.xml(show_comments=True) else: print bug.string(show_comments=True) + if bugid != args[-1]: + print "" # add a blank line between bugs def get_parser(): parser = cmdutil.CmdOptionParser("be show [options] BUG-ID [BUG-ID ...]") diff --git a/becommands/status.py b/becommands/status.py index a30b3d6..40e9b51 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -15,33 +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 """Show or change a bug's status""" -from libbe import cmdutil, bugdir -from libbe.bug import status_values, status_description +from libbe import cmdutil, bugdir, bug __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["a"]) + >>> execute(["a"], test=True) open - >>> execute(["a", "closed"]) - >>> execute(["a"]) + >>> execute(["a", "closed"], test=True) + >>> execute(["a"], test=True) closed - >>> execute(["a", "none"]) + >>> execute(["a", "none"], test=True) Traceback (most recent call last): UserError: Invalid status: none """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) not in (1,2): - print help() - return - bd = bugdir.BugDir(from_disk=True) + raise cmdutil.UsageError + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.status - elif len(args) == 2: + else: try: bug.status = args[1] except ValueError, e: @@ -54,20 +54,46 @@ def get_parser(): parser = cmdutil.CmdOptionParser("be status BUG-ID [STATUS]") return parser -longhelp=[""" -Show or change a bug's severity level. -If no severity is specified, the current value is printed. If a severity level +def help(): + longhelp=[""" +Show or change a bug's status. + +If no status is specified, the current value is printed. If a status is specified, it will be assigned to the bug. -Severity levels are: +Status levels are: """] -longest_status_len = max([len(s) for s in status_values]) -for status in status_values : - description = status_description[status] - s = "%*s : %s\n" % (longest_status_len, status, description) - longhelp.append(s) -longhelp = ''.join(longhelp) - -def help(): + try: # See if there are any per-tree status configurations + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=False) + except bugdir.NoBugDir, e: + pass # No tree, just show the defaults + longest_status_len = max([len(s) for s in bug.status_values]) + for status in bug.status_values : + description = bug.status_description[status] + s = "%*s : %s\n" % (longest_status_len, status, description) + longhelp.append(s) + longhelp = ''.join(longhelp) return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option,value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + for pos,value in enumerate(args): + if value == "--complete": + try: # See if there are any per-tree status configurations + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=False) + except bugdir.NoBugDir: + bd = None + if pos == 0: # fist positional argument is a bug id + ids = [] + if bd != None: + bd.load_all_bugs() + ids = [bd.bug_shortname(bg) for bg in bd] + raise cmdutil.GetCompletions(ids) + elif pos == 1: # second positional argument is a status + raise cmdutil.GetCompletions(bug.status_values) + raise cmdutil.GetCompletions() diff --git a/becommands/target.py b/becommands/target.py index dce100f..c83ffa7 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -15,36 +15,38 @@ # 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 cmdutil, bugdir +from libbe import cmdutil, bugdir, settings_object __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import os >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["a"]) + >>> execute(["a"], test=True) No target assigned. - >>> execute(["a", "tomorrow"]) - >>> execute(["a"]) + >>> execute(["a", "tomorrow"], test=True) + >>> execute(["a"], test=True) tomorrow - >>> execute(["a", "none"]) - >>> execute(["a"]) + >>> execute(["a", "none"], test=True) + >>> execute(["a"], test=True) No target assigned. """ - options, args = get_parser().parse_args(args) - assert(len(args) in (0, 1, 2)) - if len(args) == 0: - print help() - return - bd = bugdir.BugDir(from_disk=True) + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) + 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]) if len(args) == 1: - if bug.target is None: + if bug.target is None or bug.target is settings_object.EMPTY: print "No target assigned." else: print bug.target - elif len(args) == 2: + else: + assert len(args) == 2 if args[1] == "none": bug.target = None else: |