#!/usr/bin/env python3
-# Copyright © 2019 Intel Corporation
+# Copyright © 2019-2020 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
"""Update the main page, release notes, and calendar."""
-import calendar
-import datetime
+import argparse
import pathlib
-from lxml import (
- etree,
- html,
-)
+import subprocess
-def calculate_previous_version(version: str, is_point: bool) -> str:
- """Calculate the previous version to compare to.
+def update_homepage(version: str) -> None:
+ p = pathlib.Path(__file__).parent.parent / 'docs' / 'conf.py'
- 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)
+ # Don't post release candidates to the homepage
+ if 'rc' in version:
+ return
+ with open(p, 'r') as f:
+ conf = f.readlines()
-def get_version() -> str:
- v = pathlib.Path(__file__).parent.parent / 'VERSION'
- with v.open('rt') as f:
- raw_version = f.read().strip()
- return raw_version.split('-')[0]
+ new_conf = []
+ for line in conf:
+ if line.startswith("version = '") and line.endswith("'\n"):
+ old_version = line.split("'")[1]
+ # Avoid overwriting 20.1.0 when releasing 20.0.8
+ # TODO: we might need more than that to handle 20.0.10
+ if old_version < version:
+ line = f"version = '{version}'\n"
+ new_conf.append(line)
+ with open(p, 'w') as f:
+ for line in new_conf:
+ f.write(line)
-def is_point_release() -> bool:
- v = pathlib.Path(__file__).parent.parent / 'VERSION'
- with v.open('rt') as f:
- raw_version = f.read().strip()
- return '-rc' not in raw_version
+ subprocess.run(['git', 'add', p])
-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)
+def update_release_notes(version: str) -> None:
+ p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.rst'
- news = tree.xpath('.//h1')[0]
+ with open(p, 'r') as f:
+ relnotes = f.readlines()
- date = datetime.date.today()
- month = calendar.month_name[date.month]
- header = etree.Element('h2')
- header.text=f"{month} {date.day}, {date.year}"
+ new_relnotes = []
+ first_list = True
+ for line in relnotes:
+ if first_list and line.startswith('-'):
+ first_list = False
+ new_relnotes.append(f'- `{version} release notes <relnotes/{version}.rst>`__\n')
+ new_relnotes.append(line)
- body = etree.Element('p')
- a = etree.SubElement(body, 'a', attrib={'href': f'relnotes/{previous_version}'})
- 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.")
+ with open(p, 'w') as f:
+ for line in new_relnotes:
+ f.write(line)
- root = news.getparent()
- index = root.index(news) + 1
- root.insert(index, body)
- root.insert(index, header)
+ subprocess.run(['git', 'add', p])
- tree.write(p.as_posix(), method='html')
+def update_calendar(version: str) -> None:
+ p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.rst'
-def update_release_notes(previous_version: str) -> None:
- p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html'
- with p.open('rt') as f:
- tree = html.parse(f)
+ with open(p, 'r') as f:
+ calendar = f.readlines()
- li = etree.Element('li')
- a = etree.SubElement(li, 'a', href=f'relnotes/{previous_version}')
- a.text = f'{previous_version} release notes'
+ branch = ''
+ skip_line = False
+ new_calendar = []
+ for line in calendar:
+ if version in line:
+ branch = line.split('|')[1].strip()
+ skip_line = True
+ elif skip_line:
+ skip_line = False
+ elif branch:
+ # Put the branch number back on the next line
+ new_calendar.append(line[:2] + branch + line[len(branch) + 2:])
+ branch = ''
+ else:
+ new_calendar.append(line)
- ul = tree.xpath('.//ul')[0]
- ul.insert(0, li)
+ with open(p, 'w') as f:
+ for line in new_calendar:
+ f.write(line)
- tree.write(p.as_posix(), method='html')
+ subprocess.run(['git', 'add', p])
def main() -> None:
- is_point = is_point_release()
- version = get_version()
- previous_version = calculate_previous_version(version, is_point)
+ parser = argparse.ArgumentParser()
+ parser.add_argument('version', help="The released version.")
+ args = parser.parse_args()
- update_index(is_point, version, previous_version)
- update_release_notes(previous_version)
+ update_homepage(args.version)
+ update_calendar(args.version)
+ done = 'update calendar'
+
+ if not is_release_candidate(args.version):
+ update_index(args.version)
+ update_release_notes(args.version)
+ done += ', add news item, and link releases notes'
+
+ subprocess.run(['git', 'commit', '-m',
+ f'docs: {done} for {args.version}'])
if __name__ == "__main__":