Merge lp:~jelmer/lptools/capture-bug-counts into lp:lptools

Proposed by Jelmer Vernooij
Status: Merged
Approved by: dobey
Approved revision: 40
Merged at revision: 41
Proposed branch: lp:~jelmer/lptools/capture-bug-counts
Merge into: lp:lptools
Diff against target: 120 lines (+116/-0)
1 file modified
bin/lp-capture-bug-counts (+116/-0)
To merge this branch: bzr merge lp:~jelmer/lptools/capture-bug-counts
Reviewer Review Type Date Requested Status
dobey Approve
Review via email: mp+100284@code.launchpad.net

Commit message

Import capture bug counts from hydrazine.

Description of the change

Import lp-capture-bug-counts tool from hydrazine.

This shows a summary of how many bugs there are for a particular project.

To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote :

Looks ok to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/lp-capture-bug-counts'
2--- bin/lp-capture-bug-counts 1970-01-01 00:00:00 +0000
3+++ bin/lp-capture-bug-counts 2012-03-31 13:10:24 +0000
4@@ -0,0 +1,116 @@
5+#! /usr/bin/python
6+
7+import sys
8+
9+from lptools import config
10+
11+project_name = 'bzr'
12+
13+
14+def get_project():
15+ sys.stderr.write('getting project... ')
16+ project = launchpad.projects[project_name]
17+ sys.stderr.write('%s (%s)\n' % (project.name, project.title))
18+ return project
19+
20+
21+class BugCategory(object):
22+ """Holds a set of logically-related bugs"""
23+
24+ def __init__(self):
25+ self.bugs = set()
26+
27+ def add(self, bt):
28+ self.bugs.add(bt)
29+
30+ def count_bugs(self):
31+ return len(self.bugs)
32+
33+ def get_link_url(self):
34+ return None
35+
36+
37+class HasPatchBugCategory(BugCategory):
38+
39+ def get_name(self):
40+ return 'HasPatch'
41+
42+ def get_link_url(self):
43+ return 'https://bugs.edge.launchpad.net/%s/+bugs' \
44+ '?search=Search&field.has_patch=on' \
45+ % (project_name)
46+
47+
48+class StatusBugCategory(BugCategory):
49+
50+ def __init__(self, status):
51+ BugCategory.__init__(self)
52+ self.status = status
53+
54+ def get_name(self):
55+ return self.status
56+
57+ def get_link_url(self):
58+ return 'https://bugs.edge.launchpad.net/%s/+bugs?search=Search&field.status=%s' \
59+ % (project_name, self.status)
60+
61+
62+class CannedQuery(object):
63+
64+ def __init__(self, project):
65+ self.project = project
66+
67+ def _run_query(self, from_collection):
68+ sys.stderr.write(self.get_name())
69+ for bt in from_collection:
70+ yield bt
71+ sys.stderr.write('.')
72+ sys.stderr.write('\n')
73+
74+ def show_text(self):
75+ # print self.get_name()
76+ for category in self.query_categories():
77+ print '%6d %s %s' % (category.count_bugs(),
78+ category.get_name(),
79+ category.get_link_url() or '')
80+ print
81+
82+
83+class PatchCannedQuery(CannedQuery):
84+
85+ def get_collection(self):
86+ return self.project.searchTasks(has_patch=True)
87+
88+ def get_name(self):
89+ return 'Bugs with patches'
90+
91+ def query_categories(self):
92+ has_patches = HasPatchBugCategory()
93+ for bt in self._run_query(
94+ self.project.searchTasks(has_patch=True)):
95+ has_patches.add(bt)
96+ return [has_patches]
97+
98+
99+class StatusCannedQuery(CannedQuery):
100+
101+ def get_name(self):
102+ return 'By Status'
103+
104+ def query_categories(self):
105+ by_status = {}
106+ for bugtask in self._run_query(self.project.searchTasks()):
107+ if bugtask.status not in by_status:
108+ by_status[bugtask.status] = StatusBugCategory(bugtask.status)
109+ by_status[bugtask.status].add(bugtask)
110+ return by_status.values()
111+
112+
113+def show_bug_report(project):
114+ for query_class in StatusCannedQuery, PatchCannedQuery:
115+ query_class(project).show_text()
116+
117+
118+launchpad = config.get_launchpad("capture-bug-counts")
119+project = get_project()
120+show_bug_report(project)

Subscribers

People subscribed via source and target branches