Merge branch 'master' of wking.cfbe
[be.git] / libbe / command / assign.py
1 # Copyright (C) 2005-2010 Aaron Bentley <abentley@panoramicfeedback.com>
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>
6 #
7 # This file is part of Bugs Everywhere.
8 #
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.
13 #
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.
18 #
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/>.
21
22 import libbe
23 import libbe.command
24 import libbe.command.util
25
26
27 class Assign (libbe.command.Command):
28     u"""Assign an individual or group to fix a bug
29
30     >>> import sys
31     >>> import libbe.bugdir
32     >>> bd = libbe.bugdir.SimpleBugDir(memory=False)
33     >>> io = libbe.command.StringInputOutput()
34     >>> io.stdout = sys.stdout
35     >>> ui = libbe.command.UserInterface(io=io)
36     >>> ui.storage_callbacks.set_storage(bd.storage)
37     >>> cmd = Assign(ui=ui)
38
39     >>> bd.bug_from_uuid('a').assigned is None
40     True
41     >>> ui._user_id = u'Fran\xe7ois'
42     >>> ret = ui.run(cmd, args=['-', '/a'])
43     >>> bd.flush_reload()
44     >>> bd.bug_from_uuid('a').assigned
45     u'Fran\\xe7ois'
46
47     >>> ret = ui.run(cmd, args=['someone', '/a', '/b'])
48     >>> bd.flush_reload()
49     >>> bd.bug_from_uuid('a').assigned
50     'someone'
51     >>> bd.bug_from_uuid('b').assigned
52     'someone'
53
54     >>> ret = ui.run(cmd, args=['none', '/a'])
55     >>> bd.flush_reload()
56     >>> bd.bug_from_uuid('a').assigned is None
57     True
58     >>> ui.cleanup()
59     >>> bd.cleanup()
60     """
61     name = 'assign'
62
63     def __init__(self, *args, **kwargs):
64         libbe.command.Command.__init__(self, *args, **kwargs)
65         self.args.extend([
66                 libbe.command.Argument(
67                     name='assigned', metavar='ASSIGNED', default=None,
68                     completion_callback=libbe.command.util.complete_assigned),
69                 libbe.command.Argument(
70                     name='bug-id', metavar='BUG-ID', default=None,
71                     repeatable=True,
72                     completion_callback=libbe.command.util.complete_bug_id),
73                 ])
74
75     def _run(self, **params):
76         assigned = params['assigned']
77         if assigned == 'none':
78             assigned = None
79         elif assigned == '-':
80             assigned = self._get_user_id()
81         bugdir = self._get_bugdir()
82         for bug_id in params['bug-id']:
83             bug,dummy_comment = \
84                 libbe.command.util.bug_comment_from_user_id(bugdir, bug_id)
85             if bug.assigned != assigned:
86                 bug.assigned = assigned
87         return 0
88
89     def _long_help(self):
90         return """
91 Assign a person to fix a bug.
92
93 Assigneds should be the person's Bugs Everywhere identity, the same
94 string that appears in Creator fields.
95
96 Special assigned strings:
97   "-"      assign the bug to yourself
98   "none"   un-assigns the bug
99 """