/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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/python3
2
2
 
3
3
# Copyright 2009-2010 Canonical Ltd.
4
4
#
19
19
"""Generate doc/en/release-notes/index.txt from the per-series NEWS files.
20
20
 
21
21
NEWS files are kept in doc/en/release-notes/, one file per series, e.g.
22
 
doc/en/release-notes/bzr-2.3.txt
 
22
doc/en/release-notes/brz-2.3.txt
23
23
"""
24
24
 
25
 
# XXX: add test_source test that latest doc/en/release-notes/bzr-*.txt has the
 
25
# XXX: add test_source test that latest doc/en/release-notes/brz-*.txt has the
26
26
# NEWS file-id (so that merges of new work will tend to always land new NEWS
27
27
# entries in the latest series).
28
28
 
35
35
 
36
36
preamble_plain = """\
37
37
####################
38
 
Bazaar Release Notes
 
38
Breezy Release Notes
39
39
####################
40
40
 
41
41
 
46
46
 
47
47
preamble_sphinx = """\
48
48
####################
49
 
Bazaar Release Notes
 
49
Breezy Release Notes
50
50
####################
51
51
 
52
52
 
58
58
 
59
59
def natural_sort_key(file_name):
60
60
    """Split 'aaa-N.MMbbb' into ('aaa-', N, '.' MM, 'bbb')
61
 
    
 
61
 
62
62
    e.g. 1.10b1 will sort as greater than 1.2::
63
63
 
64
 
        >>> natural_sort_key('bzr-1.10b1.txt') > natural_sort_key('bzr-1.2.txt')
 
64
        >>> natural_sort_key('brz-1.10b1.txt') > natural_sort_key('brz-1.2.txt')
65
65
        True
66
66
    """
67
67
    file_name = os.path.basename(file_name)
86
86
 
87
87
 
88
88
def output_news_file_plain(out_file, news_file_name):
89
 
    f = open(news_file_name, 'rb')
90
 
    try:
 
89
    with open(news_file_name, 'r') as f:
91
90
        lines = f.readlines()
92
 
    finally:
93
 
        f.close()
94
 
    title = os.path.basename(news_file_name)[len('bzr-'):-len('.txt')]
 
91
    title = os.path.basename(news_file_name)[len('brz-'):-len('.txt')]
95
92
    for line in lines:
96
93
        if line == '####################\n':
97
94
            line = '#' * len(title) + '\n'
98
 
        elif line == 'Bazaar Release Notes\n':
 
95
        elif line == 'Breezy Release Notes\n':
99
96
            line = title + '\n'
100
97
        elif line == '.. toctree::\n':
101
98
            continue
124
121
        preamble = preamble_plain
125
122
        output_news_file = output_news_file_plain
126
123
 
127
 
    out_file = open(out_file_name, 'w')
128
 
    try:
 
124
    with open(out_file_name, 'w') as out_file:
129
125
        out_file.write(preamble)
130
126
        for news_file_name in news_file_names:
131
127
            output_news_file(out_file, news_file_name)
132
 
    finally:
133
 
        out_file.close()
134
128
 
135
129
 
136
130
if __name__ == '__main__':