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

Subscribers

People subscribed via source and target branches