amd/registers: add a script that generates json from kernel headers
[mesa.git] / bin / post_version.py
index c55309d93870380b42ce9ad51538d307e17e31e5..359cbd9012cc177fb5428eddbac9f4d20abaf01f 100755 (executable)
 """Update the main page, release notes, and calendar."""
 
 import argparse
-import calendar
-import datetime
 import pathlib
 import subprocess
 
-from lxml import (
-    etree,
-    html,
-)
-
-
-def is_first_release(version: str) -> bool:
-    return version.endswith('.0')
-
-
-def is_release_candidate(version: str) -> bool:
-    return '-rc' in version
-
-
-def branch_name(version: str) -> str:
-    if is_release_candidate(version):
-        version = version.split('-')[0]
-    (major, minor, _) = version.split('.')
-    return f'{major}.{minor}'
-
-
-def update_index(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/{version}.html'})
-    a.text = f"Mesa {version}"
-    if is_first_release(version):
-        a.tail = (" is released. This is a new development release. "
-                  "See the release notes for more information about this release.")
-    else:
-        a.tail = " is released. This is a bug fix 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])
-
 
 def update_release_notes(version: str) -> None:
-    p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html'
-    with p.open('rt') as f:
-        tree = html.parse(f)
+    p = pathlib.Path('docs') / 'relnotes.rst'
+
+    with open(p, 'r') as f:
+        relnotes = f.readlines()
+
+    new_relnotes = []
+    first_list = True
+    second_list = True
+    for line in relnotes:
+        if first_list and line.startswith('-'):
+            first_list = False
+            new_relnotes.append(f'-  :doc:`{version} release notes <relnotes/{version}>`\n')
+        if not first_list and second_list and line.startswith('   relnotes/'):
+            second_list = False
+            new_relnotes.append(f'   relnotes/{version}\n')
+        new_relnotes.append(line)
+
+    with open(p, 'w') as f:
+        for line in new_relnotes:
+            f.write(line)
 
-    li = etree.Element('li')
-    a = etree.SubElement(li, 'a', href=f'relnotes/{version}.html')
-    a.text = f'{version} release notes'
-
-    ul = tree.xpath('.//ul')[0]
-    ul.insert(0, li)
-
-    tree.write(p.as_posix(), method='html', pretty_print=True)
     subprocess.run(['git', 'add', p])
 
 
 def update_calendar(version: str) -> None:
-    p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.html'
-    with p.open('rt') as f:
-        tree = html.parse(f)
-
-    branch = branch_name(version)
-
-    old = None
-    new = None
-
-    for tr in tree.xpath('.//tr'):
-        if old is not None:
-            new = tr
-            break
-
-        for td in tr.xpath('./td'):
-            if td.text == branch:
-                old = tr
-                break
-
-    assert old is not None
-    assert new is not None
-    old.getparent().remove(old)
-
-    # rowspan is 1 based in html, but 0 based in lxml
-    rowspan = int(td.get("rowspan")) - 1
-    if rowspan:
-        td.set("rowspan", str(rowspan))
-        new.insert(0, td)
+    p = pathlib.Path('docs') / 'release-calendar.rst'
+
+    with open(p, 'r') as f:
+        calendar = f.readlines()
+
+    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)
+
+    with open(p, 'w') as f:
+        for line in new_calendar:
+            f.write(line)
 
-    tree.write(p.as_posix(), method='html', pretty_print=True)
     subprocess.run(['git', 'add', p])
 
 
@@ -137,10 +88,9 @@ def main() -> None:
     update_calendar(args.version)
     done = 'update calendar'
 
-    if not is_release_candidate(args.version):
-        update_index(args.version)
+    if 'rc' not in args.version:
         update_release_notes(args.version)
-        done += ', add news item, and link releases notes'
+        done += ' and link releases notes'
 
     subprocess.run(['git', 'commit', '-m',
                     f'docs: {done} for {args.version}'])