[PATCH 05/51] parsemail: Add a function to parse series markers eg. "1/12"
Damien Lespiau
damien.lespiau at intel.com
Sat Sep 12 01:54:38 AEST 2015
This can be used to identify cover letters, patches part of series,
length of series, ...
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
patchwork/bin/parsemail.py | 12 ++++++++++++
patchwork/tests/test_patchparser.py | 9 ++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 8f55a4a..8c26c5f 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -162,6 +162,18 @@ class MailContent:
self.patch = None
self.comment = None
+def parse_series_marker(subject_prefixes):
+ """If this patch is part a of multi-patches series, ie has x/n in its
+ subject, return (x, n). Otherwise, return (None, None)."""
+
+ regex = re.compile('^([0-9]+)/([0-9]+)$')
+ for prefix in subject_prefixes:
+ m = regex.match(prefix)
+ if not m:
+ continue
+ return (int(m.group(1)), int(m.group(2)))
+ return (None, None)
+
def find_content(project, mail):
patchbuf = None
commentbuf = ''
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 87a94d5..09737d4 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -38,7 +38,8 @@ class PatchTest(TestCase):
project = defaults.project
from patchwork.bin.parsemail import find_content, find_author, find_project, \
- parse_mail, split_prefixes, clean_subject
+ parse_mail, split_prefixes, clean_subject, \
+ parse_series_marker
class InlinePatchTest(PatchTest):
patch_filename = '0001-add-line.patch'
@@ -623,6 +624,12 @@ class PrefixTest(TestCase):
self.assertEquals(split_prefixes('PATCH,RFC'), ['PATCH', 'RFC'])
self.assertEquals(split_prefixes('PATCH 1/2'), ['PATCH', '1/2'])
+ def testSeriesMarkers(self):
+ self.assertEqual(parse_series_marker([]), (None, None))
+ self.assertEqual(parse_series_marker(['bar']), (None, None))
+ self.assertEqual(parse_series_marker(['bar', '1/2']), (1, 2))
+ self.assertEqual(parse_series_marker(['bar', '0/12']), (0, 12))
+
class SubjectTest(TestCase):
def testCleanSubject(self):
--
2.1.0
More information about the Patchwork
mailing list