mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-04-16 12:51:08 +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
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
usage = "Usage: %prog [-f] <new main bug> <bug to dup> [<bug to dup>...]"
|
||||
optParser = OptionParser(usage)
|
||||
optParser.add_option("-f",
|
||||
help="Skip confirmation prompt",
|
||||
dest="force", default=False, action="store_true")
|
||||
optParser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
||||
help="Launchpad instance to connect to (default: production)",
|
||||
dest="lpinstance", default=None)
|
||||
optParser.add_option("--no-conf",
|
||||
help="Don't read config files or environment variables.",
|
||||
dest="no_conf", default=False, action="store_true")
|
||||
(options, args) = optParser.parse_args()
|
||||
opt_parser = OptionParser(usage)
|
||||
opt_parser.add_option("-f",
|
||||
help="Skip confirmation prompt",
|
||||
dest="force", default=False, action="store_true")
|
||||
opt_parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
||||
help="Launchpad instance to connect to "
|
||||
"(default: production)",
|
||||
dest="lpinstance", default=None)
|
||||
opt_parser.add_option("--no-conf",
|
||||
help="Don't read config files or "
|
||||
"environment variables.",
|
||||
dest="no_conf", default=False, action="store_true")
|
||||
(options, args) = opt_parser.parse_args()
|
||||
|
||||
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)
|
||||
if options.lpinstance is None:
|
||||
@ -64,16 +66,19 @@ if __name__ == '__main__':
|
||||
except ImportError:
|
||||
suggestion = "check whether python-launchpadlib is installed"
|
||||
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:
|
||||
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
|
||||
try:
|
||||
new_main_bug = launchpad.bugs[args[0]]
|
||||
except HTTPError, error:
|
||||
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)
|
||||
else:
|
||||
raise
|
||||
@ -81,7 +86,10 @@ if __name__ == '__main__':
|
||||
if new_main_dup_of is not None:
|
||||
s = None
|
||||
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:
|
||||
die("Aborted")
|
||||
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
|
||||
bugs_to_process = []
|
||||
for b in args[1:]:
|
||||
print "Processing %s" % (b)
|
||||
for bug_number in args[1:]:
|
||||
print "Processing %s" % (bug_number)
|
||||
try:
|
||||
bug = launchpad.bugs[b]
|
||||
bug = launchpad.bugs[bug_number]
|
||||
except HTTPError, error:
|
||||
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)
|
||||
continue
|
||||
else:
|
||||
@ -104,11 +113,12 @@ if __name__ == '__main__':
|
||||
dups = bug.duplicates
|
||||
if dups is not None:
|
||||
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)
|
||||
|
||||
# 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:
|
||||
s = None
|
||||
@ -124,3 +134,5 @@ if __name__ == '__main__':
|
||||
bug.duplicate_of = new_main_bug
|
||||
bug.lp_save()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user