~apw/arsenal/kernel

« back to all changes in this revision

Viewing changes to contrib/linux/series-tag.py

  • Committer: Andy Whitcroft
  • Date: 2010-01-26 11:24:45 UTC
  • Revision ID: apw@canonical.com-20100126112445-3se412n9z3d64rk7
kernel: series-tag -- tag bugs to their series if unknown

Where we do not already have a series tag on a bug try and determine this
from any apport data we have and tag the bug appropriatly.

Signed-off-by: Andy Whitcroft <apw@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# The purpose of this script it to find and mark duplicates of bug 464552 
 
4
#
 
5
 
 
6
from arsenal_lib import *
 
7
import sys
 
8
 
 
9
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
 
10
 
 
11
#end = int(sys.argv[1])
 
12
 
 
13
arsenal = Arsenal()
 
14
distro = arsenal.load_project("ubuntu")
 
15
opt_dryrun = True
 
16
 
 
17
linux = distro.getSourcePackage(name="linux")
 
18
#linux = distro.getSourcePackage(name="alsa-driver")
 
19
#linux = distro.getSourcePackage(name="pulseaudio")
 
20
collection = linux.searchTasks(order_by="-id")[:500]
 
21
#collection = linux.searchTasks(order_by="-id", status="New")
 
22
 
 
23
count = 0
 
24
ttl_count = 0
 
25
 
 
26
unknown = 'kernel-series-unknown'
 
27
mapping = {
 
28
    '10.04':    'lucid',
 
29
    '9.10':     'karmic',
 
30
    '9.04':     'jaunty',
 
31
    '8.10':     'intrepid',
 
32
    '8.04':     'hardy'
 
33
}
 
34
alltags = mapping.values()
 
35
#alltags.append(unknown)
 
36
 
 
37
kernel_mapping = {
 
38
    '2.6.32':   '10.04',
 
39
    '2.6.31':   '9.10',
 
40
    '2.6.28':   '9.04',
 
41
    '2.6.27':   '8.10',
 
42
    '2.6.24':   '9.04'
 
43
}
 
44
 
 
45
re_distro = re.compile("\nDistroRelease: Ubuntu (.*)\n");
 
46
re_uname = re.compile("\nUname: Linux (\S+)-\d+-\S+ \S+\n");
 
47
re_binary = re.compile("\nBinary package hint: linux\S+-(\d+\.\d+\.\d+)");
 
48
for bug_task in collection:
 
49
#        if bug_task.bug.id != 486643:
 
50
#            continue
 
51
 
 
52
        #print count, "/", ttl_count
 
53
        ttl_count += 1
 
54
        bug = ArsenalBug(bug_task.bug, arsenal.launchpad)
 
55
 
 
56
#        print "{0} checking {1}".format(bug.id, end)
 
57
#        if bug.id == end:
 
58
#            print "DONE"
 
59
#            sys.exit(0)
 
60
 
 
61
        # If we have a valid version tag then trust it, do not change it.
 
62
        tagged = None
 
63
        for tag in alltags:
 
64
            if bug.has_tag(tag):
 
65
                tagged = tag
 
66
                break
 
67
            if bug.has_tag("kernel-" + tag):
 
68
                tagged = tag
 
69
                break
 
70
        if tagged:
 
71
            print "{0} already tagged {1}".format(bug.id, tagged)
 
72
            if tagged != unknown and bug.has_tag(unknown):
 
73
                print "{0} removing {1}".format(bug.id, unknown)
 
74
                bug.remove_tag(unknown)
 
75
            if tagged == 'lucid' and bug.has_tag("kernel-lucid"):
 
76
                bug.append_tag("lucid")
 
77
                bug.remove_tag("kernel-lucid")
 
78
            continue
 
79
 
 
80
        desc = bug.description.decode("utf-8")
 
81
        desc = "\n" + desc + "\n"
 
82
 
 
83
        # Scan DistroRelease: for distro version
 
84
        distro = None
 
85
        m = re_distro.search(desc)
 
86
        if m:
 
87
            distro = m.group(1)
 
88
            print "{0} distro {1}".format(bug.id, distro)
 
89
 
 
90
        # Scan Uname: for kernel version
 
91
        kernel = None
 
92
        m = re_uname.search(desc)
 
93
        if m:
 
94
            kernel = m.group(1)
 
95
            print "{0} has uname {1}".format(bug.id, kernel)
 
96
 
 
97
        # Scan Binary package hint: for kernel version
 
98
        if not distro and not kernel:
 
99
            m = re_binary.search(desc)
 
100
            if m:
 
101
                kernel = m.group(1)
 
102
                print "{0} has binary hint {1}".format(bug.id, kernel)
 
103
 
 
104
        # Convert version to a distro if we have no distro
 
105
        if not distro and kernel:
 
106
            if kernel in kernel_mapping:
 
107
                distro = kernel_mapping[kernel]
 
108
                print "{0} distro {1} from version {2}".format(bug.id,
 
109
                    distro, kernel)
 
110
 
 
111
        # Check for apport data
 
112
        if not distro and bug.has_tag('apport-collected'):
 
113
            data = None
 
114
            for m in bug.bug.messages:
 
115
                if m.subject == 'apport-collect data':
 
116
                    data = m.content
 
117
                    break
 
118
            if data:
 
119
                m = re_distro.search(data)
 
120
                if m:
 
121
                    distro = m.group(1)
 
122
                    print "{0} distro {1} from apport data".format(bug.id, distro)
 
123
 
 
124
        tag = unknown
 
125
        if distro in mapping:
 
126
            tag = mapping[distro]
 
127
 
 
128
        if tag and not bug.has_tag(tag):
 
129
            print "{0} needs {1}".format(bug.id, tag)
 
130
            bug.append_tag(tag)
 
131
            if tag != unknown and bug.has_tag(unknown):
 
132
                print "{0} removing {1}".format(bug.id, unknown)
 
133
                bug.remove_tag(unknown)
 
134
        else:
 
135
            print "{0} already tagged {1}".format(bug.id, tag)
 
136
 
 
137
 
 
138
#        if not distro or not kernel:
 
139
#            print "{0} ? - -".format(bug.id)
 
140
#            continue
 
141
#
 
142
#        match = 'B'
 
143
#        if distro == '10.04':
 
144
#            if kernel == '2.6.32':
 
145
#                match = 'G'
 
146
#        if distro == '9.10':
 
147
#            if kernel == '2.6.31':
 
148
#                match = 'G'
 
149
#        elif distro == '9.04':
 
150
#            if kernel == '2.6.28':
 
151
#                match = 'G'
 
152
#        elif distro == '8.10':
 
153
#            if kernel == '2.6.27':
 
154
#                match = 'G'
 
155
#        else:
 
156
#            match = '?'
 
157
#
 
158
#        if match == 'B':
 
159
#            count += 1
 
160
#
 
161
#        print "{0} {1} {2} {3}".format(bug.id, match, distro, kernel)
 
162
 
 
163
print "{0} / {1}".format(count, ttl_count)