1bf215546Sopenharmony_ci#!/usr/bin/env python3 2bf215546Sopenharmony_ci# Copyright © 2019-2020 Intel Corporation 3bf215546Sopenharmony_ci 4bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a copy 5bf215546Sopenharmony_ci# of this software and associated documentation files (the "Software"), to deal 6bf215546Sopenharmony_ci# in the Software without restriction, including without limitation the rights 7bf215546Sopenharmony_ci# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8bf215546Sopenharmony_ci# copies of the Software, and to permit persons to whom the Software is 9bf215546Sopenharmony_ci# furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci 11bf215546Sopenharmony_ci# The above copyright notice and this permission notice shall be included in 12bf215546Sopenharmony_ci# all copies or substantial portions of the Software. 13bf215546Sopenharmony_ci 14bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17bf215546Sopenharmony_ci# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19bf215546Sopenharmony_ci# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20bf215546Sopenharmony_ci# SOFTWARE. 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_ci"""Update the main page, release notes, and calendar.""" 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ciimport argparse 25bf215546Sopenharmony_ciimport csv 26bf215546Sopenharmony_ciimport pathlib 27bf215546Sopenharmony_ciimport subprocess 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_cidef update_release_notes(version: str) -> None: 31bf215546Sopenharmony_ci p = pathlib.Path('docs') / 'relnotes.rst' 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci with open(p, 'r') as f: 34bf215546Sopenharmony_ci relnotes = f.readlines() 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci new_relnotes = [] 37bf215546Sopenharmony_ci first_list = True 38bf215546Sopenharmony_ci second_list = True 39bf215546Sopenharmony_ci for line in relnotes: 40bf215546Sopenharmony_ci if first_list and line.startswith('-'): 41bf215546Sopenharmony_ci first_list = False 42bf215546Sopenharmony_ci new_relnotes.append(f'- :doc:`{version} release notes <relnotes/{version}>`\n') 43bf215546Sopenharmony_ci if not first_list and second_list and line.startswith(' relnotes/'): 44bf215546Sopenharmony_ci second_list = False 45bf215546Sopenharmony_ci new_relnotes.append(f' relnotes/{version}\n') 46bf215546Sopenharmony_ci new_relnotes.append(line) 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci with open(p, 'w') as f: 49bf215546Sopenharmony_ci for line in new_relnotes: 50bf215546Sopenharmony_ci f.write(line) 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci subprocess.run(['git', 'add', p]) 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_cidef update_calendar(version: str) -> None: 56bf215546Sopenharmony_ci p = pathlib.Path('docs') / 'release-calendar.csv' 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci with p.open('r') as f: 59bf215546Sopenharmony_ci calendar = list(csv.reader(f)) 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci branch = None 62bf215546Sopenharmony_ci for i, line in enumerate(calendar): 63bf215546Sopenharmony_ci if line[2] == version: 64bf215546Sopenharmony_ci if line[0]: 65bf215546Sopenharmony_ci branch = line[0] 66bf215546Sopenharmony_ci break 67bf215546Sopenharmony_ci if branch is not None: 68bf215546Sopenharmony_ci calendar[i + 1][0] = branch 69bf215546Sopenharmony_ci del calendar[i] 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci with p.open('w') as f: 72bf215546Sopenharmony_ci writer = csv.writer(f) 73bf215546Sopenharmony_ci writer.writerows(calendar) 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci subprocess.run(['git', 'add', p]) 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_cidef main() -> None: 79bf215546Sopenharmony_ci parser = argparse.ArgumentParser() 80bf215546Sopenharmony_ci parser.add_argument('version', help="The released version.") 81bf215546Sopenharmony_ci args = parser.parse_args() 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci update_calendar(args.version) 84bf215546Sopenharmony_ci done = 'update calendar' 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci if 'rc' not in args.version: 87bf215546Sopenharmony_ci update_release_notes(args.version) 88bf215546Sopenharmony_ci done += ' and link releases notes' 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci subprocess.run(['git', 'commit', '-m', 91bf215546Sopenharmony_ci f'docs: {done} for {args.version}']) 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ciif __name__ == "__main__": 95bf215546Sopenharmony_ci main() 96