mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-20 13:21:28 +00:00
lp-set-dup: Make pylint a little bit happier.
This commit is contained in:
parent
e0457ff333
commit
0fe7076e88
58
lp-set-dup
58
lp-set-dup
@ -34,22 +34,24 @@ def die(message):
|
|||||||
print >> sys.stderr, "Fatal: " + message
|
print >> sys.stderr, "Fatal: " + message
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main():
|
||||||
usage = "Usage: %prog [-f] <new main bug> <bug to dup> [<bug to dup>...]"
|
usage = "Usage: %prog [-f] <new main bug> <bug to dup> [<bug to dup>...]"
|
||||||
optParser = OptionParser(usage)
|
opt_parser = OptionParser(usage)
|
||||||
optParser.add_option("-f",
|
opt_parser.add_option("-f",
|
||||||
help="Skip confirmation prompt",
|
help="Skip confirmation prompt",
|
||||||
dest="force", default=False, action="store_true")
|
dest="force", default=False, action="store_true")
|
||||||
optParser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
opt_parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
||||||
help="Launchpad instance to connect to (default: production)",
|
help="Launchpad instance to connect to "
|
||||||
dest="lpinstance", default=None)
|
"(default: production)",
|
||||||
optParser.add_option("--no-conf",
|
dest="lpinstance", default=None)
|
||||||
help="Don't read config files or environment variables.",
|
opt_parser.add_option("--no-conf",
|
||||||
dest="no_conf", default=False, action="store_true")
|
help="Don't read config files or "
|
||||||
(options, args) = optParser.parse_args()
|
"environment variables.",
|
||||||
|
dest="no_conf", default=False, action="store_true")
|
||||||
|
(options, args) = opt_parser.parse_args()
|
||||||
|
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
optParser.error("Need at least a new main bug and a bug to dup")
|
opt_parser.error("Need at least a new main bug and a bug to dup")
|
||||||
|
|
||||||
config = UDTConfig(options.no_conf)
|
config = UDTConfig(options.no_conf)
|
||||||
if options.lpinstance is None:
|
if options.lpinstance is None:
|
||||||
@ -64,16 +66,19 @@ if __name__ == '__main__':
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
suggestion = "check whether python-launchpadlib is installed"
|
suggestion = "check whether python-launchpadlib is installed"
|
||||||
except IOError:
|
except IOError:
|
||||||
suggestion = "you might want to \"manage-credentials create --consumer ubuntu-dev-tools --level 2\""
|
suggestion = "you might want to \"manage-credentials create " + \
|
||||||
|
"--consumer ubuntu-dev-tools --level 2\""
|
||||||
if launchpad is None:
|
if launchpad is None:
|
||||||
die("Couldn't setup Launchpad for the ubuntu-dev-tools consumer; %s" % (suggestion, ))
|
die("Couldn't setup Launchpad for the ubuntu-dev-tools consumer; %s" % \
|
||||||
|
(suggestion, ))
|
||||||
|
|
||||||
# check that the new main bug isn't a duplicate
|
# check that the new main bug isn't a duplicate
|
||||||
try:
|
try:
|
||||||
new_main_bug = launchpad.bugs[args[0]]
|
new_main_bug = launchpad.bugs[args[0]]
|
||||||
except HTTPError, error:
|
except HTTPError, error:
|
||||||
if error.response.status == 401:
|
if error.response.status == 401:
|
||||||
print >> sys.stderr, "E: Don't have enough permissions to access bug %s" % (args[0])
|
print >> sys.stderr, ("E: Don't have enough permissions to access "
|
||||||
|
"bug %s") % (args[0])
|
||||||
die(error.content)
|
die(error.content)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
@ -81,7 +86,10 @@ if __name__ == '__main__':
|
|||||||
if new_main_dup_of is not None:
|
if new_main_dup_of is not None:
|
||||||
s = None
|
s = None
|
||||||
try:
|
try:
|
||||||
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))
|
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))
|
||||||
except:
|
except:
|
||||||
die("Aborted")
|
die("Aborted")
|
||||||
if s.lower() not in ("y", "yes"):
|
if s.lower() not in ("y", "yes"):
|
||||||
@ -90,13 +98,14 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# build list of bugs to process, first the dups then the bug
|
# build list of bugs to process, first the dups then the bug
|
||||||
bugs_to_process = []
|
bugs_to_process = []
|
||||||
for b in args[1:]:
|
for bug_number in args[1:]:
|
||||||
print "Processing %s" % (b)
|
print "Processing %s" % (bug_number)
|
||||||
try:
|
try:
|
||||||
bug = launchpad.bugs[b]
|
bug = launchpad.bugs[bug_number]
|
||||||
except HTTPError, error:
|
except HTTPError, error:
|
||||||
if error.response.status == 401:
|
if error.response.status == 401:
|
||||||
print >> sys.stderr, "W: Don't have enough permissions to access bug %s" % (b)
|
print >> sys.stderr, ("W: Don't have enough permissions to "
|
||||||
|
"access bug %s") % (bug_number)
|
||||||
print >> sys.stderr, "W: %s" % (error.content)
|
print >> sys.stderr, "W: %s" % (error.content)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -104,11 +113,12 @@ if __name__ == '__main__':
|
|||||||
dups = bug.duplicates
|
dups = bug.duplicates
|
||||||
if dups is not None:
|
if dups is not None:
|
||||||
bugs_to_process.extend(dups)
|
bugs_to_process.extend(dups)
|
||||||
print "Found %i dups for %s" % (len(dups), b)
|
print "Found %i dups for %s" % (len(dups), bug_number)
|
||||||
bugs_to_process.append(bug)
|
bugs_to_process.append(bug)
|
||||||
|
|
||||||
# process dups first, then their main bug
|
# process dups first, then their main bug
|
||||||
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]))
|
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]))
|
||||||
|
|
||||||
if not options.force:
|
if not options.force:
|
||||||
s = None
|
s = None
|
||||||
@ -124,3 +134,5 @@ if __name__ == '__main__':
|
|||||||
bug.duplicate_of = new_main_bug
|
bug.duplicate_of = new_main_bug
|
||||||
bug.lp_save()
|
bug.lp_save()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user