Cura/scripts/extract_changelog.py
David Fries 6e3e3e6742 Use raw strings for regular expressions with invalid escape sequences
If "T(\d*)" was "T(\n*)" it would search for newlines.  There isn't
any such \d escape character.

It should be "T(\\d*)" or r"T(\d*)" going with the latter, to be
easier to read and be consistent with other Cura usage.

Start python with -Wd or for python 3.12 will raise a SyntaxWarning.
2024-08-31 12:11:59 -05:00

39 lines
1.4 KiB
Python

import argparse
import re
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = 'Extract the changelog to be inserted to the release description')
parser.add_argument('--changelog', type = str, help = 'Path to the changelog file', required = True)
parser.add_argument('--version', type = str, help = 'Cura version to be extracted', required = True)
args = parser.parse_args()
# In the changelog we usually omit the patch number for minor release (i.e. 5.7.0 => 5.7)
if args.version.endswith('.0'):
args.version = args.version[:-2]
start_token = f"[{args.version}]"
pattern_stop_log = r"\[\d+(\.\d+){1,2}\]"
log_line = False
first_chapter = True
with open(args.changelog, "r") as changelog_file:
for line in changelog_file.readlines():
line = line.strip()
if log_line:
if re.match(pattern_stop_log, line):
log_line = False
elif len(line) > 0:
if line.startswith('*'):
if not first_chapter:
print("")
first_chapter = False
line = line[1:].strip()
print(f"<H2>{line}</H2>\n")
else:
print(line)
elif line == start_token:
log_line = True