[PATCH 03/14] parsemail: Add a function to parse series markers eg. "1/12"
Damien Lespiau
damien.lespiau at intel.com
Wed Oct 21 08:59:32 AEDT 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>
Acked-by: Stephen Finucane <stephen.finucane 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 e61f1f4..a98066f 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -160,6 +160,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 a70def6..fe1fd2a 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -34,7 +34,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'
@@ -619,6 +620,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.4.3
More information about the Patchwork
mailing list