Linux: Change minimum priority threads from SCHED_IDLE to nice 19 SCHED_BATCH.
[mesa.git] / bin / post_version.py
1 #!/usr/bin/env python3
2 # Copyright © 2019-2020 Intel Corporation
3
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
10
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
13
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21
22 """Update the main page, release notes, and calendar."""
23
24 import argparse
25 import calendar
26 import datetime
27 import pathlib
28 import subprocess
29
30 from lxml import (
31 etree,
32 html,
33 )
34
35
36 def is_point_release(version: str) -> bool:
37 return not version.endswith('.0')
38
39
40 def update_index(is_point: bool, version: str) -> None:
41 p = pathlib.Path(__file__).parent.parent / 'docs' / 'index.html'
42 with p.open('rt') as f:
43 tree = html.parse(f)
44
45 news = tree.xpath('.//h1')[0]
46
47 date = datetime.date.today()
48 month = calendar.month_name[date.month]
49 header = etree.Element('h2')
50 header.text = f"{month} {date.day}, {date.year}"
51
52 body = etree.Element('p')
53 a = etree.SubElement(
54 body, 'a', attrib={'href': f'relnotes/{version}.html'})
55 a.text = f"Mesa {version}"
56 if is_point:
57 a.tail = " is released. This is a bug fix release."
58 else:
59 a.tail = (" is released. This is a new development release. "
60 "See the release notes for more information about this release.")
61
62 root = news.getparent()
63 index = root.index(news) + 1
64 root.insert(index, body)
65 root.insert(index, header)
66
67 tree.write(p.as_posix(), method='html', pretty_print=True)
68 subprocess.run(['git', 'add', p])
69
70
71 def update_release_notes(version: str) -> None:
72 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html'
73 with p.open('rt') as f:
74 tree = html.parse(f)
75
76 li = etree.Element('li')
77 a = etree.SubElement(li, 'a', href=f'relnotes/{version}.html')
78 a.text = f'{version} release notes'
79
80 ul = tree.xpath('.//ul')[0]
81 ul.insert(0, li)
82
83 tree.write(p.as_posix(), method='html', pretty_print=True)
84 subprocess.run(['git', 'add', p])
85
86
87 def update_calendar(version: str) -> None:
88 p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.html'
89 with p.open('rt') as f:
90 tree = html.parse(f)
91
92 base_version = version[:-2]
93
94 old = None
95 new = None
96
97 for tr in tree.xpath('.//tr'):
98 if old is not None:
99 new = tr
100 break
101
102 for td in tr.xpath('./td'):
103 if td.text == base_version:
104 old = tr
105 break
106
107 assert old is not None
108 assert new is not None
109 old.getparent().remove(old)
110
111 # rowspan is 1 based in html, but 0 based in lxml
112 rowspan = int(td.get("rowspan")) - 1
113 if rowspan:
114 td.set("rowspan", str(rowspan))
115 new.insert(0, td)
116
117 tree.write(p.as_posix(), method='html', pretty_print=True)
118 subprocess.run(['git', 'add', p])
119
120
121 def main() -> None:
122 parser = argparse.ArgumentParser()
123 parser.add_argument('version', help="The released version.")
124 args = parser.parse_args()
125
126 is_point = is_point_release(args.version)
127
128 update_index(is_point, args.version)
129 update_release_notes(args.version)
130 update_calendar(args.version)
131 subprocess.run(['git', 'commit', '-m',
132 'docs: update calendar, add news item, and link releases '
133 f'notes for {args.version}'])
134
135
136 if __name__ == "__main__":
137 main()