summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2022-07-03 02:02:49 +0200
committerBen Hutchings <ben@decadent.org.uk>2023-08-20 22:28:16 +0200
commit04063792800307a2110442ef70ca33405a179e02 (patch)
treeb5c38caaa6c78a6f3caa74a90a2c6ff72b2abd92 /scripts
parentbb8cb7e1f2f9b2f7c96e085d889879e334168e6b (diff)
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.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/issue.py59
1 files changed, 50 insertions, 9 deletions
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<state>\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()

© 2014-2024 Faster IT GmbH | imprint | privacy policy