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