1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 # Chris Ball <cjb@laptop.org>
3 # Gianluca Montecchi <gian@grys.it>
4 # Marien Zwart <marienz@gentoo.org>
5 # Thomas Gerigk <tgerigk@gmx.de>
6 # W. Trevor King <wking@drexel.edu>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 """Show or change a bug's target for fixing"""
22 from libbe import cmdutil, bugdir
25 def execute(args, manipulate_encodings=True):
28 >>> bd = bugdir.SimpleBugDir()
30 >>> execute(["a"], manipulate_encodings=False)
32 >>> execute(["a", "tomorrow"], manipulate_encodings=False)
33 >>> execute(["a"], manipulate_encodings=False)
35 >>> execute(["--list"], manipulate_encodings=False)
37 >>> execute(["a", "none"], manipulate_encodings=False)
38 >>> execute(["a"], manipulate_encodings=False)
43 options, args = parser.parse_args(args)
44 cmdutil.default_complete(options, args, parser,
45 bugid_args={0: lambda bug : bug.active==True})
47 if len(args) not in (1, 2):
48 if not (options.list == True and len(args) == 0):
49 raise cmdutil.UsageError
50 bd = bugdir.BugDir(from_disk=True,
51 manipulate_encodings=manipulate_encodings)
53 ts = set([bd.bug_from_uuid(bug).target for bug in bd.list_uuids()])
54 for target in sorted(ts):
55 if target and isinstance(target,str):
58 bug = cmdutil.bug_from_shortname(bd, args[0])
60 if bug.target is None:
61 print "No target assigned."
72 parser = cmdutil.CmdOptionParser("be target BUG-ID [TARGET]\nor: be target --list")
73 parser.add_option("-l", "--list", action="store_true", dest="list",
74 help="List all available targets and exit")
78 Show or change a bug's target for fixing.
80 If no target is specified, the current value is printed. If a target
81 is specified, it will be assigned to the bug.
83 Targets are freeform; any text may be specified. They will generally be
84 milestone names or release numbers.
86 The value "none" can be used to unset the target.
88 In the alternative `be target --list` form print a list of all
89 currently specified targets. Note that bug status
90 (i.e. opened/closed) is ignored. If you want to list all bugs
91 matching a current target, see `be list --target TARGET'.
95 return get_parser().help_str() + longhelp