~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
5853.4.3 by Vincent Ladeuil
Add an option to check-newsbug to get a quicker access to bugs that needs to be closed.
19
options, args = getopt.gnu_getopt(sys.argv, "lw", ["launchpad", 'webbrowser'])
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
20
options = dict(options)
21
22
if len(args) == 1:
5853.4.3 by Vincent Ladeuil
Add an option to check-newsbug to get a quicker access to bugs that needs to be closed.
23
    print ("Usage: check-newsbugs [--launchpad][--webbrowser] "
24
           "doc/en/release-notes/bzr-x.y.txt")
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
25
    print "Options:"
26
    print "--launchpad     Print out Launchpad mail commands for closing bugs "
27
    print "                that are already fixed."
5853.4.3 by Vincent Ladeuil
Add an option to check-newsbug to get a quicker access to bugs that needs to be closed.
28
    print "--webbrowser    Open launchpad bug pages for bugs that are already "
29
    print "                fixed."
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
30
    sys.exit(1)
31
32
33
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
34
    print
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
35
    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.
36
    print "Launchpad title: %s" % bug.title
37
    print "NEWS summary: "
38
    print section
39
    if "--launchpad" in options or "-l" in options:
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
40
        print "  bug %d" % bug.id
41
        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.
42
        print "  status fixreleased"
5853.4.3 by Vincent Ladeuil
Add an option to check-newsbug to get a quicker access to bugs that needs to be closed.
43
    if "--webbrowser" in options or "-w" in options:
44
        import webbrowser
45
        webbrowser.open('http://pad.lv/%s>' % (bug.id,))
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
46
47
48
def read_news_bugnos(path):
49
    """Read the bug numbers closed by a particular NEWS file
50
51
    :param path: Path to the NEWS file
52
    :return: list of bug numbers that were closed.
53
    """
54
    # Pattern to find bug numbers
55
    bug_pattern = re.compile("\#([0-9]+)")
56
    ret = set()
57
    f = open(path, 'r')
58
    try:
59
        section = ""
60
        for l in f.readlines():
61
            if l.strip() == "":
62
                try:
63
                    parenthesed = section.rsplit("(", 1)[1]
64
                except IndexError:
65
                    parenthesed = ""
66
                # Empty line, next section begins
67
                for bugno in [int(m) for m in bug_pattern.findall(parenthesed)]:
68
                    ret.add((bugno, section))
69
                section = ""
70
            else:
71
                section += l
72
        return ret
73
    finally:
74
        f.close()
75
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
76
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
77
def print_bug_url(bugno):
78
    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.
79
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
80
launchpad = hydrazine.create_session()
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
81
bugnos = read_news_bugnos(args[1])
82
for bugno, section in bugnos:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
83
    try:
84
        bug = launchpad.bugs[bugno]
85
    except errors.HTTPError, e:
86
        if e.response.status == 401:
87
            print_bug_url(bugno)
88
            # Private, we can't access the bug content
89
            print '%s is private and cannot be accessed' % (bugno,)
90
            continue
91
        raise
5552.1.3 by Vincent Ladeuil
Merge 2.2 into 2.3 including fixes for bug #583667 and bug #681885
92
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
93
    found_bzr = False
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
94
    fix_released = False
5274.1.1 by Jelmer Vernooij
Convert check-newsbugs.py to launchpadlib.
95
    for task in bug.bug_tasks:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
96
        parts = task.bug_target_name.split('/')
97
        if len(parts) == 1:
98
            project = parts[0]
99
            distribution = None
100
        else:
101
            project = parts[0]
102
            distribution = parts[1]
103
        if project == "bzr":
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
104
            found_bzr = True
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
105
            if not fix_released and task.status == "Fix Released":
106
                # We could check that the NEWS section and task_status are in
107
                # sync, but that would be overkill. (case at hand: bug #416732)
108
                fix_released = True
109
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
110
    if not found_bzr:
5430.4.1 by Vincent Ladeuil
Tiny doc cleanups and tweaks for tools/check-newsbugs.py.
111
        print_bug_url(bugno)
3966.2.4 by Jelmer Vernooij
Add simple script for checking that all bugs in NEWS are closed in launchpad.
112
        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.
113
    elif not fix_released:
114
        print_bug_url(bugno)
115
        report_notmarked(bug, task, section)