/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/check-newsbugs.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
# Simple script that will check which bugs mentioned in NEWS
 
1
#!/usr/bin/python
 
2
# Simple script that will check which bugs mentioned in NEWS 
3
3
# are not yet marked Fix Released in Launchpad
4
4
 
5
5
import getopt, re, sys
6
6
try:
7
 
    from launchpadlib.launchpad import Launchpad
8
 
    from lazr.restfulclient import errors
9
 
except ImportError:
10
 
    print("Please install launchpadlib from lp:launchpadlib")
11
 
    sys.exit(1)
12
 
try:
13
 
    import hydrazine
14
 
except ImportError:
15
 
    print("Please install hydrazine from lp:hydrazine")
16
 
    sys.exit(1)
17
 
 
18
 
 
19
 
options, args = getopt.gnu_getopt(sys.argv, "lw", ["launchpad", 'webbrowser'])
 
7
    from launchpadbugs import connector
 
8
except ImportError:
 
9
    print "Please install launchpadbugs from lp:python-launchpad-bugs"
 
10
    sys.exit(1)
 
11
 
 
12
options, args = getopt.gnu_getopt(sys.argv, "l", ["launchpad"])
20
13
options = dict(options)
21
14
 
22
15
if len(args) == 1:
23
 
    print("Usage: check-newsbugs [--launchpad][--webbrowser] "
24
 
          "doc/en/release-notes/brz-x.y.txt")
25
 
    print("Options:")
26
 
    print("--launchpad     Print out Launchpad mail commands for closing bugs ")
27
 
    print("                that are already fixed.")
28
 
    print("--webbrowser    Open launchpad bug pages for bugs that are already ")
29
 
    print("                fixed.")
 
16
    print "Usage: check-newsbugs [--launchpad] NEWS"
 
17
    print "Options:"
 
18
    print "--launchpad     Print out Launchpad mail commands for closing bugs "
 
19
    print "                that are already fixed."
30
20
    sys.exit(1)
31
21
 
32
22
 
33
23
def report_notmarked(bug, task, section):
34
 
    print()
35
 
    print("Bug %d was mentioned in NEWS but is not marked fix released:" % (bug.id, ))
36
 
    print("Launchpad title: %s" % bug.title)
37
 
    print("NEWS summary: ")
38
 
    print(section)
 
24
    print 
 
25
    print "Bug %d was mentioned in NEWS but is not marked fix released:" % (bug.bugnumber, )
 
26
    print "Launchpad title: %s" % bug.title
 
27
    print "NEWS summary: "
 
28
    print section
39
29
    if "--launchpad" in options or "-l" in options:
40
 
        print("  bug %d" % bug.id)
41
 
        print("  affects %s" % task.bug_target_name)
42
 
        print("  status fixreleased")
43
 
    if "--webbrowser" in options or "-w" in options:
44
 
        import webbrowser
45
 
        webbrowser.open('http://pad.lv/%s>' % (bug.id,))
 
30
        print "  bug %d" % bug.bugnumber
 
31
        print "  affects bzr"
 
32
        print "  status fixreleased"
46
33
 
47
34
 
48
35
def read_news_bugnos(path):
52
39
    :return: list of bug numbers that were closed.
53
40
    """
54
41
    # Pattern to find bug numbers
55
 
    bug_pattern = re.compile(r"\#([0-9]+)")
 
42
    bug_pattern = re.compile("\#([0-9]+)")
56
43
    ret = set()
57
 
    with open(path, 'r') as f:
 
44
    f = open(path, 'r')
 
45
    try:
58
46
        section = ""
59
47
        for l in f.readlines():
60
48
            if l.strip() == "":
69
57
            else:
70
58
                section += l
71
59
        return ret
72
 
 
73
 
 
74
 
def print_bug_url(bugno):
75
 
    print('<URL:http://pad.lv/%s>' % (bugno,))
76
 
 
77
 
launchpad = hydrazine.create_session()
 
60
    finally:
 
61
        f.close()
 
62
 
 
63
open_bug = connector.ConnectBug("TEXT")
 
64
 
78
65
bugnos = read_news_bugnos(args[1])
79
66
for bugno, section in bugnos:
80
 
    try:
81
 
        bug = launchpad.bugs[bugno]
82
 
    except errors.HTTPError as e:
83
 
        if e.response.status == 401:
84
 
            print_bug_url(bugno)
85
 
            # Private, we can't access the bug content
86
 
            print('%s is private and cannot be accessed' % (bugno,))
87
 
            continue
88
 
        raise
89
 
 
90
 
    found_brz = False
91
 
    fix_released = False
92
 
    for task in bug.bug_tasks:
93
 
        parts = task.bug_target_name.split('/')
94
 
        if len(parts) == 1:
95
 
            project = parts[0]
96
 
            distribution = None
97
 
        else:
98
 
            project = parts[0]
99
 
            distribution = parts[1]
100
 
        if project == "brz":
101
 
            found_brz = True
102
 
            if not fix_released and task.status == "Fix Released":
103
 
                # We could check that the NEWS section and task_status are in
104
 
                # sync, but that would be overkill. (case at hand: bug #416732)
105
 
                fix_released = True
106
 
 
107
 
    if not found_brz:
108
 
        print_bug_url(bugno)
109
 
        print("Bug %d was mentioned in NEWS but is not marked as affecting brz" % bugno)
110
 
    elif not fix_released:
111
 
        print_bug_url(bugno)
112
 
        report_notmarked(bug, task, section)
 
67
    bug = open_bug(url="https://bugs.launchpad.net/bzr/+bug/%d" % bugno)
 
68
    found_bzr = False
 
69
    for task in bug.infotable:
 
70
        if task.affects == "bzr":
 
71
            found_bzr = True
 
72
            if task.status != "Fix Released":
 
73
                report_notmarked(bug, task, section)
 
74
    if not found_bzr:
 
75
        print "Bug %d was mentioned in NEWS but is not marked as affecting bzr" % bugno