~vorlon/ubuntu-archive-tools/close-EOL-bugs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python2.7

# Copyright (C) 2011, 2012  Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Move all bugs of a milestone to another milestone. This is usually done after
# the milestone was released.

import optparse
import sys

from launchpadlib.launchpad import Launchpad


def parse_args():
    '''Parse command line.

    Return (options, arguments).
    '''
    parser = optparse.OptionParser(
        usage='Usage: %prog [options] <from milestone> <to milestone>')
    parser.add_option(
        "-l", "--launchpad", dest="launchpad_instance", default="production")
    parser.add_option(
        "-s", "--series",
        help="Ubuntu release to work on (default: current development "
             "release)")
    parser.add_option(
        "-n", "--no-act", "--dry-run", action="store_true",
        help="Only show bugs that would be moved, but do not act on them")
    options, args = parser.parse_args()

    if len(args) != 2:
        parser.error('Need to specify "from" and "to" milestone. See --help')

    return (options, args)

if __name__ == '__main__':
    (options, (from_ms, to_ms)) = parse_args()

    launchpad = Launchpad.login_with(
        'ubuntu-archive-tools', options.launchpad_instance)
    ubuntu = launchpad.distributions['ubuntu']
    if options.series:
        distro_series = ubuntu.getSeries(name_or_version=options.series)
    else:
        distro_series = ubuntu.current_series

    # convert milestone names to LP objects
    lp_milestones = {}
    for m in distro_series.all_milestones:
        lp_milestones[m.name] = m
    try:
        from_ms = lp_milestones[from_ms]
    except KeyError:
        sys.stderr.write('ERROR: Unknown milestone %s\n' % from_ms)
        sys.exit(1)
    try:
        to_ms = lp_milestones[to_ms]
    except KeyError:
        sys.stderr.write('ERROR: Unknown milestone %s\n' % to_ms)
        sys.exit(1)

    # move them over
    if options.no_act:
        print('Would move the following bug tasks to %s:' % to_ms.name)
    else:
        print('Moving the following bug tasks to %s:' % to_ms.name)
    for task in from_ms.searchTasks():
        print(task.title)
        if not options.no_act:
            task.milestone_link = to_ms
            task.lp_save()