/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/generate_release_notes.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:
20
20
import sys
21
21
from optparse import OptionParser
22
22
 
23
 
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
24
 
 
25
23
 
26
24
def split_into_topics(lines, out_file, out_dir):
27
25
    """Split a large NEWS file into topics, one per release.
32
30
    """
33
31
    topic_file = None
34
32
    for index, line in enumerate(lines):
35
 
        maybe_new_topic = line[:4] in ['bzr ', 'bzr-0',]
 
33
        maybe_new_topic = line[:4] in ('bzr ', 'bzr-',)
36
34
        if maybe_new_topic and lines[index + 1].startswith('####'):
37
35
            release = line.strip()
38
36
            if topic_file is None:
45
43
        elif topic_file:
46
44
            topic_file.write(line)
47
45
        else:
 
46
            # FIXME: the 'content' directive is used for rst2html (and
 
47
            # conflicts with the 'toctree' we insert), we should get rid of
 
48
            # that once we fully switch to sphinx -- vila 20100505
 
49
            if (line.startswith('.. contents::')
 
50
                or line.startswith('   :depth:')):
 
51
                    continue
48
52
            # Still in the header - dump content straight to output
49
53
            out_file.write(line)
 
54
    if topic_file is not None:
 
55
        # Close the last topic_file opened
 
56
        topic_file.close()
50
57
 
51
58
 
52
59
def open_topic_file(out_file, out_dir, release):
53
60
    topic_name = release.replace(' ', '-')
54
 
    out_file.write("   %s\n" % (topic_name,))
 
61
    out_file.write("   %s <%s>\n" % (release, topic_name,))
55
62
    topic_path = os.path.join(out_dir, "%s.txt" % (topic_name,))
56
63
    result = open(topic_path, 'w')
57
64
    result.write("%s\n" % (release,))