| Line | Revision | Contents |
| 1 | 288 | #!/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 os, sys |
|
| 26 | from optparse import OptionParser |
|
| 27 | ||
| 28 | 318 | import ubuntutools.lp.libsupport as lp_libsupport |
| 29 | 288 | |
| 30 | def die(message): |
|
| 31 | print >> sys.stderr, "Fatal: " + message |
|
| 32 | sys.exit(1) |
|
| 33 | ||
| 34 | if __name__ == '__main__': |
|
| 35 | usage = "Usage: %prog [-f] <new main bug> <bug to dup> [<bug to dup>...]" |
|
| 36 | optParser = OptionParser(usage) |
|
| 37 | optParser.add_option("-f", action = "store_true", |
|
| 38 | dest = "force", default = False, |
|
| 39 | help = "Skip confirmation prompt") |
|
| 40 | ||
| 41 | (options, args) = optParser.parse_args() |
|
| 42 | ||
| 43 | if len(args) < 2: |
|
| 44 | optParser.error("Need at least a new main bug and a bug to dup") |
|
| 45 | ||
| 46 | launchpad = None |
|
| 47 | try: |
|
| 48 | print "Setting up Launchpad" |
|
| 49 | 302 | launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools") |
| 50 | 288 | print "Launchpad setup complete" |
| 51 | except ImportError: |
|
| 52 | suggestion = "check whether python-launchpadlib is installed" |
|
| 53 | except IOError: |
|
| 54 | suggestion = "you might want to \"manage-credentials create --consumer ubuntu-dev-tools --level 2\"" |
|
| 55 | if launchpad is None: |
|
| 56 | 443 | die("Couldn't setup Launchpad for the ubuntu-dev-tools consumer; %s" % (suggestion, )) |
| 57 | 288 | |
| 58 | # check that the new main bug isn't a duplicate |
|
| 59 | new_main_bug = launchpad.bugs[args[0]] |
|
| 60 | new_main_dup_of = new_main_bug.duplicate_of |
|
| 61 | if new_main_dup_of is not None: |
|
| 62 | 291 | s = None |
| 63 | try: |
|
| 64 | s = raw_input("Bug %s is a duplicate of %s; would you like to use %s as the new main bug instead? [y/N]" % (new_main_bug.id, new_main_dup_of.id, new_main_dup_of.id)) |
|
| 65 | except: |
|
| 66 | die("Aborted") |
|
| 67 | if s.lower() not in ("y", "yes"): |
|
| 68 | die("User aborted") |
|
| 69 | new_main_bug = new_main_dup_of |
|
| 70 | 288 | |
| 71 | # build list of bugs to process, first the dups then the bug |
|
| 72 | bugs_to_process = [] |
|
| 73 | for b in args[1:]: |
|
| 74 | print "Processing %s" % (b) |
|
| 75 | bug = launchpad.bugs[b] |
|
| 76 | dups = bug.duplicates |
|
| 77 | if dups is not None: |
|
| 78 | bugs_to_process.extend(dups) |
|
| 79 | print "Found %i dups for %s" % (len(dups), b) |
|
| 80 | bugs_to_process.append(bug) |
|
| 81 | ||
| 82 | # process dups first, then their main bug |
|
| 83 | print "Would set the following bugs as duplicates of %s: %s" % (new_main_bug.id, " ".join([str(b.id) for b in bugs_to_process])) |
|
| 84 | ||
| 85 | if not options.force: |
|
| 86 | 292 | s = None |
| 87 | 288 | try: |
| 88 | 292 | s = raw_input("Proceed? [y/N]") |
| 89 | 288 | except: |
| 90 | die("Aborted") |
|
| 91 | if s.lower() not in ("y", "yes"): |
|
| 92 | die("User aborted") |
|
| 93 | ||
| 94 | for bug in bugs_to_process: |
|
| 95 | print "Marking bug %s as a duplicate of %s" % (bug.id, new_main_bug.id) |
|
| 96 | bug.duplicate_of = new_main_bug |
|
| 97 | bug.lp_save() |
|
| 98 |
Loggerhead 1.10 is a web-based interface for Bazaar branches