1 # Copyright (C) 2005-2011 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Gianluca Montecchi <gian@grys.it>
3 # Marien Zwart <marien.zwart@gmail.com>
4 # Thomas Gerigk <tgerigk@gmx.de>
5 # W. Trevor King <wking@drexel.edu>
7 # This file is part of Bugs Everywhere.
9 # Bugs Everywhere is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation, either version 2 of the License, or (at your
12 # option) any later version.
14 # Bugs Everywhere is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
25 import libbe.command.util
28 class Severity (libbe.command.Command):
29 """Change a bug's severity level
32 >>> import libbe.bugdir
33 >>> bd = libbe.bugdir.SimpleBugDir(memory=False)
34 >>> io = libbe.command.StringInputOutput()
35 >>> io.stdout = sys.stdout
36 >>> ui = libbe.command.UserInterface(io=io)
37 >>> ui.storage_callbacks.set_bugdir(bd)
38 >>> cmd = Severity(ui=ui)
40 >>> bd.bug_from_uuid('a').severity
42 >>> ret = ui.run(cmd, args=['wishlist', '/a'])
44 >>> bd.bug_from_uuid('a').severity
46 >>> ret = ui.run(cmd, args=['none', '/a'])
47 Traceback (most recent call last):
48 UserError: Invalid severity level: none
54 def __init__(self, *args, **kwargs):
55 libbe.command.Command.__init__(self, *args, **kwargs)
57 libbe.command.Argument(
58 name='severity', metavar='SEVERITY', default=None,
59 completion_callback=libbe.command.util.complete_severity),
60 libbe.command.Argument(
61 name='bug-id', metavar='BUG-ID', default=None,
63 completion_callback=libbe.command.util.complete_bug_id),
66 def _run(self, **params):
67 bugdir = self._get_bugdir()
68 for bug_id in params['bug-id']:
70 libbe.command.util.bug_comment_from_user_id(bugdir, bug_id)
71 if bug.severity != params['severity']:
73 bug.severity = params['severity']
75 if e.name != 'severity':
77 raise libbe.command.UserError(
78 'Invalid severity level: %s' % e.value)
83 Show or change a bug's severity level.
85 If no severity is specified, the current value is printed. If a severity level
86 is specified, it will be assigned to the bug.
90 try: # See if there are any per-tree severity configurations
91 bd = self._get_bugdir()
92 except NotImplementedError:
93 pass # No tree, just show the defaults
94 longest_severity_len = max([len(s) for s in libbe.bug.severity_values])
95 for severity in libbe.bug.severity_values :
96 description = libbe.bug.severity_description[severity]
97 ret.append('%*s : %s\n' \
98 % (longest_severity_len, severity, description))