4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
1 |
#!/usr/bin/python
|
2 |
||
3 |
# Copyright 2009 Canonical Ltd.
|
|
4 |
#
|
|
5 |
# This program is free software; you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU General Public License as published by
|
|
7 |
# the Free Software Foundation; either version 2 of the License, or
|
|
8 |
# (at your option) any later version.
|
|
9 |
#
|
|
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
#
|
|
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
||
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
19 |
"""Generate doc/en/release-notes/index.txt from the per-series NEWS files.
|
20 |
||
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
|
|
23 |
"""
|
|
24 |
||
25 |
# XXX: add test_source test that latest doc/en/release-notes/bzr-*.txt has the
|
|
26 |
# NEWS file-id (so that merges of new work will tend to always land new NEWS
|
|
27 |
# entries in the latest series).
|
|
28 |
||
29 |
||
30 |
import os.path |
|
31 |
import re |
|
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
32 |
import sys |
33 |
from optparse import OptionParser |
|
34 |
||
35 |
||
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
36 |
preamble = """\ |
37 |
####################
|
|
38 |
Bazaar Release Notes
|
|
39 |
####################
|
|
40 |
||
41 |
||
42 |
.. toctree::
|
|
43 |
:maxdepth: 1
|
|
44 |
||
45 |
"""
|
|
46 |
||
47 |
||
48 |
def natural_sort_key(file_name): |
|
49 |
"""Split 'aaa-N.MMbbb' into ('aaa-', N, '.' MM, 'bbb')
|
|
50 |
|
|
51 |
e.g. 1.10b1 will sort as greater than 1.2::
|
|
52 |
||
53 |
>>> natural_sort_key('bzr-1.10b1.txt') > natural_sort_key('bzr-1.2.txt')
|
|
54 |
True
|
|
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
55 |
"""
|
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
56 |
parts = re.findall(r'(?:[0-9]+|[^0-9]+)', file_name) |
57 |
result = [] |
|
58 |
for part in parts: |
|
59 |
if re.match('^[0-9]+$', part) is not None: |
|
60 |
part = int(part) |
|
61 |
result.append(part) |
|
62 |
return tuple(result) |
|
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
63 |
|
64 |
||
65 |
def main(argv): |
|
66 |
# Check usage
|
|
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
67 |
parser = OptionParser(usage="%prog OUTPUT_FILE NEWS_FILE [NEWS_FILE ...]") |
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
68 |
(options, args) = parser.parse_args(argv) |
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
69 |
if len(args) < 2: |
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
70 |
parser.print_help() |
71 |
sys.exit(1) |
|
72 |
||
73 |
# Open the files and do the work
|
|
5462.5.1
by Andrew Bennetts
Split NEWS into per-release doc/en/release-notes/bzr-*.txt |
74 |
out_file_name = args[0] |
75 |
news_file_names = map(os.path.basename, args[1:]) |
|
76 |
news_file_names = sorted(news_file_names, key=natural_sort_key, |
|
77 |
reverse=True) |
|
78 |
||
79 |
out_file = open(out_file_name, 'w') |
|
80 |
try: |
|
81 |
out_file.write(preamble) |
|
82 |
for news_file_name in news_file_names: |
|
83 |
if not news_file_name.endswith('.txt'): |
|
84 |
raise AssertionError( |
|
85 |
'NEWS file %s does not have .txt extension.' |
|
86 |
% (news_file_name,)) |
|
87 |
doc_name = news_file_name[:-4] |
|
88 |
link_text = doc_name.replace('-', ' ') |
|
89 |
out_file.write(' %s <%s>\n' % (link_text, doc_name)) |
|
90 |
finally: |
|
91 |
out_file.close() |
|
4634.38.5
by Ian Clatworthy
Split Release Notes into topics so easier to navigate and print from chm & html |
92 |
|
93 |
||
94 |
if __name__ == '__main__': |
|
95 |
main(sys.argv[1:]) |