~wallyworld/launchpadlib/services-serviceroot

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
86
87
88
89
90
91
92
93
#!/usr/bin/env python

# Copyright (C) 2009 Canonical Ltd.
#
# This file is part of launchpadlib.
#
# launchpadlib is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, version 3 of the License.
#
# launchpadlib 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 Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.

# Written By Julian Edwards.

"""Mark all your Fix Committed bugs in a project's milestone as Fix Released.

Quite useful at the end of a cycle when you want to avoid the pain of doing
it through the web UI!
"""

import os
import sys

from optparse import OptionParser

from launchpadlib.launchpad import Launchpad
from launchpadlib.uris import service_roots

COMMASPACE = ', '


def main(args):
    usage = """%s: project milestone\n\n%s""" % (sys.argv[0], __doc__)

    parser = OptionParser(usage=usage)
    parser.add_option(
        '-s', '--system', type='string', default='production', dest='lpsystem',
        help=("The Launchpad system to use.  Must be one of %s" %
              COMMASPACE.join(sorted(service_roots))))
    parser.add_option(
        '-y', '--yes', action='store_true', default=False, dest='force',
        help="Skip yes/no prompting and do it anyway")
    parser.add_option(
        '-f', '--force', action="store_true", default=False, dest='force',
        help='Obsolete synonym for --yes')
    parser.add_option(
        '-n', '--dry-run', action='store_true',
        help='Describe what the script would do without doing it.')
    options, args = parser.parse_args(args=args)
    if len(args) != 2:
        parser.print_usage()
        return 1

    project = args[0]
    milestone = args[1]

    launchpad = Launchpad.login_with(os.path.basename(sys.argv[0]),
                                     options.lpsystem)
    lp_project = launchpad.projects[project]
    lp_milestone = lp_project.getMilestone(name=milestone)

    my_committed_tasks = [
        task for task in lp_milestone.searchTasks(
            status="Fix Committed", assignee=launchpad.me)]

    for task in my_committed_tasks:
        print "Bug #%s: %s" % (task.bug.id, task.bug.title)

    if options.dry_run:
        print '\n*** Nothing changed.  Re-run without --dry-run/-n to commit.'
    else:
        if not options.force:
            answer = raw_input("Mark these bugs as Fix Released?  [y/N]")
            if answer in ("n", "N") or not answer:
                print "Ok, leaving them alone."
                return

        for task in my_committed_tasks:
            print "Releasing %s" % task.bug.id
            task.transitionToStatus(status='Fix Released')
        print "Done."

    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))