Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env python3
  2. # Copyright © 2019 Intel Corporation
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. # The above copyright notice and this permission notice shall be included in
  10. # all copies or substantial portions of the Software.
  11. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. # SOFTWARE.
  18. """Update the main page, release notes, and calendar."""
  19. import argparse
  20. import calendar
  21. import datetime
  22. import pathlib
  23. from lxml import (
  24. etree,
  25. html,
  26. )
  27. def calculate_previous_version(version: str, is_point: bool) -> str:
  28. """Calculate the previous version to compare to.
  29. In the case of -rc to final that verison is the previous .0 release,
  30. (19.3.0 in the case of 20.0.0, for example). for point releases that is
  31. the last point release. This value will be the same as the input value
  32. for a poiont release, but different for a major release.
  33. """
  34. if '-' in version:
  35. version = version.split('-')[0]
  36. if is_point:
  37. return version
  38. base = version.split('.')
  39. if base[1] == '0':
  40. base[0] = str(int(base[0]) - 1)
  41. base[1] = '3'
  42. else:
  43. base[1] = str(int(base[1]) - 1)
  44. return '.'.join(base)
  45. def is_point_release(version: str) -> bool:
  46. return not version.endswith('.0')
  47. def update_index(is_point: bool, version: str, previous_version: str) -> None:
  48. p = pathlib.Path(__file__).parent.parent / 'docs' / 'index.html'
  49. with p.open('rt') as f:
  50. tree = html.parse(f)
  51. news = tree.xpath('.//h1')[0]
  52. date = datetime.date.today()
  53. month = calendar.month_name[date.month]
  54. header = etree.Element('h2')
  55. header.text = f"{month} {date.day}, {date.year}"
  56. body = etree.Element('p')
  57. a = etree.SubElement(
  58. body, 'a', attrib={'href': f'relnotes/{previous_version}.html'})
  59. a.text = f"Mesa {previous_version}"
  60. if is_point:
  61. a.tail = " is released. This is a bug fix release."
  62. else:
  63. a.tail = (" is released. This is a new development release. "
  64. "See the release notes for mor information about this release.")
  65. root = news.getparent()
  66. index = root.index(news) + 1
  67. root.insert(index, body)
  68. root.insert(index, header)
  69. tree.write(p.as_posix(), method='html')
  70. def update_release_notes(previous_version: str) -> None:
  71. p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html'
  72. with p.open('rt') as f:
  73. tree = html.parse(f)
  74. li = etree.Element('li')
  75. a = etree.SubElement(li, 'a', href=f'relnotes/{previous_version}.html')
  76. a.text = f'{previous_version} release notes'
  77. ul = tree.xpath('.//ul')[0]
  78. ul.insert(0, li)
  79. tree.write(p.as_posix(), method='html')
  80. def main() -> None:
  81. parser = argparse.ArgumentParser()
  82. parser.add_argument('version', help="The released version.")
  83. args = parser.parse_args()
  84. is_point = is_point_release(args.version)
  85. previous_version = calculate_previous_version(args.version, is_point)
  86. update_index(is_point, args.version, previous_version)
  87. update_release_notes(previous_version)
  88. if __name__ == "__main__":
  89. main()