File: lp-capture-bug-counts

package info (click to toggle)
lptools 0.3.0-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 396 kB
  • sloc: python: 1,550; makefile: 6
file content (116 lines) | stat: -rwxr-xr-x 2,825 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /usr/bin/python3

import sys

from lptools import config

project_name = 'bzr'


def get_project():
    sys.stderr.write('getting project... ')
    project = launchpad.projects[project_name]
    sys.stderr.write('%s (%s)\n' % (project.name, project.title))
    return project


class BugCategory(object):
    """Holds a set of logically-related bugs"""

    def __init__(self):
        self.bugs = set()

    def add(self, bt):
        self.bugs.add(bt)

    def count_bugs(self):
        return len(self.bugs)

    def get_link_url(self):
        return None


class HasPatchBugCategory(BugCategory):

    def get_name(self):
        return 'HasPatch'

    def get_link_url(self):
        return 'https://bugs.edge.launchpad.net/%s/+bugs' \
            '?search=Search&field.has_patch=on' \
            % (project_name)


class StatusBugCategory(BugCategory):

    def __init__(self, status):
        BugCategory.__init__(self)
        self.status = status

    def get_name(self):
        return self.status

    def get_link_url(self):
        return 'https://bugs.edge.launchpad.net/%s/+bugs?search=Search&field.status=%s' \
            % (project_name, self.status)


class CannedQuery(object):

    def __init__(self, project):
        self.project = project

    def _run_query(self, from_collection):
        sys.stderr.write(self.get_name())
        for bt in from_collection:
            yield bt
            sys.stderr.write('.')
        sys.stderr.write('\n')

    def show_text(self):
        # print self.get_name()
        for category in self.query_categories():
            print('%6d %s %s' % (category.count_bugs(),
                category.get_name(),
                category.get_link_url() or ''))
        print()


class PatchCannedQuery(CannedQuery):

    def get_collection(self):
        return self.project.searchTasks(has_patch=True)

    def get_name(self):
        return 'Bugs with patches'

    def query_categories(self):
        has_patches = HasPatchBugCategory()
        for bt in self._run_query(
            self.project.searchTasks(has_patch=True)):
            has_patches.add(bt)
        return [has_patches]


class StatusCannedQuery(CannedQuery):

    def get_name(self):
        return 'By Status'

    def query_categories(self):
        by_status = {}
        for bugtask in self._run_query(self.project.searchTasks()):
            if bugtask.status not in by_status:
                by_status[bugtask.status] = StatusBugCategory(bugtask.status)
            by_status[bugtask.status].add(bugtask)
        return list(by_status.values())


def show_bug_report(project):
    for query_class in StatusCannedQuery, PatchCannedQuery:
        query_class(project).show_text()


launchpad = config.get_launchpad("capture-bug-counts")
project = get_project()
show_bug_report(project)