genrelnotes.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # Copyright 2019 The Meson development team
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys, os, subprocess
  16. from glob import glob
  17. relnote_template = '''---
  18. title: Release %s
  19. short-description: Release notes for %s
  20. ...
  21. # New features
  22. '''
  23. def add_to_sitemap(from_version, to_version):
  24. sitemapfile = '../sitemap.txt'
  25. sf = open(sitemapfile)
  26. lines = sf.readlines()
  27. sf.close()
  28. with open(sitemapfile, 'w') as sf:
  29. for line in lines:
  30. if 'Release-notes' in line and from_version in line:
  31. new_line = line.replace(from_version, to_version)
  32. sf.write(new_line)
  33. sf.write(line)
  34. def generate(from_version, to_version):
  35. ofilename = 'Release-notes-for-%s.md' % to_version
  36. with open(ofilename, 'w') as ofile:
  37. ofile.write(relnote_template % (to_version, to_version))
  38. for snippetfile in glob('snippets/*.md'):
  39. snippet = open(snippetfile).read()
  40. ofile.write(snippet)
  41. if not snippet.endswith('\n'):
  42. ofile.write('\n')
  43. ofile.write('\n')
  44. subprocess.check_call(['git', 'rm', snippetfile])
  45. subprocess.check_call(['git', 'add', ofilename])
  46. add_to_sitemap(from_version, to_version)
  47. if __name__ == '__main__':
  48. if len(sys.argv) != 3:
  49. print(sys.argv[0], 'from_version to_version')
  50. sys.exit(1)
  51. from_version = sys.argv[1]
  52. to_version = sys.argv[2]
  53. os.chdir('markdown')
  54. generate(from_version, to_version)