extract_changelog.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import argparse
  2. import re
  3. if __name__ == "__main__":
  4. parser = argparse.ArgumentParser(description = 'Extract the changelog to be inserted to the release description')
  5. parser.add_argument('--changelog', type = str, help = 'Path to the changelog file', required = True)
  6. parser.add_argument('--version', type = str, help = 'Cura version to be extracted', required = True)
  7. args = parser.parse_args()
  8. # In the changelog we usually omit the patch number for minor release (i.e. 5.7.0 => 5.7)
  9. if args.version.endswith('.0'):
  10. args.version = args.version[:-2]
  11. start_token = f"[{args.version}]"
  12. pattern_stop_log = "\[\d+(\.\d+){1,2}\]"
  13. log_line = False
  14. first_chapter = True
  15. with open(args.changelog, "r") as changelog_file:
  16. for line in changelog_file.readlines():
  17. line = line.strip()
  18. if log_line:
  19. if re.match(pattern_stop_log, line):
  20. log_line = False
  21. elif len(line) > 0:
  22. if line.startswith('*'):
  23. if not first_chapter:
  24. print("")
  25. first_chapter = False
  26. line = line[1:].strip()
  27. print(f"<H2>{line}</H2>\n")
  28. else:
  29. print(line)
  30. elif line == start_token:
  31. log_line = True