update-metainfo-releases.py 909 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. import html
  3. import re
  4. from pathlib import Path
  5. root = Path(__file__).resolve().parent.parent
  6. title_pattern = re.compile(r"## (\d+\.\d+\.\d+) \((\d{4}-\d\d-\d\d)\)")
  7. release_lines = [" <releases>"]
  8. for line in (root / "docs" / "CHANGELOG.md").read_text().splitlines():
  9. match = title_pattern.match(line)
  10. if match:
  11. args = (html.escape(match.group(1)), html.escape(match.group(2)))
  12. release_lines.append(' <release version="%s" date="%s"/>' % args)
  13. appdata = root / "packaging" / "moment.metainfo.xml"
  14. in_releases = False
  15. final_lines = []
  16. for line in appdata.read_text().splitlines():
  17. if line == " <releases>":
  18. in_releases = True
  19. final_lines += release_lines
  20. elif line == " </releases>":
  21. in_releases = False
  22. if not in_releases:
  23. final_lines.append(line)
  24. appdata.write_text("\n".join(final_lines))