From 04063792800307a2110442ef70ca33405a179e02 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 3 Jul 2022 02:02:49 +0200 Subject: scripts/issue.py: Parse multiple statuses in the same field For issues with complex fixes, sometimes only part of the fix is applied to a stable branch. We record this by marking the issue as some combination of "released", "pending", and "needed". Change issue.parse_status() to be able to read past the first status and coalesce the statuses as necessary. --- scripts/issue.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/issue.py b/scripts/issue.py index 31484f13..ee8a1c59 100644 --- a/scripts/issue.py +++ b/scripts/issue.py @@ -1,6 +1,7 @@ from debian import deb822 import os.path import re +import sys class issue(deb822.Deb822): @@ -65,13 +66,53 @@ def get_issues(dir): return [ issue(os.path.join(dir, f)) for f in L ] +_status_re = re.compile( + r'\s*(\S*)' + r'(?:\s*\([^\s)]+\))?' # optional version + r'(?:\s*\[[^]]+\])?' # optional changerefs + r'(?:\s*"[^"]+")?' # optional comment + ) + + +_comma_re = re.compile(r'\s*,\s*') + + +def _coalesce_state(old_state, new_state): + if old_state is None: + return new_state + # "needed" overrides everything else + if 'needed' in [old_state, new_state]: + return 'needed' + # "pendng" overrides everything but "needed" + if 'pending' in [old_state, new_state]: + return 'pending' + # We don't expect to use more than one of "released", "ignored", + # or "N/A" and it's not clear which should override which + if old_state != new_state: + print(f'W: Not sure how to coalesce status {old_state} and {new_state}', + file=sys.stderr) + return old_state + + def parse_status(s): - ws = '\s*' - state = '(?P\S*)' - - statusre = re.compile(ws + state) - m = statusre.match(s) - if not m: - raise SyntaxError - else: - return m.groupdict() + state = None + start = 0 + + while True: + m = _status_re.match(s[start:]) + if not m: + raise SyntaxError(f'bad status {s[start:]}') + start += m.end() + + # Coalesce with last status + state = _coalesce_state(state, m.group(1)) + + # End of field? + if start == len(s) or s[start:].isspace(): + return {'state': state} + + # No, must be followed by a comma separator + m = _comma_re.match(s[start:]) + if not m: + raise SyntaxError(f'missing separator in{s[start:]}') + start += m.end() -- cgit v1.2.3