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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/usr/bin/python
from lpltk import LaunchpadService
from operator import itemgetter
import datetime
import optparse
def process_tasks(recent_tasks):
packages = {}
for task in recent_tasks:
src_pkg = task.bug_target_name.split(' ')[0]
if src_pkg == 'ubuntu':
continue
packages[src_pkg] = packages.setdefault(src_pkg, 0) + 1
return packages
if __name__ == '__main__':
lp = LaunchpadService(config={'read_only':True})
ubuntu = lp.load_project('ubuntu')
parser = optparse.OptionParser()
parser.add_option("--within", help="Filter on bugs reported within \
X day(s)")
parser.add_option("--limit", help="Number of packages to return")
parser.add_option("--team", help="Team name")
(opt, args) = parser.parse_args()
today = datetime.datetime.utcnow()
periods = opt.within.split(',')
print '<html>'
print '<title>Packages subscribed to by %s receiving the most new bugs</title>' % (opt.team)
print '<body>'
print '<h2>Packages subscribed to by %s receiving the most new bugs</h2>' % (opt.team)
for period in periods:
total_created = 0
target_date = today - datetime.timedelta(int(period))
if opt.team:
team = lp.launchpad.people[opt.team]
recent_tasks = ubuntu.searchTasks(created_since=target_date,
bug_supervisor=team)
pkg_freq = process_tasks(recent_tasks)
for pkg in pkg_freq:
total_created += pkg_freq[pkg]
median_created = (total_created/len(pkg_freq))
if int(period) == 1:
print 'Within the past %s day' % period
else:
print 'Within the past %s days' % period
print '<table>'
if opt.limit:
print '<th>Package</th><th>Quantity</th>\n'
limit = int(opt.limit)
for k, v in sorted(freq.items(), key=itemgetter(1), reverse=True)[:limit]:
print '<tr><td><a href="https://bugs.launchpad.net/ubuntu/+source/%s/+bugs?field.searchtext=&orderby=-datecreated&search=Search&field.status:list=NEW">%s</a></td><td align="right">%s</td></tr>\n' % (k, k, v)
else:
print '<th>Package</th><th>Quantity</th><th>Amount over median</th>\n'
for k, v in sorted(pkg_freq.items(), key=itemgetter(1), reverse=True):
if v <= median_created:
break
print '<tr><td><a href="https://bugs.launchpad.net/ubuntu/+source/%s/+bugs?field.searchtext=&orderby=-datecreated&search=Search&field.status:list=NEW">%s</a></td><td align="right">%d</td><td align="right">+%d</td></tr>\n' % (k, k, v, (v-median_created))
print '</table>'
print '<br>'
print '</body>'
print '</html>'
|