~ubuntu-branches/debian/sid/ubuntu-dev-tools/sid

« back to all changes in this revision

Viewing changes to lp-set-dup

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung, Colin Watson, Jelmer Vernooij, Stefano Rivera, Julian Taylor, Benjamin Drung
  • Date: 2011-09-06 14:31:31 UTC
  • Revision ID: package-import@ubuntu.com-20110906143131-pukbbowpabmw4w42
Tags: 0.129
[ Colin Watson ]
* syncpackage: Convert to new LP API, with --no-lp available for the old
  style of operation.
* syncpackage: Require -f/--force option to overwrite Ubuntu changes.

[ Jelmer Vernooij ]
* Remove several tools not specific to Ubuntu that have been migrated to
  lptools (LP: #708886):
 - get-branches (renamed to lp-get-branches)
 - grab-attachments (renamed to lp-grab-attachments)
 - lp-project-upload
 - lp-list-bugs
 - lp-set-dup
 - lp-shell

[ Stefano Rivera ]
* syncpackage: Show changes to be synced when performing native syncs.
* syncpackage: Check the sync blacklist.
* syncpackage: Support --bug (extra bugs to be closed by the sync) with
  native syncs. (Bugs are closed one individually, via the API, post-sync)
* dgetlp, submittodebian, 404main: Use unicode strings for literal strings
  containing non-ASCII characters (LP: #836661)
* Recommend pbuilder | aptitude for get-build-deps, and exit with an error
  if neither are installed (LP: #799368)
* get-build-deps: Tell aptitude not to follow Recommends (LP: #817500)
* doc/requestsync.1: Document the -C option (LP: #833408)
* ubuntutools.archive: Don't write .dsc files until we pull the entire
  source package, just hold it in memory. Avoids littering the current
  directory (LP: #838361)
* Run harvest as part of sponsor-patch (LP: #833699)

[ Julian Taylor ]
* requestsync: omit dups when checking for duplicate requests (LP: #842217)

[ Benjamin Drung ]
* sponsor-patch: Default to not upload the package.
* requestsync: Do not crash on user abort (Closes: #637168).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- coding: UTF-8 -*-
3
 
"""Sets the "duplicate of" bug of a bug and its dups."""
4
 
 
5
 
# Copyright (c) 2009 Canonical Ltd.
6
 
#
7
 
# lp-set-dup is free software; you can redistribute it and/or modify it
8
 
# under the terms of the GNU General Public License as published by the
9
 
# Free Software Foundation; either version 2, or (at your option) any
10
 
# later version.
11
 
#
12
 
# lp-set-dup is distributed in the hope that it will be useful, but
13
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
# General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with lp-set-dup; see the file COPYING.  If not, write to the Free
19
 
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
# 02110-1301, USA.
21
 
#
22
 
# Authors:
23
 
#  Loïc Minier <lool@dooz.org>
24
 
 
25
 
import sys
26
 
from optparse import OptionParser
27
 
 
28
 
from launchpadlib.launchpad import Launchpad
29
 
from launchpadlib.errors import HTTPError
30
 
 
31
 
from ubuntutools.config import UDTConfig
32
 
 
33
 
def die(message):
34
 
    print >> sys.stderr, "Fatal: " + message
35
 
    sys.exit(1)
36
 
 
37
 
def main():
38
 
    usage = "Usage: %prog [-f] <new main bug> <bug to dup> [<bug to dup>...]"
39
 
    opt_parser = OptionParser(usage)
40
 
    opt_parser.add_option("-f",
41
 
                          help="Skip confirmation prompt",
42
 
                          dest="force", default=False, action="store_true")
43
 
    opt_parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
44
 
                          help="Launchpad instance to connect to "
45
 
                               "(default: production)",
46
 
                          dest="lpinstance", default=None)
47
 
    opt_parser.add_option("--no-conf",
48
 
                          help="Don't read config files or "
49
 
                               "environment variables.",
50
 
                          dest="no_conf", default=False, action="store_true")
51
 
    (options, args) = opt_parser.parse_args()
52
 
 
53
 
    if len(args) < 2:
54
 
        opt_parser.error("Need at least a new main bug and a bug to dup")
55
 
 
56
 
    config = UDTConfig(options.no_conf)
57
 
    if options.lpinstance is None:
58
 
        options.lpinstance = config.get_value("LPINSTANCE")
59
 
 
60
 
    launchpad = None
61
 
    try:
62
 
        print "Setting up Launchpad"
63
 
        launchpad = Launchpad.login_with("ubuntu-dev-tools", options.lpinstance)
64
 
        print "Launchpad setup complete"
65
 
    except ImportError:
66
 
        suggestion = "check whether python-launchpadlib is installed"
67
 
    if launchpad is None:
68
 
        die("Couldn't setup Launchpad for the ubuntu-dev-tools consumer; %s" % \
69
 
            (suggestion, ))
70
 
 
71
 
    # check that the new main bug isn't a duplicate
72
 
    try:
73
 
        new_main_bug = launchpad.bugs[args[0]]
74
 
    except HTTPError, error:
75
 
        if error.response.status == 401:
76
 
            print >> sys.stderr, ("E: Don't have enough permissions to access "
77
 
                                  "bug %s") % (args[0])
78
 
            die(error.content)
79
 
        else:
80
 
            raise
81
 
    new_main_dup_of = new_main_bug.duplicate_of
82
 
    if new_main_dup_of is not None:
83
 
        answer = None
84
 
        try:
85
 
            answer = raw_input("Bug %s is a duplicate of %s; would you like to "
86
 
                               "use %s as the new main bug instead? [y/N]" % \
87
 
                               (new_main_bug.id, new_main_dup_of.id,
88
 
                                new_main_dup_of.id))
89
 
        except:
90
 
            die("Aborted")
91
 
        if answer.lower() not in ("y", "yes"):
92
 
            die("User aborted")
93
 
        new_main_bug = new_main_dup_of
94
 
 
95
 
    # build list of bugs to process, first the dups then the bug
96
 
    bugs_to_process = []
97
 
    for bug_number in args[1:]:
98
 
        print "Processing %s" % (bug_number)
99
 
        try:
100
 
            bug = launchpad.bugs[bug_number]
101
 
        except HTTPError, error:
102
 
            if error.response.status == 401:
103
 
                print >> sys.stderr, ("W: Don't have enough permissions to "
104
 
                                      "access bug %s") % (bug_number)
105
 
                print >> sys.stderr, "W: %s" % (error.content)
106
 
                continue
107
 
            else:
108
 
                raise
109
 
        dups = bug.duplicates
110
 
        if dups is not None:
111
 
            bugs_to_process.extend(dups)
112
 
            print "Found %i dups for %s" % (len(dups), bug_number)
113
 
        bugs_to_process.append(bug)
114
 
 
115
 
    # process dups first, then their main bug
116
 
    print "Would set the following bugs as duplicates of %s: %s" % \
117
 
          (new_main_bug.id, " ".join([str(b.id) for b in bugs_to_process]))
118
 
 
119
 
    if not options.force:
120
 
        answer = None
121
 
        try:
122
 
            answer = raw_input("Proceed? [y/N]")
123
 
        except:
124
 
            die("Aborted")
125
 
        if answer.lower() not in ("y", "yes"):
126
 
            die("User aborted")
127
 
 
128
 
    for bug in bugs_to_process:
129
 
        print "Marking bug %s as a duplicate of %s" % (bug.id, new_main_bug.id)
130
 
        bug.duplicate_of = new_main_bug
131
 
        bug.lp_save()
132
 
 
133
 
if __name__ == '__main__':
134
 
    main()