summaryrefslogtreecommitdiffstats
path: root/src/Backtrace
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2010-02-07 17:20:15 +0100
committerKarel Klic <kklic@redhat.com>2010-02-07 17:20:15 +0100
commit7ac55cf99fbbc974c6f37f3287c5897f68da0fc1 (patch)
tree92cb758ad18cb1ee3fac9a80134eb3c01808b358 /src/Backtrace
parent1e76e071620e1f9bf110dacf3cf8caffccef324b (diff)
downloadabrt-7ac55cf99fbbc974c6f37f3287c5897f68da0fc1.tar.gz
abrt-7ac55cf99fbbc974c6f37f3287c5897f68da0fc1.tar.xz
abrt-7ac55cf99fbbc974c6f37f3287c5897f68da0fc1.zip
+wiki output, +caching, +faster pickling
Diffstat (limited to 'src/Backtrace')
-rwxr-xr-xsrc/Backtrace/abrt-bz-dupchecker69
1 files changed, 59 insertions, 10 deletions
diff --git a/src/Backtrace/abrt-bz-dupchecker b/src/Backtrace/abrt-bz-dupchecker
index 344d1326..cbdafc53 100755
--- a/src/Backtrace/abrt-bz-dupchecker
+++ b/src/Backtrace/abrt-bz-dupchecker
@@ -24,6 +24,7 @@ from optparse import OptionParser
import sys
import os.path
import subprocess
+import cPickle
parser = OptionParser(version="%prog 1.0")
parser.add_option("-u", "--user", dest="user",
@@ -34,6 +35,8 @@ parser.add_option("-b", "--bugzilla", dest="bugzilla",
help="Bugzilla URL (defaults to Red Hat Bugzilla)", metavar="URL")
parser.add_option("-v", "--verbose", dest="verbose",
help="Detailed output")
+parser.add_option("-i", "--wiki", help="Generate output in wiki syntax",
+ action="store_true", default=False, dest="wiki")
(options, args) = parser.parse_args()
@@ -54,9 +57,38 @@ buginfos = bz.query({'status_whiteboard_type':'allwordssubstr','status_whiteboar
print "{0} bugs found.".format(len(buginfos))
+#
+# Load cache from previous run. Speeds up the case Bugzilla closes connection.
+# The cache should be manually removed after a day or so, because the data in it
+# are no longer valid.
+#
database = {}
-
+ids = {}
+CACHE_FILE = "abrt-bz-dupchecker-cache.tmp"
+if os.path.isfile(CACHE_FILE):
+ f = open(CACHE_FILE, 'r')
+ database = cPickle.load(f)
+ ids = cPickle.load(f)
+ f.close()
+
+def save_to_cache():
+ global database
+ f = open(CACHE_FILE, 'w')
+ cPickle.dump(database, f, 2)
+ cPickle.dump(ids, f, 2)
+ f.close()
+
+count = 0
for buginfo in buginfos:
+ count += 1
+ print "{0}/{1}".format(count, len(buginfos))
+ if count % 100 == 0:
+ save_to_cache()
+
+ if ids.has_key(buginfo.bug_id):
+ continue
+ ids[buginfo.bug_id] = True
+
if not buginfo.bug_status in ["NEW", "ASSIGNED", "MODIFIED", "VERIFIED"]:
if options.verbose:
print "Bug {0} has status {1}, skipping.".format(buginfo.bug_id, buginfo.bug_status)
@@ -127,21 +159,38 @@ print "=========================================================================
# The number of duplicates.
dupcount = 0
+# The number of duplicates that can be closed.
+dupclosecount = 0
for backtrace, components in database.items():
for component, bugitems in components.items():
- if len(bugitems) > 1:
- dupcount += len(bugitems) - 1
-
+ dupcount += len(bugitems) - 1
+ dupclosecount += min(len(filter(lambda x: x <= 2,
+ map(lambda x: x["comments"],
+ bugitems))),
+ len(bugitems) - 1)
+
print "Total number of duplicate bugs detected: {0}".format(dupcount)
+print "Number of duplicate bugs that will be closed : {0}".format(dupclosecount)
print "------------------------------"
# Print the duplicates
for backtrace, components in database.items():
for component, bugitems in components.items():
if len(bugitems) > 1:
- print "Component: {0}".format(component)
- print "Duplicates: {0}".format(
- reduce(lambda x,y: x+", "+y,
- map(lambda x: "{0} ({1})".format(x['id'],x['comments']),
- bugitems)))
- print "Backtrace: {0}".format(backtrace)
+ if options.wiki:
+ print "----"
+ print "* component: '''{0}'''".format(component)
+ print "* duplicates: {0}".format(
+ reduce(lambda x,y: x+", "+y,
+ map(lambda x: "#[https://bugzilla.redhat.com/show_bug.cgi?id={0} {0}] ({1} comments)".format(x['id'],x['comments']),
+ bugitems)))
+ print "* backtrace:"
+ for line in backtrace.replace("Thread\n", "").splitlines():
+ print "*# {0}".format(line)
+ else:
+ print "Component: {0}".format(component)
+ print "Duplicates: {0}".format(
+ reduce(lambda x,y: x+", "+y,
+ map(lambda x: "{0} ({1})".format(x['id'],x['comments']),
+ bugitems)))
+ print "Backtrace: {0}".format(backtrace)