1 # Copyright (C) 2005-2012 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Chris Ball <cjb@laptop.org>
3 # Gianluca Montecchi <gian@grys.it>
4 # Marien Zwart <marien.zwart@gmail.com>
5 # Robert Lehmann <mail@robertlehmann.de>
6 # Thomas Gerigk <tgerigk@gmx.de>
7 # W. Trevor King <wking@tremily.us>
9 # This file is part of Bugs Everywhere.
11 # Bugs Everywhere is free software: you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the Free
13 # Software Foundation, either version 2 of the License, or (at your option) any
16 # Bugs Everywhere is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 # You should have received a copy of the GNU General Public License along with
22 # Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
26 import libbe.command.util
29 class Assign (libbe.command.Command):
30 u"""Assign an individual or group to fix a bug
33 >>> import libbe.bugdir
34 >>> bd = libbe.bugdir.SimpleBugDir(memory=False)
35 >>> io = libbe.command.StringInputOutput()
36 >>> io.stdout = sys.stdout
37 >>> ui = libbe.command.UserInterface(io=io)
38 >>> ui.storage_callbacks.set_storage(bd.storage)
39 >>> cmd = Assign(ui=ui)
41 >>> bd.bug_from_uuid('a').assigned is None
43 >>> ui._user_id = u'Fran\xe7ois'
44 >>> ret = ui.run(cmd, args=['-', '/a'])
46 >>> bd.bug_from_uuid('a').assigned
49 >>> ret = ui.run(cmd, args=['someone', '/a', '/b'])
51 >>> bd.bug_from_uuid('a').assigned
53 >>> bd.bug_from_uuid('b').assigned
56 >>> ret = ui.run(cmd, args=['none', '/a'])
58 >>> bd.bug_from_uuid('a').assigned is None
65 def __init__(self, *args, **kwargs):
66 libbe.command.Command.__init__(self, *args, **kwargs)
68 libbe.command.Argument(
69 name='assigned', metavar='ASSIGNED', default=None,
70 completion_callback=libbe.command.util.complete_assigned),
71 libbe.command.Argument(
72 name='bug-id', metavar='BUG-ID', default=None,
74 completion_callback=libbe.command.util.complete_bug_id),
77 def _run(self, **params):
78 assigned = parse_assigned(self, params['assigned'])
79 bugdirs = self._get_bugdirs()
80 for bug_id in params['bug-id']:
81 bugdir,bug,comment = (
82 libbe.command.util.bugdir_bug_comment_from_user_id(
84 if bug.assigned != assigned:
85 bug.assigned = assigned
86 if bug.status == 'open':
87 bug.status = 'assigned'
92 Assign a person to fix a bug.
94 Assigneds should be the person's Bugs Everywhere identity, the same
95 string that appears in Creator fields.
97 Special assigned strings:
98 "-" assign the bug to yourself
99 "none" un-assigns the bug
102 def parse_assigned(command, assigned):
103 """Standard processing for the 'assigned' Argument.
105 if assigned == 'none':
107 elif assigned == '-':
108 assigned = command._get_user_id()