~debian-lptools/debian/sid/lptools/sid

« back to all changes in this revision

Viewing changes to bin/lp-capture-bug-counts

  • Committer: Jelmer Vernooij
  • Date: 2023-09-28 12:07:22 UTC
  • mfrom: (2.18.8)
  • Revision ID: jelmer@jelmer.uk-20230928120722-704pws90v7e943dk
* New upstream snapshot.
 + Drop patches for conversion to python 3 and breezy; now merged upstream.
+ debian/upstream/metadata: Drop unknown Homepage field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python3
 
2
 
 
3
import sys
 
4
 
 
5
from lptools import config
 
6
 
 
7
project_name = 'bzr'
 
8
 
 
9
 
 
10
def 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
 
 
17
class 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
 
 
33
class 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
 
 
44
class 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
 
 
58
class 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
 
 
79
class 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
 
 
95
class 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 list(by_status.values())
 
107
 
 
108
 
 
109
def show_bug_report(project):
 
110
    for query_class in StatusCannedQuery, PatchCannedQuery:
 
111
        query_class(project).show_text()
 
112
 
 
113
 
 
114
launchpad = config.get_launchpad("capture-bug-counts")
 
115
project = get_project()
 
116
show_bug_report(project)