From nobody Fri Apr 26 14:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153294745243852.49670890213167; Mon, 30 Jul 2018 03:44:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18AA9308625F; Mon, 30 Jul 2018 10:44:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03FC4173C3; Mon, 30 Jul 2018 10:44:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E645218037EC; Mon, 30 Jul 2018 10:44:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UAi8JG001324 for ; Mon, 30 Jul 2018 06:44:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02ACB2026D76; Mon, 30 Jul 2018 10:44:08 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-217.ams2.redhat.com [10.36.116.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 865762026D68 for ; Mon, 30 Jul 2018 10:44:07 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 30 Jul 2018 12:44:05 +0200 Message-Id: <20180730104406.22997-2-pbonzini@redhat.com> In-Reply-To: <20180730104406.22997-1-pbonzini@redhat.com> References: <20180730104406.22997-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/2] tags: use regex to match tags X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 30 Jul 2018 10:44:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is simpler, since we can use case insensitive matches, and will also be easier to reuse in the next patch. Signed-off-by: Paolo Bonzini --- mods/tags.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/tags.py b/mods/tags.py index 5ec5bc2..aa29c60 100644 --- a/mods/tags.py +++ b/mods/tags.py @@ -13,6 +13,8 @@ from mbox import parse_address from event import register_handler, emit_event, declare_event from api.models import Message from api.rest import PluginMethodField +from patchew.tags import lines_iter +import re =20 REV_BY_PREFIX =3D "Reviewed-by:" BASED_ON_PREFIX =3D "Based-on:" @@ -55,6 +57,11 @@ series cover letter, patch mail body and their replies. tagsconfig =3D self.get_config("default", "tags", default=3D"") return set([x.strip() for x in tagsconfig.split(",") if x.strip()]= + BUILT_IN_TAGS) =20 + def get_tag_regex(self): + tags =3D self.get_tag_prefixes() + tags_re =3D '|'.join(map(re.escape, tags)) + return re.compile('^(?i:%s):' % tags_re) + def update_tags(self, s): old =3D s.get_property("tags", []) new =3D self.look_for_tags(s) @@ -105,10 +112,10 @@ series cover letter, patch mail body and their replie= s. =20 def parse_message_tags(self, m): r =3D [] + regex =3D self.get_tag_regex() for l in m.get_body().splitlines(): - for p in self.get_tag_prefixes(): - if l.lower().startswith(p.lower()): - r.append(l) + if regex.match(l): + r.append(l) return r =20 def look_for_tags(self, m): --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Apr 26 14:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532947452454445.5779317071689; Mon, 30 Jul 2018 03:44:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DBB7308213D; Mon, 30 Jul 2018 10:44:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D58D17CEF; Mon, 30 Jul 2018 10:44:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 08ACF18037F0; Mon, 30 Jul 2018 10:44:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UAi8KO001329 for ; Mon, 30 Jul 2018 06:44:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB6742026D76; Mon, 30 Jul 2018 10:44:08 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-217.ams2.redhat.com [10.36.116.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A1252026D68 for ; Mon, 30 Jul 2018 10:44:08 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 30 Jul 2018 12:44:06 +0200 Message-Id: <20180730104406.22997-3-pbonzini@redhat.com> In-Reply-To: <20180730104406.22997-1-pbonzini@redhat.com> References: <20180730104406.22997-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/2] www: provide a quick way to download patches as mbox file X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 30 Jul 2018 10:44:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The "download mbox" file downloads the entire thread, which is rarely what you want to do. Provide an alternative download link that only includes the patches and, when the tags module is active, includes the tags into the mbox. Signed-off-by: Paolo Bonzini --- mods/tags.py | 47 +++++++++++++++++++++++++++++++- www/templates/series-detail.html | 6 ++-- www/urls.py | 1 + www/views.py | 11 ++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/mods/tags.py b/mods/tags.py index aa29c60..f7b0300 100644 --- a/mods/tags.py +++ b/mods/tags.py @@ -10,11 +10,13 @@ =20 from mod import PatchewModule from mbox import parse_address +from django.http import HttpResponse, Http404 from event import register_handler, emit_event, declare_event from api.models import Message from api.rest import PluginMethodField from patchew.tags import lines_iter import re +import www.views =20 REV_BY_PREFIX =3D "Reviewed-by:" BASED_ON_PREFIX =3D "Based-on:" @@ -27,6 +29,21 @@ tags =3D Tested-by, Reported-by, Acked-by, Suggested-by =20 BUILT_IN_TAGS =3D [REV_BY_PREFIX, BASED_ON_PREFIX] =20 +_instance =3D None + +# This is monkey-patched into www.views +def _view_series_mbox_patches(request, project, message_id): + global _instance + s =3D Message.objects.find_series(message_id, project) + if not s: + raise Http404("Series not found") + if not s.is_complete: + raise Http404("Series not complete") + mbox =3D "\n".join(["From %s %s\n" % (x.get_sender_addr(), x.get_ascti= me()) + \ + _instance.get_mbox_with_tags(x) for x in s.get_patch= es()]) + return HttpResponse(mbox, content_type=3D"text/plain") +www.views.view_series_mbox_patches =3D _view_series_mbox_patches + class SeriesTagsModule(PatchewModule): """ =20 @@ -49,6 +66,9 @@ series cover letter, patch mail body and their replies. default_config =3D _default_config =20 def __init__(self): + global _instance + assert _instance =3D=3D None + _instance =3D self register_handler("MessageAdded", self.on_message_added) declare_event("TagsUpdate", series=3D"message object that is updat= ed") =20 @@ -153,4 +173,29 @@ series cover letter, patch mail body and their replies. "char": "O", "row_class": "obsolete" }) - + message.extra_links.append({"html": mark_safe(html), "icon": "exch= ange" }) + + # FIXME: what happens with base64 messages? + def get_mbox_with_tags(self, m): + def result_iter(): + regex =3D self.get_tag_regex() + old_tags =3D set() + lines =3D lines_iter(m.get_mbox()) + need_minusminusminus =3D False + for line in lines: + if line.startswith('---'): + need_minusminusminus =3D True + break + yield line + if regex.match(line): + old_tags.add(line) + + # If no --- line, tags go at the end as there's no better place + for tag in m.get_property("tags", []): + if not tag in old_tags: + yield tag + if need_minusminusminus: + yield line + yield from lines + + return '\n'.join(result_iter()) diff --git a/www/templates/series-detail.html b/www/templates/series-detail= .html index 52b8f96..1735794 100644 --- a/www/templates/series-detail.html +++ b/www/templates/series-detail.html @@ -26,9 +26,9 @@ {{ series.age }} ago