5bf68fe35d2646a26d0b4d0a27a7d5bcf5fb26bc
2 # Copyright © 2019 Intel Corporation
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:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
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
22 """Update the main page, release notes, and calendar."""
34 def calculate_previous_version(version
: str, is_point
: bool) -> str:
35 """Calculate the previous version to compare to.
37 In the case of -rc to final that verison is the previous .0 release,
38 (19.3.0 in the case of 20.0.0, for example). for point releases that is
39 the last point release. This value will be the same as the input value
40 for a poiont release, but different for a major release.
43 version
= version
.split('-')[0]
46 base
= version
.split('.')
48 base
[0] = str(int(base
[0]) - 1)
51 base
[1] = str(int(base
[1]) - 1)
55 def is_point_release(version
: str) -> bool:
56 return not version
.endswith('.0')
59 def update_index(is_point
: bool, version
: str, previous_version
: str) -> None:
60 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'index.html'
61 with p
.open('rt') as f
:
64 news
= tree
.xpath('.//h1')[0]
66 date
= datetime
.date
.today()
67 month
= calendar
.month_name
[date
.month
]
68 header
= etree
.Element('h2')
69 header
.text
= f
"{month} {date.day}, {date.year}"
71 body
= etree
.Element('p')
73 body
, 'a', attrib
={'href': f
'relnotes/{previous_version}.html'})
74 a
.text
= f
"Mesa {previous_version}"
76 a
.tail
= " is released. This is a bug fix release."
78 a
.tail
= (" is released. This is a new development release. "
79 "See the release notes for mor information about this release.")
81 root
= news
.getparent()
82 index
= root
.index(news
) + 1
83 root
.insert(index
, body
)
84 root
.insert(index
, header
)
86 tree
.write(p
.as_posix(), method
='html')
89 def update_release_notes(previous_version
: str) -> None:
90 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'relnotes.html'
91 with p
.open('rt') as f
:
94 li
= etree
.Element('li')
95 a
= etree
.SubElement(li
, 'a', href
=f
'relnotes/{previous_version}.html')
96 a
.text
= f
'{previous_version} release notes'
98 ul
= tree
.xpath('.//ul')[0]
101 tree
.write(p
.as_posix(), method
='html')
104 def update_calendar(previous_version
: str) -> None:
105 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'release-calendar.html'
106 with p
.open('rt') as f
:
109 base_version
= previous_version
[:-2]
114 for tr
in tree
.xpath('.//tr'):
119 for td
in tr
.xpath('./td'):
120 if td
.text
== base_version
:
124 assert old
is not None
125 assert new
is not None
126 old
.getparent().remove(old
)
128 # rowspan is 1 based in html, but 0 based in lxml
129 rowspan
= int(td
.get("rowspan")) - 1
131 td
.set("rowspan", str(rowspan
))
134 tree
.write(p
.as_posix(), method
='html')
138 parser
= argparse
.ArgumentParser()
139 parser
.add_argument('version', help="The released version.")
140 args
= parser
.parse_args()
142 is_point
= is_point_release(args
.version
)
143 previous_version
= calculate_previous_version(args
.version
, is_point
)
145 update_index(is_point
, args
.version
, previous_version
)
146 update_release_notes(previous_version
)
147 update_calendar(previous_version
)
150 if __name__
== "__main__":