~bzr-pqm/bzr/bzr.dev

3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
1
#!/usr/bin/python
2
# Simple script that will check which bugs mentioned in NEWS 
3
# are not yet marked Fix Released in Launchpad
4
5
import getopt, re, sys
6
try:
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
7
    from launchpadlib.launchpad import Launchpad
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
8
    from lazr.restfulclient import errors
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
9
except ImportError:
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
10
    print "Please install launchpadlib from lp:launchpadlib"
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
11
    sys.exit(1)
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
12
try:
13
    import hydrazine
14
except ImportError:
5555.1.1 by Vincent Ladeuil
Release 2.3b4
15
    print "Please install hydrazine from lp:hydrazine"
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
16
    sys.exit(1)
17
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
18
19
options, args = getopt.gnu_getopt(sys.argv, "l", ["launchpad"])
20
options = dict(options)
21
22
if len(args) == 1:
23
    print "Usage: check-newsbugs [--launchpad] NEWS"
24
    print "Options:"
25
    print "--launchpad     Print out Launchpad mail commands for closing bugs "
26
    print "                that are already fixed."
27
    sys.exit(1)
28
29
30
def report_notmarked(bug, task, section):
5552.1.3 by Vincent Ladeuil
Merge 2.2 into 2.3 including fixes for bug #583667 and bug #681885
31
    print
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
32
    print "Bug %d was mentioned in NEWS but is not marked fix released:" % (bug.id, )
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
33
    print "Launchpad title: %s" % bug.title
34
    print "NEWS summary: "
35
    print section
36
    if "--launchpad" in options or "-l" in options:
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
37
        print "  bug %d" % bug.id
38
        print "  affects %s" % task.bug_target_name
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
39
        print "  status fixreleased"
40
41
42
def read_news_bugnos(path):
43
    """Read the bug numbers closed by a particular NEWS file
44
45
    :param path: Path to the NEWS file
46
    :return: list of bug numbers that were closed.
47
    """
48
    # Pattern to find bug numbers
49
    bug_pattern = re.compile("\#([0-9]+)")
50
    ret = set()
51
    f = open(path, 'r')
52
    try:
53
        section = ""
54
        for l in f.readlines():
55
            if l.strip() == "":
56
                try:
57
                    parenthesed = section.rsplit("(", 1)[1]
58
                except IndexError:
59
                    parenthesed = ""
60
                # Empty line, next section begins
61
                for bugno in [int(m) for m in bug_pattern.findall(parenthesed)]:
62
                    ret.add((bugno, section))
63
                section = ""
64
            else:
65
                section += l
66
        return ret
67
    finally:
68
        f.close()
69
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
70
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
71
def print_bug_url(bugno):
72
    print '<URL:http://pad.lv/%s>' % (bugno,)
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
73
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
74
launchpad = hydrazine.create_session()
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
75
bugnos = read_news_bugnos(args[1])
76
for bugno, section in bugnos:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
77
    try:
78
        bug = launchpad.bugs[bugno]
79
    except errors.HTTPError, e:
80
        if e.response.status == 401:
81
            print_bug_url(bugno)
82
            # Private, we can't access the bug content
83
            print '%s is private and cannot be accessed' % (bugno,)
84
            continue
85
        raise
5552.1.3 by Vincent Ladeuil
Merge 2.2 into 2.3 including fixes for bug #583667 and bug #681885
86
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
87
    found_bzr = False
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
88
    fix_released = False
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
89
    for task in bug.bug_tasks:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
90
        parts = task.bug_target_name.split('/')
91
        if len(parts) == 1:
92
            project = parts[0]
93
            distribution = None
94
        else:
95
            project = parts[0]
96
            distribution = parts[1]
97
        if project == "bzr":
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
98
            found_bzr = True
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
99
            if not fix_released and task.status == "Fix Released":
100
                # We could check that the NEWS section and task_status are in
101
                # sync, but that would be overkill. (case at hand: bug #416732)
102
                fix_released = True
103
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
104
    if not found_bzr:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
105
        print_bug_url(bugno)
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
106
        print "Bug %d was mentioned in NEWS but is not marked as affecting bzr" % bugno
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
107
    elif not fix_released:
108
        print_bug_url(bugno)
109
        report_notmarked(bug, task, section)