-from lxml import (
- etree,
- html,
-)
-
-
-def calculate_previous_version(version: str, is_point: bool) -> str:
- """Calculate the previous version to compare to.
-
- In the case of -rc to final that verison is the previous .0 release,
- (19.3.0 in the case of 20.0.0, for example). for point releases that is
- the last point release. This value will be the same as the input value
- for a poiont release, but different for a major release.
- """
- if '-' in version:
- version = version.split('-')[0]
- if is_point:
- return version
- base = version.split('.')
- if base[1] == '0':
- base[0] = str(int(base[0]) - 1)
- base[1] = '3'
- else:
- base[1] = str(int(base[1]) - 1)
- return '.'.join(base)
-
-
-def is_point_release(version: str) -> bool:
- return not version.endswith('.0')
-
-
-def update_index(is_point: bool, version: str, previous_version: str) -> None:
- p = pathlib.Path(__file__).parent.parent / 'docs' / 'index.html'
- with p.open('rt') as f:
- tree = html.parse(f)
-
- news = tree.xpath('.//h1')[0]
-
- date = datetime.date.today()
- month = calendar.month_name[date.month]
- header = etree.Element('h2')
- header.text = f"{month} {date.day}, {date.year}"
-
- body = etree.Element('p')
- a = etree.SubElement(
- body, 'a', attrib={'href': f'relnotes/{previous_version}.html'})
- a.text = f"Mesa {previous_version}"
- if is_point:
- a.tail = " is released. This is a bug fix release."
- else:
- a.tail = (" is released. This is a new development release. "
- "See the release notes for mor information about this release.")
-
- root = news.getparent()
- index = root.index(news) + 1
- root.insert(index, body)
- root.insert(index, header)
-
- tree.write(p.as_posix(), method='html', pretty_print=True)
- subprocess.run(['git', 'add', p])