[PATCH 06/13] parsemail: Parse series markers e.g. "1/12"

Stephen Finucane stephen.finucane at intel.com
Fri Mar 11 23:08:10 AEDT 2016


From: Damien Lespiau <damien.lespiau at intel.com>

This can be used to identify cover letters, patches part of series,
length of series, etc.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/bin/parsemail.py          | 23 +++++++++++++++++++++++
 patchwork/tests/test_patchparser.py |  9 ++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 062cc80..44046ff 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -193,6 +193,29 @@ def try_decode(payload, charset):
     return payload
 
 
+def parse_series_marker(subject_prefixes):
+    """Extract series markers from subject.
+
+    Extract the markers of multi-patches series, i.e. 'x/n', from the
+    provided subject series.
+
+    Args:
+        subject_prefixes: List of subject prefixes to extract markers
+          from
+
+    Returns:
+        (x, n) if markers found, else (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 06a2598..2bc54cb 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -25,7 +25,8 @@ from django.test import TestCase
 
 from patchwork.bin.parsemail import (find_content, find_author,
                                      find_project_by_header, parse_mail,
-                                     split_prefixes, clean_subject)
+                                     split_prefixes, clean_subject,
+                                     parse_series_marker)
 from patchwork.models import (Project, Person, Patch, Comment, State,
                               get_default_initial_patch_state)
 from patchwork.tests.utils import (read_patch, read_mail, create_email,
@@ -644,6 +645,12 @@ class PrefixTest(TestCase):
         self.assertEqual(split_prefixes('PATCH,RFC'), ['PATCH', 'RFC'])
         self.assertEqual(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):
 
-- 
2.0.0



More information about the Patchwork mailing list