unbreak some tests.
[be.git] / becommands / severity.py
1 # Copyright (C) 2005 Aaron Bentley and Panometrics, Inc.
2 # <abentley@panoramicfeedback.com>
3 #
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.
8 #
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.
13 #
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 bugdir
19 from libbe import cmdutil 
20 __desc__ = __doc__
21
22 def execute(args):
23     """
24     >>> from libbe import tests
25     >>> import os
26     >>> dir = tests.simple_bug_dir()
27     >>> os.chdir(dir.dir)
28     >>> execute(["a"])
29     minor
30     >>> execute(["a", "wishlist"])
31     >>> execute(["a"])
32     wishlist
33     >>> execute(["a", "none"])
34     Traceback (most recent call last):
35     UserError: Invalid severity level: none
36     >>> tests.clean_up()
37     """
38     options, args = get_parser().parse_args(args)
39     assert(len(args) in (0, 1, 2))
40     if len(args) == 0:
41         print help()
42         return
43     bug = cmdutil.get_bug(args[0])
44     if len(args) == 1:
45         print bug.severity
46     elif len(args) == 2:
47         try:
48             bug.severity = args[1]
49         except bugdir.InvalidValue, e:
50             if e.name != "severity":
51                 raise
52             raise cmdutil.UserError ("Invalid severity level: %s" % e.value)
53         bug.save()
54
55 def get_parser():
56     parser = cmdutil.CmdOptionParser("be severity bug-id [severity]")
57     return parser
58
59 longhelp="""
60 Show or change a bug's severity level.  
61
62 If no severity is specified, the current value is printed.  If a severity level
63 is specified, it will be assigned to the bug.
64
65 Severity levels are:
66 wishlist: A feature that could improve usefulness, but not a bug. 
67    minor: The standard bug level.
68  serious: A bug that requires workarounds.
69 critical: A bug that prevents some features from working at all.
70    fatal: A bug that makes the package unusable.
71 """
72
73 def help():
74     return get_parser().help_str() + longhelp