~racb/apport/877852

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
#
# Author: Brian Murray <brian@canonical.com>
# Copyright (C) 2011 Canonical, Ltd.
# License: GPLv3
#
# Parse the bugpatterns.xml file and create a list of packages for which to
# search for bug reports for and consolidate duplicates.  This is necessary
# for previous releases of Ubuntu which will not check for the generic
# bugpatterns.xml file but rather for per package ones.  Additionally useful
# for cleaning up duplicates already reported in the event that pattern
# writers don't use search-bugs.
#
# It'd be better if the xml parsing routine determined if the ProblemType was
# a "Crash" or "Package" and then used search-bugs with the appropriate tags
# instead of just using apport-crash.

import xml.dom

from subprocess import *
from xml.dom.minidom import parseString

pattern_file = open('bugpatterns.xml')
data = pattern_file.read()
pattern_file.close()

dom = parseString(data)

packages = []

for pattern in dom.getElementsByTagName('pattern'):
    if not pattern.attributes.has_key('url'):
        continue

    for cn in pattern.childNodes:
        if cn.nodeType == xml.dom.Node.ELEMENT_NODE and cn.nodeName == 're' \
            and cn.attributes.has_key('key'):
            key = cn.attributes['key'].nodeValue
            if key == 'PackageVersion':
                continue
            if key != 'SourcePackage' and key != 'Package':
                continue
            if cn.hasChildNodes() and \
                cn.childNodes[0].nodeType == xml.dom.Node.TEXT_NODE:
                package = cn.childNodes[0].nodeValue.encode('UTF-8')
                package = package.replace('^', '')
                package = package.strip()
                if package not in packages:
                    packages.append(package)

for package in packages:
    print 'search-bugs --package %s --tags apport-crash --within 2 -C' % \
        package
    results = Popen(['./search-bugs','--package', '%s' % package, '--tags',
        'apport-crash', '--within', '2', '-C'], stdout=PIPE).communicate()[0]
    print results
    # need to do apport-bug bugs too
    print 'search-bugs --package %s --tags apport-bug --within 2 -C' % \
        package
    results = Popen(['./search-bugs','--package', '%s' % package, '--tags',
        'apport-bug', '--within', '2', '-C'], stdout=PIPE).communicate()[0]
    print results