1 # Copyright (C) 2005 Aaron Bentley and Panometrics, Inc.
2 # <abentley@panoramicfeedback.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """Show or change a bug's severity level"""
18 from libbe import cmdutil, bugdir, bug
21 def execute(args, test=False):
24 >>> bd = bugdir.simple_bug_dir()
26 >>> execute(["a"], test=True)
28 >>> execute(["a", "wishlist"], test=True)
29 >>> execute(["a"], test=True)
31 >>> execute(["a", "none"], test=True)
32 Traceback (most recent call last):
33 UserError: Invalid severity level: none
36 options, args = parser.parse_args(args)
37 complete(options, args, parser)
38 if len(args) not in (1,2):
39 raise cmdutil.UsageError
40 bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
41 bug = bd.bug_from_shortname(args[0])
46 bug.severity = args[1]
48 if e.name != "severity":
50 raise cmdutil.UserError ("Invalid severity level: %s" % e.value)
54 parser = cmdutil.CmdOptionParser("be severity BUG-ID [SEVERITY]")
59 Show or change a bug's severity level.
61 If no severity is specified, the current value is printed. If a severity level
62 is specified, it will be assigned to the bug.
66 try: # See if there are any per-tree severity configurations
67 bd = bugdir.BugDir(from_disk=True, manipulate_encodings=False)
68 except bugdir.NoBugDir, e:
69 pass # No tree, just show the defaults
70 longest_severity_len = max([len(s) for s in bug.severity_values])
71 for severity in bug.severity_values :
72 description = bug.severity_description[severity]
73 s = "%*s : %s\n" % (longest_severity_len, severity, description)
75 longhelp = ''.join(longhelp)
76 return get_parser().help_str() + longhelp
78 def complete(options, args, parser):
79 for option,value in cmdutil.option_value_pairs(options, parser):
80 if value == "--complete":
81 # no argument-options at the moment, so this is future-proofing
82 raise cmdutil.GetCompletions()
83 for pos,value in enumerate(args):
84 if value == "--complete":
85 try: # See if there are any per-tree severity configurations
86 bd = bugdir.BugDir(from_disk=True,
87 manipulate_encodings=False)
88 except bugdir.NoBugDir:
90 if pos == 0: # fist positional argument is a bug id
94 filter = lambda bg : bg.active==True
95 bugs = [bg for bg in bd if filter(bg)==True]
96 ids = [bd.bug_shortname(bg) for bg in bugs]
97 raise cmdutil.GetCompletions(ids)
98 elif pos == 1: # second positional argument is a severity
99 raise cmdutil.GetCompletions(bug.severity_values)
100 raise cmdutil.GetCompletions()