/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

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
import getopt, re, sys
6
6
try:
7
 
    from launchpadbugs import connector
8
 
except ImportError:
9
 
    print "Please install launchpadbugs from lp:python-launchpad-bugs"
10
 
    sys.exit(1)
 
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:launchpadlib"
 
16
    sys.exit(1)
 
17
 
11
18
 
12
19
options, args = getopt.gnu_getopt(sys.argv, "l", ["launchpad"])
13
20
options = dict(options)
22
29
 
23
30
def report_notmarked(bug, task, section):
24
31
    print 
25
 
    print "Bug %d was mentioned in NEWS but is not marked fix released:" % (bug.bugnumber, )
 
32
    print "Bug %d was mentioned in NEWS but is not marked fix released:" % (bug.id, )
26
33
    print "Launchpad title: %s" % bug.title
27
34
    print "NEWS summary: "
28
35
    print section
29
36
    if "--launchpad" in options or "-l" in options:
30
 
        print "  bug %d" % bug.bugnumber
31
 
        print "  affects bzr"
 
37
        print "  bug %d" % bug.id
 
38
        print "  affects %s" % task.bug_target_name
32
39
        print "  status fixreleased"
33
40
 
34
41
 
60
67
    finally:
61
68
        f.close()
62
69
 
63
 
open_bug = connector.ConnectBug("TEXT")
64
 
 
 
70
 
 
71
def print_bug_url(bugno):
 
72
    print '<URL:http://pad.lv/%s>' % (bugno,)
 
73
 
 
74
launchpad = hydrazine.create_session()
65
75
bugnos = read_news_bugnos(args[1])
66
76
for bugno, section in bugnos:
67
 
    bug = open_bug(url="https://bugs.launchpad.net/bzr/+bug/%d" % bugno)
 
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
 
86
     
68
87
    found_bzr = False
69
 
    for task in bug.infotable:
70
 
        if task.affects == "bzr":
 
88
    fix_released = False
 
89
    for task in bug.bug_tasks:
 
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":
71
98
            found_bzr = True
72
 
            if task.status != "Fix Released":
73
 
                report_notmarked(bug, task, section)
 
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
 
74
104
    if not found_bzr:
 
105
        print_bug_url(bugno)
75
106
        print "Bug %d was mentioned in NEWS but is not marked as affecting bzr" % bugno
 
107
    elif not fix_released:
 
108
        print_bug_url(bugno)
 
109
        report_notmarked(bug, task, section)