1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 # Gianluca Montecchi <gian@grys.it>
3 # Marien Zwart <marienz@gentoo.org>
4 # Thomas Gerigk <tgerigk@gmx.de>
5 # W. Trevor King <wking@drexel.edu>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 """Show or change a bug's severity level"""
21 from libbe import cmdutil, bugdir, bug
24 def execute(args, manipulate_encodings=True, restrict_file_access=False):
27 >>> bd = bugdir.SimpleBugDir()
29 >>> execute(["a"], manipulate_encodings=False)
31 >>> execute(["a", "wishlist"], manipulate_encodings=False)
32 >>> execute(["a"], manipulate_encodings=False)
34 >>> execute(["a", "none"], manipulate_encodings=False)
35 Traceback (most recent call last):
36 UserError: Invalid severity level: none
40 options, args = parser.parse_args(args)
41 complete(options, args, parser)
42 if len(args) not in (1,2):
43 raise cmdutil.UsageError
44 bd = bugdir.BugDir(from_disk=True,
45 manipulate_encodings=manipulate_encodings)
46 bug = cmdutil.bug_from_id(bd, args[0])
51 bug.severity = args[1]
53 if e.name != "severity":
55 raise cmdutil.UserError ("Invalid severity level: %s" % e.value)
58 parser = cmdutil.CmdOptionParser("be severity BUG-ID [SEVERITY]")
63 Show or change a bug's severity level.
65 If no severity is specified, the current value is printed. If a severity level
66 is specified, it will be assigned to the bug.
70 try: # See if there are any per-tree severity configurations
71 bd = bugdir.BugDir(from_disk=True, manipulate_encodings=False)
72 except bugdir.NoBugDir, e:
73 pass # No tree, just show the defaults
74 longest_severity_len = max([len(s) for s in bug.severity_values])
75 for severity in bug.severity_values :
76 description = bug.severity_description[severity]
77 s = "%*s : %s\n" % (longest_severity_len, severity, description)
79 longhelp = ''.join(longhelp)
80 return get_parser().help_str() + longhelp
82 def complete(options, args, parser):
83 for option,value in cmdutil.option_value_pairs(options, parser):
84 if value == "--complete":
85 # no argument-options at the moment, so this is future-proofing
86 raise cmdutil.GetCompletions()
87 for pos,value in enumerate(args):
88 if value == "--complete":
89 try: # See if there are any per-tree severity configurations
90 bd = bugdir.BugDir(from_disk=True,
91 manipulate_encodings=False)
92 except bugdir.NoBugDir:
94 if pos == 0: # fist positional argument is a bug id
98 filter = lambda bg : bg.active==True
99 bugs = [bg for bg in bd if filter(bg)==True]
100 ids = [bd.bug_shortname(bg) for bg in bugs]
101 raise cmdutil.GetCompletions(ids)
102 elif pos == 1: # second positional argument is a severity
103 raise cmdutil.GetCompletions(bug.severity_values)
104 raise cmdutil.GetCompletions()