~wallyworld/launchpadlib/services-serviceroot

53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2009 Canonical Ltd.
4
#
5
# This file is part of launchpadlib.
6
#
7
# launchpadlib is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU Lesser General Public License as published by the
9
# Free Software Foundation, version 3 of the License.
10
#
11
# launchpadlib is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
# for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License
17
# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
18
19
# Written By Julian Edwards.
20
21
"""Mark all your Fix Committed bugs in a project's milestone as Fix Released.
22
23
Quite useful at the end of a cycle when you want to avoid the pain of doing
24
it through the web UI!
25
"""
26
60 by Brad Crittenden
[r=leonardr] Removed use of lp_factory from real scripts in contrib in favor of Launchpad.login_with.
27
import os
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
28
import sys
71.1.1 by Barry Warsaw
------------------------------------------------------------
29
30
from optparse import OptionParser
31
59 by Brad Crittenden
[r=bac] Added a short service root name for production.
32
from launchpadlib.launchpad import Launchpad
71.1.1 by Barry Warsaw
------------------------------------------------------------
33
from launchpadlib.uris import service_roots
34
35
COMMASPACE = ', '
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
36
59 by Brad Crittenden
[r=bac] Added a short service root name for production.
37
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
38
def main(args):
71.1.1 by Barry Warsaw
------------------------------------------------------------
39
    usage = """%s: project milestone\n\n%s""" % (sys.argv[0], __doc__)
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
40
41
    parser = OptionParser(usage=usage)
42
    parser.add_option(
112 by Leonard Richardson
[r=leonardr] Replace edge with production in the contrib scripts.
43
        '-s', '--system', type='string', default='production', dest='lpsystem',
60 by Brad Crittenden
[r=leonardr] Removed use of lp_factory from real scripts in contrib in favor of Launchpad.login_with.
44
        help=("The Launchpad system to use.  Must be one of %s" %
71.1.1 by Barry Warsaw
------------------------------------------------------------
45
              COMMASPACE.join(sorted(service_roots))))
46
    parser.add_option(
47
        '-y', '--yes', action='store_true', default=False, dest='force',
48
        help="Skip yes/no prompting and do it anyway")
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
49
    parser.add_option(
50
        '-f', '--force', action="store_true", default=False, dest='force',
71.1.1 by Barry Warsaw
------------------------------------------------------------
51
        help='Obsolete synonym for --yes')
52
    parser.add_option(
53
        '-n', '--dry-run', action='store_true',
54
        help='Describe what the script would do without doing it.')
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
55
    options, args = parser.parse_args(args=args)
56
    if len(args) != 2:
57
        parser.print_usage()
58
        return 1
59
60
    project = args[0]
61
    milestone = args[1]
62
60 by Brad Crittenden
[r=leonardr] Removed use of lp_factory from real scripts in contrib in favor of Launchpad.login_with.
63
    launchpad = Launchpad.login_with(os.path.basename(sys.argv[0]),
64
                                     options.lpsystem)
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
65
    lp_project = launchpad.projects[project]
66
    lp_milestone = lp_project.getMilestone(name=milestone)
67
68
    my_committed_tasks = [
69
        task for task in lp_milestone.searchTasks(
60 by Brad Crittenden
[r=leonardr] Removed use of lp_factory from real scripts in contrib in favor of Launchpad.login_with.
70
            status="Fix Committed", assignee=launchpad.me)]
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
71
72
    for task in my_committed_tasks:
73
        print "Bug #%s: %s" % (task.bug.id, task.bug.title)
74
71.1.1 by Barry Warsaw
------------------------------------------------------------
75
    if options.dry_run:
76
        print '\n*** Nothing changed.  Re-run without --dry-run/-n to commit.'
77
    else:
78
        if not options.force:
79
            answer = raw_input("Mark these bugs as Fix Released?  [y/N]")
80
            if answer in ("n", "N") or not answer:
81
                print "Ok, leaving them alone."
82
                return
83
84
        for task in my_committed_tasks:
85
            print "Releasing %s" % task.bug.id
86
            task.transitionToStatus(status='Fix Released')
87
        print "Done."
88
53.1.2 by Gary Poster
move "samples" to "contrib" to indicate that they are actually valuable to use, beyond merely being valuable to examine; and add a number of scripts to that directory from lp-dev-utils.
89
    return 0
90
91
92
if __name__ == '__main__':
93
    sys.exit(main(sys.argv[1:]))