summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2010-02-15 15:07:24 +0100
committerKarel Klic <kklic@redhat.com>2010-02-15 15:07:24 +0100
commitba32bbb864eec78e0d17f5a75fc3a58d5762d04a (patch)
tree529f7b142d1c727eeff82494ba0c04796cf9b30e
parent55ef6d8102047344f170dcb1202a117302ae3768 (diff)
downloadabrt-ba32bbb864eec78e0d17f5a75fc3a58d5762d04a.tar.gz
abrt-ba32bbb864eec78e0d17f5a75fc3a58d5762d04a.tar.xz
abrt-ba32bbb864eec78e0d17f5a75fc3a58d5762d04a.zip
Added option to close bugs recognized as a duplicate: --close
-rwxr-xr-xsrc/Backtrace/abrt-bz-dupchecker79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/Backtrace/abrt-bz-dupchecker b/src/Backtrace/abrt-bz-dupchecker
index d7798acb..dc2ef8ea 100755
--- a/src/Backtrace/abrt-bz-dupchecker
+++ b/src/Backtrace/abrt-bz-dupchecker
@@ -33,10 +33,12 @@ parser.add_option("-u", "--user", dest="user",
help="Bugzilla user name (REQUIRED)", metavar="USERNAME")
parser.add_option("-p", "--password", dest="password",
help="Bugzilla password (REQUIRED)", metavar="PASSWORD")
-parser.add_option("-b", "--bugzilla", dest="bugzilla",
+parser.add_option("-b", "--bugzilla", dest="bugzilla", default="https://bugzilla.redhat.com/xmlrpc.cgi",
help="Bugzilla URL (defaults to Red Hat Bugzilla)", metavar="URL")
parser.add_option("-v", "--verbose", dest="verbose",
help="Detailed output")
+parser.add_option("-c", "--close", help="Close some of the bugs in Bugzilla (DANGEROUS)",
+ action="store_true", default=False, dest="close")
parser.add_option("-i", "--wiki", help="Generate output in wiki syntax",
action="store_true", default=False, dest="wiki")
@@ -48,9 +50,6 @@ if not options.user or len(options.user) == 0:
if not options.password or len(options.password) == 0:
parser.error("Password is required.\nTry {0} --help".format(sys.argv[0]))
-if not options.bugzilla or len(options.bugzilla) == 0:
- options.bugzilla = "https://bugzilla.redhat.com/xmlrpc.cgi"
-
bz = RHBugzilla()
bz.connect(options.bugzilla)
bz.login(options.user, options.password)
@@ -155,8 +154,6 @@ for buginfo in buginfos:
else:
database[backtrace] = { buginfo.component: [ bugitem ] }
-bz.logout()
-
# The number of duplicates.
dupcount = 0
# The number of duplicates that can be closed.
@@ -168,26 +165,67 @@ for backtrace, components in database.items():
map(lambda x: x["comments"],
bugitems))),
len(bugitems) - 1)
-
+
+# Get the component owner.
# Sort the duplicates by the component owner, and
# filter out those which should not be printed.
dups = []
for backtrace, components in database.items():
for component, bugitems in components.items():
- if len(bugitems) > 1:
- # Get the component owner
- owner = "Failed to get component owner"
- try:
- component_info = json.load(urllib.urlopen("https://admin.fedoraproject.org/pkgdb/packages/name/{0}?tg_format=json".format(component)))
- component_packages = component_info['packageListings']
- component_f12 = filter(lambda x:x["collection"]["version"]=="12", component_packages)
- if len(component_f12) == 1:
- owner = component_f12[0]["owner"]
- except KeyError:
- pass
+ if len(bugitems) <= 1:
+ continue
+
+ # Get the component owner
+ owner = "Failed to get component owner"
+ try:
+ component_info = json.load(urllib.urlopen("https://admin.fedoraproject.org/pkgdb/packages/name/{0}?tg_format=json".format(component)))
+ component_packages = component_info['packageListings']
+ component_f12 = filter(lambda x:x["collection"]["version"]=="12", component_packages)
+ if len(component_f12) == 1:
+ owner = component_f12[0]["owner"]
+ except KeyError:
+ pass
- dups.append((component, owner, bugitems, backtrace))
- print ".",
+ dups.append((component, owner, bugitems, backtrace))
+ print "."
+
+# Close all bugs where it is appropriate.
+if options.close:
+ for (component, owner, bugitems, backtrace) in dups:
+ # Find the master bug item
+ # Its the one with the most comments.
+
+ # Sort function sorting by comment count.
+ def commentCmp(x, y):
+ if x['comments'] < y['comments']:
+ return 1
+ elif x['comments'] == y['comments']:
+ # Sort by bug id, older bugs should became the master bug
+ if x['id'] > y['id']:
+ return 1
+ elif x['id'] == y['id']:
+ return 0
+ else:
+ return -1
+ else:
+ return -1
+
+ sorteditems = sorted(bugitems, commentCmp)
+
+ master = sorteditems[0]
+ for item in sorteditems[1:]:
+ if item['comments'] > 2:
+ continue
+
+ print "Closing bug #{0} with {1} comments as a duplicate of #{2}.".format(item['id'], item['comments'], master['id'])
+ bug = bz.getbug(int(item['id']))
+ bug.close("DUPLICATE", int(master['id']), "",
+ "This bug appears to have been filled using a buggy version of ABRT, because\n" +
+ "it contains a backtrace which is considered as a duplicate of the backtrace in #{0}." +
+ "Sorry for the inconvenience.\n\n" +
+ "Closing as a duplicate of #{0}.".format(master['id']))
+
+bz.logout()
print
print "SUMMARY"
@@ -204,6 +242,7 @@ def cmp(x, y):
return 0
else:
return 1
+
for (component, owner, bugitems, backtrace) in sorted(dups, cmp):
if options.wiki:
print "----"