From nobody Fri May 3 06:52:24 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; dkim=fail; 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 1520496077403551.5278170203517; Thu, 8 Mar 2018 00:01:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7546881DF0; Thu, 8 Mar 2018 08:01:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63FF16134B; Thu, 8 Mar 2018 08:01:16 +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 55D594CA99; Thu, 8 Mar 2018 08:01:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2880q5l032349 for ; Thu, 8 Mar 2018 03:00:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 10C849F6F; Thu, 8 Mar 2018 08:00:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 093159F6E for ; Thu, 8 Mar 2018 08:00:48 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D92E480F6C for ; Thu, 8 Mar 2018 08:00:46 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id t6so9290588wmt.5 for ; Thu, 08 Mar 2018 00:00:46 -0800 (PST) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id b9sm21755912wrh.68.2018.03.08.00.00.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Mar 2018 00:00:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=N0GVbxiXNH+ISThVMNHH1tYVNVLHqNULUdIk7uOb6ek=; b=iJsUhVLfJZpwSVGHvVHJfpq9gl2d+8w6w2G1ZVifwXKr+Uf+LiGZmETtmPiBUPHzOX 6xaH83FBJUe1NGLCq+GuZr5tPehsmQxZGqotQ4Tzo60UW+VIIB9VFbwOKki2xAeDQdWc xBfUjbAfI0acKnXs/suhvfbsSMT504JF9bMN9rvCyVPaInW7Kkv9/t6AZbrW43BKJPlj +Z8CT7rJTaxXozY4evmLWTRTwuMKpysgZ0me062PMnjaimxUB0VQvZyXevTeEbMrpIhu O2xIJt5VfLeF9cjizddkxnjFbHgVk8ztOLZUx0dAPrCnLdK04p+J/EvXArM+QDGO3iUK x6sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=N0GVbxiXNH+ISThVMNHH1tYVNVLHqNULUdIk7uOb6ek=; b=UTLmNq53lWDEtd9MDoMK03LrKv5BoM28ewYJ5Oxz3mbHcepU6y2op3lCDkn7k1wEDJ YuWqmDXgiuAfiAV+mo9cDpJknGkW2LiKUf1RopDrEBbjtNRXD6yYRAVi09DlN+UvCAJ/ B+z3ytkGo15pCazCmPKoFUB20Cg7j0n7k/bDLLM/+Mlf7BOaYyuD+7gCfRBimbK2FvzH IaSfNFbEa4cNWYZyPmu8Ux5vonFRS+5sS7h77l2XdmZTSv/ZCRBW3tQHKDVLQNtPAxfE 7wDDrGuTBMxf95Gh3Pe61718aZj82inufX+RW4XEtHJ0Bfcm8sfS2rr+peBu+ToLjQSB KInQ== X-Gm-Message-State: AElRT7HiIOiMnFJBe2ufoo7NUC+QYjUPMObqErgN4kwHZbSEl+75NBJ/ SeQ1bYpUy9yQN8SXxk8g+wwAPdyp X-Google-Smtp-Source: AG47ELuAthZ0aHtteKHJMBpkCijmA3acrrD92IAmkvoIKmg/TucedGLWjx8K08sggRV51zPIuCIatA== X-Received: by 10.28.191.90 with SMTP id p87mr15014333wmf.145.1520496045160; Thu, 08 Mar 2018 00:00:45 -0800 (PST) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 8 Mar 2018 09:00:36 +0100 Message-Id: <20180308080042.19342-2-pbonzini@redhat.com> In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com> References: <20180308080042.19342-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 08 Mar 2018 08:00:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 08 Mar 2018 08:00:47 +0000 (UTC) for IP:'74.125.82.68' DOMAIN:'mail-wm0-f68.google.com' HELO:'mail-wm0-f68.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.469 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.68 mail-wm0-f68.google.com 74.125.82.68 mail-wm0-f68.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/7] ansi2html: add _write_form_feed 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 08 Mar 2018 08:01:16 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Form feeds are rendered differently by HTML and text converters, so move the HTML rendering out of _write_line's argument. Signed-off-by: Paolo Bonzini --- patchew/logviewer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/patchew/logviewer.py b/patchew/logviewer.py index bf67149..ab5f5c3 100644 --- a/patchew/logviewer.py +++ b/patchew/logviewer.py @@ -197,6 +197,9 @@ class ANSI2HTMLConverter(object): # the remaining light colors: dark grey and white self.bg =3D arg - 92 =20 + def _write_form_feed(self): + yield '
' + def _class_to_id(self, html_class): class_id =3D self.class_to_id.get(html_class, None) if class_id is None: @@ -319,7 +322,8 @@ class ANSI2HTMLConverter(object): =20 if csi[-1] =3D=3D 'J': save_pos =3D self.pos - yield from self._write_line('
') + yield from self._write_line('') + yield from self._write_form_feed() self._set_pos(save_pos) elif csi[-1] =3D=3D 'K': self._parse_csi_with_args(csi, self._do_csi_K) @@ -346,7 +350,8 @@ class ANSI2HTMLConverter(object): yield from self._write_line('\n') continue elif seq =3D=3D '\f': - yield from self._write_line('\n
') + yield from self._write_line('\n') + yield from self._write_form_feed() continue =20 if self.lazy_contents !=3D '': --=20 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri May 3 06:52:24 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; dkim=fail; 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 1520496056919932.2665132951437; Thu, 8 Mar 2018 00:00:56 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DCA9356DD; Thu, 8 Mar 2018 08:00:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 020B66134B; Thu, 8 Mar 2018 08:00:56 +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 EE31A4CA99; Thu, 8 Mar 2018 08:00:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2880swN032370 for ; Thu, 8 Mar 2018 03:00:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3C43917996; Thu, 8 Mar 2018 08:00:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34ABC614D0 for ; Thu, 8 Mar 2018 08:00:51 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE5A7285CF for ; Thu, 8 Mar 2018 08:00:48 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id t3so9469470wmc.2 for ; Thu, 08 Mar 2018 00:00:48 -0800 (PST) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id b9sm21755912wrh.68.2018.03.08.00.00.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Mar 2018 00:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=xMux4HtlHc5yORzLzkJhaeITJ9S4pkotopj5COMdbWg=; b=Pqdwei7rEoiTs5/AohlV5glWQRh6CcPrGYmx4ddq3w1N2Ts1o8GDPI+20rtVnkMz7p N3QLXiKCmBiYNv9yL3wE3xr4yOA2dTmKJhELbOrmKnPX3bQqjCBj7XkOn5tN5+EmG9Uw rPmyaBH4ZYGfmImfdx5Wz0iK5vzDJ8J06Z+2tf2MAdMD6S6PqOphNHTer7hdFm/TcG2z v57g96gx0y7LmhmH+wXMp3Bo6Dtl/7eygyRjipPUGUr7P84dbl8k++W82wh8oeylE4+o PvkeVnpjo3H9iGkWIgdtoLxEBp7Wh4pjxSXFVXpR/WQYfrbdvvo/iRzMUdmcrbnvxrIJ hQmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=xMux4HtlHc5yORzLzkJhaeITJ9S4pkotopj5COMdbWg=; b=FBeFyq2xQ0kdQQ4UoVhaLeRstCO0hNmkqkG4t1esCP9tZw2GxKwradu6VlpSzWGABD qAnWOGPTodliRytsE8lpecnAc+8AW5jm9LKEHSZXMMYVjJtochkN/HG7avu0OjStJ/CB qKkcAvbCtgPyayZW6V/EeX3aC+WxA6xB+b7vDzn6oqZLWrw9UKwsc9LphnXVaCh2xZ0B 1Pp9/DhJHzhxk3eerAViKR1wNf6mPeTdLSIkXa5EFhowXj5S60CLYjsK+WxFUiBVRM8B 926i8koyLe1Ko+pY564kwt7FY0uzcC2ovqx5UoKrS6mShUfDEQSd23lIgiOOn3pEO6CC /ZRg== X-Gm-Message-State: AElRT7HYMk0M4GhPobTIJLwWotJJfRY/oj28F8vxsTzd8PDJzA7Re2Rb iHMcC8ENKD6zppokBE36fvwVLnmi X-Google-Smtp-Source: AG47ELtdHjnvlp/wUcaYmoGb6rv4oOSnbdSJlvNRn20Ex+HpknAlvAbXRbSZ6MgcF4zTtOUsjF8n8Q== X-Received: by 10.28.94.11 with SMTP id s11mr16049679wmb.159.1520496046899; Thu, 08 Mar 2018 00:00:46 -0800 (PST) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 8 Mar 2018 09:00:37 +0100 Message-Id: <20180308080042.19342-3-pbonzini@redhat.com> In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com> References: <20180308080042.19342-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Mar 2018 08:00:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Mar 2018 08:00:49 +0000 (UTC) for IP:'74.125.82.68' DOMAIN:'mail-wm0-f68.google.com' HELO:'mail-wm0-f68.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.469 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.68 mail-wm0-f68.google.com 74.125.82.68 mail-wm0-f68.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/7] ansi2html: create ANSIProcessor superclass 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Mar 2018 08:00:56 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- patchew/logviewer.py | 216 ++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 120 insertions(+), 96 deletions(-) diff --git a/patchew/logviewer.py b/patchew/logviewer.py index ab5f5c3..aa5d2bb 100644 --- a/patchew/logviewer.py +++ b/patchew/logviewer.py @@ -15,38 +15,18 @@ from django.views import View from django.http import HttpResponse, StreamingHttpResponse from django.utils.safestring import mark_safe =20 -class ANSI2HTMLConverter(object): +class ANSIProcessor(object): RE_STRING =3D '[^\b\t\n\f\r\x1B]+' RE_NUMS =3D '[0-9]+(?:;[0-9]+)*' RE_CSI =3D r'\[\??(?:' + RE_NUMS + ')?[^;0-9]' RE_OSC =3D r'].*?(?:\x1B\\|\x07)' RE_CONTROL =3D '\x1B(?:%s|%s|[^][])|\r\n|[\b\t\n\f\r]' % (RE_CSI, RE_O= SC) RE =3D re.compile('(%s)|(%s)' % (RE_STRING, RE_CONTROL)) - COLORS =3D [ "BLK", "RED", "GRN", "YEL", "BLU", "MAG", "CYN", "WHI", - "HIK", "HIR", "HIG", "HIY", "HIB", "HIM", "HIC", "HIW" ] - - ENTITIES =3D { - '\x00' : '␀', '\x01' : '␁', '\x02' : '␂', - '\x03' : '␃', '\x04' : '␄', '\x05' : '␅', - '\x06' : '␆', '\x07' : '🔔', '\x0B' : '␋', - '\x0E' : '␎', '\x0F' : '␏', '\x10' : '␐', - '\x11' : '␑', '\x12' : '␒', '\x13' : '␓', - '\x14' : '␔', '\x15' : '␕', '\x16' : '␖', - '\x17' : '␗', '\x18' : '␘', '\x19' : '␙', - '\x1A' : '␚', '\x1B' : '␛', '\x1C' : '␜', - '\x1D' : '␝', '\x1E' : '␞', '\x1F' : '␟', - '<' : '<', '>' : '>', '&' : '&', - '\x7F' : '⌦' - } - RE_ENTITIES =3D re.compile('[\x00-\x1F<>&\x7F]') =20 - def __init__(self, white_bg=3DFalse): + def __init__(self): self.class_to_id =3D {} self.id_to_class =3D [] - self.default_fg =3D 0 if white_bg else 7 - self.default_bg =3D 7 if white_bg else 0 self.cur_class =3D self._class_to_id("") - self.prefix =3D '
'
         self._reset()
         self._reset_attrs()
=20
@@ -99,17 +79,9 @@ class ANSI2HTMLConverter(object):
             self.line +=3D [' '] * num
             self.class_ids +=3D [0] * num
=20
-    def _write_prefix(self):
-        if self.prefix !=3D '':
-            yield self.prefix
-            self.prefix =3D ''
-
+    @abc.abstractmethod
     def _write_span(self, text, class_id):
-        if class_id > 0:
-            yield ('' % self.id_to_class[class_id])
-        yield self.RE_ENTITIES.sub(lambda x: self.ENTITIES[x.group(0)], te=
xt)
-        if class_id > 0:
-            yield ''
+        pass
=20
     # Flushing a line locates spans that have the same style, and prints t=
hose
     # with a  tag if they are styled.
@@ -198,7 +170,7 @@ class ANSI2HTMLConverter(object):
             self.bg =3D arg - 92
=20
     def _write_form_feed(self):
-        yield '
' + pass =20 def _class_to_id(self, html_class): class_id =3D self.class_to_id.get(html_class, None) @@ -208,67 +180,8 @@ class ANSI2HTMLConverter(object): self.id_to_class.append(html_class) return class_id =20 - def _map_color(self, color, default, dim): - # map a color assigned by _do_one_csi_m to an index in the COLORS = array - - color =3D color if color is not None else default - if dim: - # must be foreground color - if isinstance(color, int): - # unlike vte which has a "very dark" grey, for simplicity - # dark grey remains dark grey - return 8 if color =3D=3D default or color =3D=3D 8 else co= lor&~8 - else: - return ('d' + color[0], 'd' + color[1]) - else: - if isinstance(color, int): - # use light colors by default, except for black and light = grey - # (but see bold case in _compute_class) - return color if color =3D=3D 0 or color =3D=3D 7 else colo= r|8 - else: - return color - def _compute_class(self): - fg =3D self._map_color(self.fg, self.default_fg, self.dim) - bg =3D self._map_color(self.bg, self.default_bg, False) - - # apply inverse now: "inverse dim" affects the *background* color! - if self.inverse: - fg, bg =3D bg, fg - - # bold turns foreground light grey into white - if fg =3D=3D 7 and not self.dim and self.bold: - fg =3D 15 - - # now compute CSS classes - classes =3D [] - if isinstance(fg, int): - if fg !=3D self.default_fg: - classes.append(self.COLORS[fg]) - else: - # 256-color palette - classes.append(fg[0]) - - if isinstance(bg, int): - if bg !=3D self.default_bg: - classes.append('B' + self.COLORS[bg]) - else: - classes.append(bg[1]) - - if self.bold: - classes.append('BOLD') - if self.italic: - classes.append('ITA') - - if self.underline or self.strike: - undstr =3D '' - if self.underline: - undstr +=3D 'UND' - if self.strike: - undstr +=3D 'STR' - classes.append(undstr) - - self.cur_class =3D self._class_to_id(" ".join(classes)) + pass =20 def _do_csi_m(self, it): try: @@ -335,7 +248,6 @@ class ANSI2HTMLConverter(object): self._parse_csi_with_args(csi, self._do_csi_m) =20 def convert(self, input): - yield from self._write_prefix() for m in self.RE.finditer(input): if m.group(1): if self.lazy_accumulate: @@ -369,11 +281,123 @@ class ANSI2HTMLConverter(object): elif len(seq) > 1: yield from self._parse_csi(seq) =20 + def finish(self): + yield from self._write_line('') + self._reset_attrs() + + +class ANSI2HTMLConverter(ANSIProcessor): + ENTITIES =3D { + '\x00' : '␀', '\x01' : '␁', '\x02' : '␂', + '\x03' : '␃', '\x04' : '␄', '\x05' : '␅', + '\x06' : '␆', '\x07' : '🔔', '\x0B' : '␋', + '\x0E' : '␎', '\x0F' : '␏', '\x10' : '␐', + '\x11' : '␑', '\x12' : '␒', '\x13' : '␓', + '\x14' : '␔', '\x15' : '␕', '\x16' : '␖', + '\x17' : '␗', '\x18' : '␘', '\x19' : '␙', + '\x1A' : '␚', '\x1B' : '␛', '\x1C' : '␜', + '\x1D' : '␝', '\x1E' : '␞', '\x1F' : '␟', + '<' : '<', '>' : '>', '&' : '&', + '\x7F' : '⌦' + } + RE_ENTITIES =3D re.compile('[\x00-\x1F<>&\x7F]') + + COLORS =3D [ "BLK", "RED", "GRN", "YEL", "BLU", "MAG", "CYN", "WHI", + "HIK", "HIR", "HIG", "HIY", "HIB", "HIM", "HIC", "HIW" ] + + def __init__(self, white_bg=3DFalse): + super(ANSI2HTMLConverter, self).__init__() + self.default_fg =3D 0 if white_bg else 7 + self.default_bg =3D 7 if white_bg else 0 + self.prefix =3D '
'
+
+    def _write_prefix(self):
+        if self.prefix !=3D '':
+            yield self.prefix
+            self.prefix =3D ''
+
+    def _map_color(self, color, default, dim):
+        # map a color assigned by _do_one_csi_m to an index in the COLORS =
array
+
+        color =3D color if color is not None else default
+        if dim:
+            # must be foreground color
+            if isinstance(color, int):
+                # unlike vte which has a "very dark" grey, for simplicity
+                # dark grey remains dark grey
+                return 8 if color =3D=3D default or color =3D=3D 8 else co=
lor&~8
+            else:
+                return ('d' + color[0], 'd' + color[1])
+        else:
+            if isinstance(color, int):
+                # use light colors by default, except for black and light =
grey
+                # (but see bold case in _compute_class)
+                return color if color =3D=3D 0 or color =3D=3D 7 else colo=
r|8
+            else:
+                return color
+
+    def _compute_class(self):
+        fg =3D self._map_color(self.fg, self.default_fg, self.dim)
+        bg =3D self._map_color(self.bg, self.default_bg, False)
+
+        # apply inverse now: "inverse dim" affects the *background* color!
+        if self.inverse:
+            fg, bg =3D bg, fg
+
+        # bold turns foreground light grey into white
+        if fg =3D=3D 7 and not self.dim and self.bold:
+            fg =3D 15
+
+        # now compute CSS classes
+        classes =3D []
+        if isinstance(fg, int):
+            if fg !=3D self.default_fg:
+                classes.append(self.COLORS[fg])
+        else:
+            # 256-color palette
+            classes.append(fg[0])
+
+        if isinstance(bg, int):
+            if bg !=3D self.default_bg:
+                classes.append('B' + self.COLORS[bg])
+        else:
+            classes.append(bg[1])
+
+        if self.bold:
+            classes.append('BOLD')
+        if self.italic:
+            classes.append('ITA')
+
+        if self.underline or self.strike:
+            undstr =3D ''
+            if self.underline:
+                undstr +=3D 'UND'
+            if self.strike:
+                undstr +=3D 'STR'
+            classes.append(undstr)
+
+        self.cur_class =3D self._class_to_id(" ".join(classes))
+
+    def _write_span(self, text, class_id):
+        if class_id > 0:
+            yield ('' % self.id_to_class[class_id])
+        yield self.RE_ENTITIES.sub(lambda x: self.ENTITIES[x.group(0)], te=
xt)
+        if class_id > 0:
+            yield ''
+
+    def _write_form_feed(self):
+        yield '
' + + def convert(self, input): + yield from self._write_prefix() + yield from super(ANSI2HTMLConverter, self).convert(input) + def finish(self): yield from self._write_prefix() - yield from self._write_line('
') + yield from super(ANSI2HTMLConverter, self).finish() + yield '
' self.prefix =3D '
'
-        self._reset_attrs()
+
=20
 def ansi2html(input, white_bg=3DFalse):
     c =3D ANSI2HTMLConverter(white_bg=3Dwhite_bg)
--=20
2.14.3


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
From nobody Fri May  3 06:52:24 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;
	dkim=fail;
	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 1520496061145156.1656092560952;
 Thu, 8 Mar 2018 00:01:01 -0800 (PST)
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 3901A804F4;
	Thu,  8 Mar 2018 08:01:00 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
 (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 2157217967;
	Thu,  8 Mar 2018 08:01:00 +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 1773E4CA99;
	Thu,  8 Mar 2018 08:01:00 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com
	[10.5.11.13])
	by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id w2880woE032409 for ;
	Thu, 8 Mar 2018 03:00:58 -0500
Received: by smtp.corp.redhat.com (Postfix)
	id 87869608F2; Thu,  8 Mar 2018 08:00:58 +0000 (UTC)
Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com
	[10.5.110.29])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D3A6614D0
	for ; Thu,  8 Mar 2018 08:00:58 +0000 (UTC)
Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com
	[209.85.128.182])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id 3440237E7B
	for ; Thu,  8 Mar 2018 08:00:50 +0000 (UTC)
Received: by mail-wr0-f182.google.com with SMTP id z12so4672211wrg.4
	for ; Thu, 08 Mar 2018 00:00:50 -0800 (PST)
Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it.
	[94.36.191.219]) by smtp.gmail.com with ESMTPSA id
	b9sm21755912wrh.68.2018.03.08.00.00.47 for 
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 08 Mar 2018 00:00:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=sender:from:to:subject:date:message-id:in-reply-to:references;
	bh=eesPaABE/2R7Xuy0SUeJVfJACgFxBGegOWgazei0C7c=;
	b=SllRXVhKyq/E7PZMzJKCi91SWla6oHkXVcOnHzPPW64RzVmP9TtUk/yuvZVhiVIagl
	ufYJNtmjeLIlLC4iMt6sGmIrJHNLdzfzopHAoIM2WD2+7Y/4V65bmjZWoy5hXd6O1NIm
	oq2roDOcwX4IrkagtUpzFehhLlAEiwxXbpUO+VOJ8/E3zCcPi55QavNJ5nV3hauRtQbN
	4GTXKr3ZlCZbJHXhIC0UAvh2PZTNafpYEyEFltMiXacSEU2v826LYlQYRZEBVce54hVH
	zXkmeArY3KqSlpC+G4gDAIy0YCdYfQT6EHZlYKnmwULP8uXnFqakPKcBmQc3506GnzgS
	mcPQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:sender:from:to:subject:date:message-id
	:in-reply-to:references;
	bh=eesPaABE/2R7Xuy0SUeJVfJACgFxBGegOWgazei0C7c=;
	b=il1i0e5O/6Qmv9ebYw7deEWIUzk06kGz9pDq5EbB0jm2L/GL2jEW8cET3a/O4uT/3K
	5i/qi+Cv4i7I3XmkGJaJZlyhnsfv3wLGQBtMA2RWzG3XTXE62GDpkMmIIrM5+e28MDUZ
	jv+MTM9SlHNBR9anVKjMKTDQGFtJ/8T1GMECJB4iQUiaoAAGwhJjf/hvJvadzTVQjuVT
	Z2/pim68h7MQ1kwmXVbC9Xp7V4TE+7gntVVGKafHmo7QTj0dX+QMPD/sevlaGbLvom36
	utMfzmHrsAAPqPhlrzrsrIDZL9xS8loSTBe8TCJIDJTDHggKfn9obFVurydYAxARIitn
	zkRA==
X-Gm-Message-State: APf1xPCj+NxtRIvBCR71Y4zTH/u8aL4PHN7abpdogxTbUXbat/e9F4TQ
	Lu5sXEboAVh94D8+1DVT/KtPf4yk
X-Google-Smtp-Source: 
 AG47ELs2P6Tor340jwDGxOc0CL/1CHXx4I4sKsJcd7ZCunTv8+nOsObmalvslpzgiKsFNdTtYzugLw==
X-Received: by 10.223.153.230 with SMTP id y93mr20881553wrb.215.1520496048311;
	Thu, 08 Mar 2018 00:00:48 -0800 (PST)
From: Paolo Bonzini 
To: patchew-devel@redhat.com
Date: Thu,  8 Mar 2018 09:00:38 +0100
Message-Id: <20180308080042.19342-4-pbonzini@redhat.com>
In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com>
References: <20180308080042.19342-1-pbonzini@redhat.com>
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(mx1.redhat.com [10.5.110.29]);
	Thu, 08 Mar 2018 08:00:50 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com
 [10.5.110.29]);
	Thu, 08 Mar 2018 08:00:50 +0000 (UTC) for IP:'209.85.128.182'
	DOMAIN:'mail-wr0-f182.google.com'
	HELO:'mail-wr0-f182.google.com' FROM:'paolo.bonzini@gmail.com'
	RCPT:''
X-RedHat-Spam-Score: 0.488  (DKIM_SIGNED, DKIM_VALID,
	FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H2,
	SPF_PASS) 209.85.128.182 mail-wr0-f182.google.com 209.85.128.182
	mail-wr0-f182.google.com 
X-RedHat-Possible-Forgery:  Paolo Bonzini
	
X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-loop: patchew-devel@redhat.com
Subject: [Patchew-devel] [PATCH 3/7] ansi2html: create ANSI to text converter
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.27]);
 Thu, 08 Mar 2018 08:01:00 +0000 (UTC)
X-ZohoMail-DKIM: fail (Header signature does not verify)
X-ZohoMail: RDKM_2  RSF_0  Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"

This converter compresses sequences involving carriage returns or
backspaces, to make them readable from an editor or mail reader.

Signed-off-by: Paolo Bonzini 
---
 patchew/logviewer.py      | 29 ++++++++++++++++++
 patchew/settings.py       |  3 ++
 patchew/tags.py           | 19 ++++++++++++
 tests/test_ansi2html.py   | 75 +++++++++++++++++++++++++++++++++++++++++++=
+++-
 tests/test_custom_tags.py | 27 +++++++++++++++++
 5 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 patchew/tags.py
 create mode 100755 tests/test_custom_tags.py

diff --git a/patchew/logviewer.py b/patchew/logviewer.py
index aa5d2bb..fe0f3ca 100644
--- a/patchew/logviewer.py
+++ b/patchew/logviewer.py
@@ -286,6 +286,29 @@ class ANSIProcessor(object):
         self._reset_attrs()
=20
=20
+class ANSI2TextConverter(ANSIProcessor):
+    FF =3D '\u2500' * 72 + '\n'
+    SYMBOLS =3D {
+        '\x00' : '\u2400', '\x01' : '\u2401',      '\x02' : '\u2402',
+        '\x03' : '\u2403', '\x04' : '\u2404',      '\x05' : '\u2405',
+        '\x06' : '\u2406', '\x07' : '\U00001F514', '\x0B' : '\u240B',
+        '\x0E' : '\u240E', '\x0F' : '\u240F',      '\x10' : '\u2410',
+        '\x11' : '\u2411', '\x12' : '\u2412',      '\x13' : '\u2413',
+        '\x14' : '\u2414', '\x15' : '\u2415',      '\x16' : '\u2416',
+        '\x17' : '\u2417', '\x18' : '\u2418',      '\x19' : '\u2419',
+        '\x1A' : '\u241A', '\x1B' : '\u241B',      '\x1C' : '\u241C',
+        '\x1D' : '\u241D', '\x1E' : '\u241E',      '\x1F' : '\u241F',
+        '\x7F' : '\u2326'
+    }
+    RE_SYMBOLS =3D re.compile('[\x00-\x1F\x7F]')
+
+    def _write_span(self, text, class_id):
+        yield self.RE_SYMBOLS.sub(lambda x: self.SYMBOLS[x.group(0)], text)
+
+    def _write_form_feed(self):
+        yield self.FF
+
+
 class ANSI2HTMLConverter(ANSIProcessor):
     ENTITIES =3D {
         '\x00' : '␀', '\x01' : '␁',  '\x02' : '␂',
@@ -399,6 +422,12 @@ class ANSI2HTMLConverter(ANSIProcessor):
         self.prefix =3D '
'
=20
=20
+def ansi2text(input):
+    c =3D ANSI2TextConverter()
+    yield from c.convert(input)
+    yield from c.finish()
+
+
 def ansi2html(input, white_bg=3DFalse):
     c =3D ANSI2HTMLConverter(white_bg=3Dwhite_bg)
     yield from c.convert(input)
diff --git a/patchew/settings.py b/patchew/settings.py
index 90a28c3..65a3b29 100644
--- a/patchew/settings.py
+++ b/patchew/settings.py
@@ -84,6 +84,9 @@ TEMPLATES =3D [
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
             ],
+            'builtins': [
+                'patchew.tags',
+            ],
         },
     },
 ]
diff --git a/patchew/tags.py b/patchew/tags.py
new file mode 100644
index 0000000..22d64b0
--- /dev/null
+++ b/patchew/tags.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+#
+# Copyright 2018 Red Hat, Inc.
+#
+# Authors:
+#     Paolo Bonzini 
+#
+# This work is licensed under the MIT License.  Please see the LICENSE fil=
e or
+# http://opensource.org/licenses/MIT.
+
+from django import template
+from patchew import logviewer
+
+register =3D template.Library()
+
+@register.simple_tag
+@register.filter
+def ansi2text(value):
+    return ''.join(logviewer.ansi2text(value))
diff --git a/tests/test_ansi2html.py b/tests/test_ansi2html.py
index cb709fd..e146c3e 100644
--- a/tests/test_ansi2html.py
+++ b/tests/test_ansi2html.py
@@ -6,7 +6,7 @@
=20
 import unittest
=20
-from patchew.logviewer import ansi2html
+from patchew.logviewer import ansi2html, ansi2text, ANSI2TextConverter
=20
 class ANSI2HTMLTest(unittest.TestCase):
     def assertAnsi(self, test, expected, **kwargs):
@@ -291,5 +291,78 @@ class ANSI2HTMLTest(unittest.TestCase):
         self.assertWhiteBg('abc\x1b[7m\x1b[1Kabc', '   abc')
=20
=20
+class ANSI2TextTest(unittest.TestCase):
+    def assertAnsi(self, test, expected, **kwargs):
+        self.assertEqual(''.join(ansi2text(test, **kwargs)), expected,
+                         repr(test))
+
+    # basic formatting tests
+    def test_basic(self):
+        self.assertAnsi('\tb', '        b')
+        self.assertAnsi('\t\ta', '                a')
+        self.assertAnsi('a\tb', 'a       b')
+        self.assertAnsi('ab\tc', 'ab      c')
+        self.assertAnsi('a\nbc', 'a\nbc')
+        self.assertAnsi('a\f', 'a\n' + ANSI2TextConverter.FF)
+        self.assertAnsi('a\n\f', 'a\n\n' + ANSI2TextConverter.FF)
+        self.assertAnsi('<', '<')
+        self.assertAnsi('\x07', '\U00001F514')
+
+    # backspace and carriage return
+    def test_set_pos(self):
+        self.assertAnsi('abc\b\bBC', 'aBC')
+        self.assertAnsi('a\b<', '<')
+        self.assertAnsi('<\ba', 'a')
+        self.assertAnsi('a\b\bbc', 'bc')
+        self.assertAnsi('a\rbc', 'bc')
+        self.assertAnsi('a\nb\bc', 'a\nc')
+        self.assertAnsi('a\t\bb', 'a      b')
+        self.assertAnsi('a\tb\b\bc', 'a      cb')
+        self.assertAnsi('01234567\r\tb', '01234567b')
+
+    # Escape sequences
+    def test_esc_parsing(self):
+        self.assertAnsi('{\x1b%}', '{}')
+        self.assertAnsi('{\x1b[0m}', '{}')
+        self.assertAnsi('{\x1b[m}', '{}')
+        self.assertAnsi('{\x1b[0;1;7;0m}', '{}')
+        self.assertAnsi('{\x1b[1;7m\x1b[m}', '{}')
+        self.assertAnsi('{\x1b]test\x1b\\}', '{}')
+        self.assertAnsi('{\x1b]test\x07}', '{}')
+        self.assertAnsi('{\x1b]test\x1b[0m\x07}', '{}')
+        self.assertAnsi('{\x1b]test\x1b[7m\x07}', '{}')
+
+    # ESC [C and ESC [D
+    def test_horiz_movement(self):
+        self.assertAnsi('abc\x1b[2DB', 'aBc')
+        self.assertAnsi('abc\x1b[3CD', 'abc   D')
+        self.assertAnsi('abcd\x1b[3DB\x1b[1CD', 'aBcD')
+        self.assertAnsi('abc\x1b[0CD', 'abc D')
+        self.assertAnsi('abc\x1b[CD', 'abc D')
+
+    # ESC [K
+    def test_clear_line(self):
+        self.assertAnsi('\x1b[Kabcd', 'abcd')
+        self.assertAnsi('abcd\r\x1b[K', '')
+        self.assertAnsi('abcd\b\x1b[K', 'abc')
+        self.assertAnsi('abcd\r\x1b[KDef', 'Def')
+        self.assertAnsi('abcd\b\x1b[KDef', 'abcDef')
+        self.assertAnsi('abcd\r\x1b[0K', '')
+        self.assertAnsi('abcd\b\x1b[0K', 'abc')
+        self.assertAnsi('abcd\r\x1b[1K', 'abcd')
+        self.assertAnsi('abcd\b\x1b[1K', '   d')
+        self.assertAnsi('abcd\r\x1b[2K', '')
+        self.assertAnsi('abcd\b\x1b[2K', '   ')
+        self.assertAnsi('abcd\r\x1b[2KDef', 'Def')
+        self.assertAnsi('abcd\b\x1b[2KDef', '   Def')
+
+    # combining cursor movement and formatting
+    def test_movement_and_formatting(self):
+        self.assertAnsi('\x1b[42m\tabc', '        abc')
+        self.assertAnsi('abc\x1b[42m\x1b[1Kabc', '   abc')
+        self.assertAnsi('\x1b[7m\tabc', '        abc')
+        self.assertAnsi('abc\x1b[7m\x1b[1Kabc', '   abc')
+
+
 if __name__ =3D=3D '__main__':
     unittest.main()
diff --git a/tests/test_custom_tags.py b/tests/test_custom_tags.py
new file mode 100755
index 0000000..ec875c8
--- /dev/null
+++ b/tests/test_custom_tags.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+#
+# Copyright 2018 Red Hat, Inc.
+#
+# Authors:
+#     Paolo Bonzini 
+#
+# This work is licensed under the MIT License.  Please see the LICENSE fil=
e or
+# http://opensource.org/licenses/MIT.
+
+from django.template import Context, Template
+import patchewtest
+import unittest
+
+class CustomTagsTest(unittest.TestCase):
+    def assertTemplate(self, template, expected, **kwargs):
+        context =3D Context(kwargs)
+        self.assertEqual(Template(template).render(context), expected)
+
+    def test_template_filters(self):
+        self.assertTemplate('{{s|ansi2text}}', 'dbc', s=3D'abc\rd')
+
+    def test_template_tags(self):
+        self.assertTemplate('{% ansi2text s %}', 'dbc', s=3D'abc\rd')
+
+if __name__ =3D=3D '__main__':
+    unittest.main()
--=20
2.14.3


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
From nobody Fri May  3 06:52:24 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;
	dkim=fail;
	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 152049605937146.9192381955487;
 Thu, 8 Mar 2018 00:00:59 -0800 (PST)
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 7F22AC04BD5A;
	Thu,  8 Mar 2018 08:00:58 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
 (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 701505C25F;
	Thu,  8 Mar 2018 08:00:58 +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 62E674CA9C;
	Thu,  8 Mar 2018 08:00:58 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com
	[10.5.11.16])
	by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id w2880vdh032398 for ;
	Thu, 8 Mar 2018 03:00:57 -0500
Received: by smtp.corp.redhat.com (Postfix)
	id 3CE815C25A; Thu,  8 Mar 2018 08:00:57 +0000 (UTC)
Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com
	[10.5.110.38])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 33E065C259
	for ; Thu,  8 Mar 2018 08:00:53 +0000 (UTC)
Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com
 [74.125.82.54])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id AA95C4E8AC
	for ; Thu,  8 Mar 2018 08:00:51 +0000 (UTC)
Received: by mail-wm0-f54.google.com with SMTP id w128so9550655wmw.0
	for ; Thu, 08 Mar 2018 00:00:51 -0800 (PST)
Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it.
	[94.36.191.219]) by smtp.gmail.com with ESMTPSA id
	b9sm21755912wrh.68.2018.03.08.00.00.48 for 
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 08 Mar 2018 00:00:49 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=sender:from:to:subject:date:message-id:in-reply-to:references;
	bh=7+eUFXhQDIjkYvjD1vGRCDe0w+Uav0VKq9GLoL1aGtI=;
	b=CB5H7cP7g8IHDHRGjS0jXmVf7w4E8PuXzS+AVV4iwrMrmsp1fndqJQXVi2YxWKaINI
	AUItCH8pywt9eF5Ph+w61GV1X/24cvfvOBOqQYz3bww+n3sdnZFk/g9CN7GPJfu1g08c
	V4HlzphbAItHy+YEDa3mn+PgT9NjyiLmocJwS21d/E9N9L3R7OpHT1QkvFmJc3b5TNGt
	p4jBOUwobFf7w5v7owPE9lkVQfRAhfJvjVDwSR+dwp6/8+rLQMBE1UWg1JXMd9/N2uZH
	WgXLo2SVxBwbJyanv3QooNiyiCQ79qvuLPWXp6LRxDUCJ47UH03DYMKxTXzMevyEkVEP
	8fxg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:sender:from:to:subject:date:message-id
	:in-reply-to:references;
	bh=7+eUFXhQDIjkYvjD1vGRCDe0w+Uav0VKq9GLoL1aGtI=;
	b=m48N+Uc58djtEJEudveC22Zxcj4wtqpkDmINw5t8lUyDA31NEREsR1IuWCQCDhqXPk
	q2pc7cvq59Fqw8NPPbjT+S2w6PdSd5ze5yLE+P1qiFNyo/5LmD592aZMrltX4Ku3b2ML
	F+9cnOMIJrluPj5tia/FVnyH/Szja9Skzb1Nfan43b2+5tL0zOO2tlxge/9Wa1CihYyD
	364XbKD9plI84/kwSm7nUubMgYI8U0t0XPGn2gLEEPSv6pF9UEQn+G8Wt1qFXixpYvFv
	hgjwmE8plkXWJSoHWhpr0l6eVjKZzmN+KTZtXTuthiK86Ovhi0URDLBkIawm2cF14DOR
	gAdQ==
X-Gm-Message-State: AElRT7FeCSCGJI6iVW08FEK7EBmtJ1uX1wSvEUBC4zWe1w5mOO67F52d
	7C6YxJAGLqLVzdK4uCVuWk8KQhQc
X-Google-Smtp-Source: 
 AG47ELtBJlNASTBolY/Tj8sbZXWTf829Dj9Vlv8xlxu0TizNtOlPbm4/F6b1eEl32d4L7Et5LVeI4A==
X-Received: by 10.28.163.5 with SMTP id m5mr15537129wme.7.1520496049747;
	Thu, 08 Mar 2018 00:00:49 -0800 (PST)
From: Paolo Bonzini 
To: patchew-devel@redhat.com
Date: Thu,  8 Mar 2018 09:00:39 +0100
Message-Id: <20180308080042.19342-5-pbonzini@redhat.com>
In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com>
References: <20180308080042.19342-1-pbonzini@redhat.com>
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(mx1.redhat.com [10.5.110.38]);
	Thu, 08 Mar 2018 08:00:52 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com
 [10.5.110.38]);
	Thu, 08 Mar 2018 08:00:52 +0000 (UTC) for IP:'74.125.82.54'
	DOMAIN:'mail-wm0-f54.google.com' HELO:'mail-wm0-f54.google.com'
	FROM:'paolo.bonzini@gmail.com' RCPT:''
X-RedHat-Spam-Score: 0.469  (DKIM_SIGNED, DKIM_VALID,
	FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,
	SPF_PASS) 74.125.82.54 mail-wm0-f54.google.com 74.125.82.54
	mail-wm0-f54.google.com 
X-RedHat-Possible-Forgery:  Paolo Bonzini
	
X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16
X-loop: patchew-devel@redhat.com
Subject: [Patchew-devel] [PATCH 4/7] add custom template tags for
	manipulating testing logs
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.31]);
 Thu, 08 Mar 2018 08:00:58 +0000 (UTC)
X-ZohoMail-DKIM: fail (Header signature does not verify)
X-ZohoMail: RDKM_2  RSF_0  Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"

These can be used to make test report emails shorter and more readable.

Signed-off-by: Paolo Bonzini 
---
 patchew/tags.py           |  77 ++++++++++++++++++++++++++++++++++
 tests/test_custom_tags.py | 102 ++++++++++++++++++++++++++++++++++++++++++=
++++
 2 files changed, 179 insertions(+)

diff --git a/patchew/tags.py b/patchew/tags.py
index 22d64b0..4847cb4 100644
--- a/patchew/tags.py
+++ b/patchew/tags.py
@@ -10,6 +10,57 @@
=20
 from django import template
 from patchew import logviewer
+from collections import deque
+import io
+import operator
+import re
+
+# The basic implementation uses generators.  The filters simply apply join
+# to the result of the generators.
+
+def lines_iter(value):
+    if not isinstance(value, io.IOBase):
+        # StringIO provides a generator to split lines.
+        value =3D io.StringIO(value)
+    # "chomp" the newlines on each line.  Using operator and map does
+    # everything in the interpreter, avoiding the overhead of a generator.
+    return map(operator.methodcaller('rstrip', '\r\n'), value)
+
+# To understand grep_iter, it may help to first study this implementation
+# of a "tail" iterator, which is based on the same circular array idea:
+#
+#    def tail_lines_iter(value, n):
+#        lines =3D [None] * n
+#        lineno =3D 0
+#        for line in lines_iter(value):
+#            lines[lineno % n] =3D line
+#            lineno +=3D 1
+#
+#        for i in range(max(lineno - n, 0), lineno):
+#            yield lines[i % n]
+#
+# Basic "grep" prints one line when the match is on the last line, so
+# "grep" is a variation on tail_lines with n=3D1; likewise, "grep -B1" is
+# a variation on tail_lines with n=3D2, etc.
+
+def grep_iter(value, regex, n_before, n_after, sep):
+    n =3D n_before + 1
+    lines =3D [None] * n
+    stop =3D lineno =3D 0
+    for line in lines_iter(value):
+        # Print the (lineno - n)-th line.  Each element of lines[] is used
+        # just before it is thrown away.
+        if lineno - n >=3D 0 and lineno - n < stop:
+            yield lines[lineno % n]
+        if re.search(regex, line):
+            if lineno - n >=3D stop and sep is not None and stop > 0:
+                yield sep
+            stop =3D lineno + n_after + 1
+        lines[lineno % n] =3D line
+        lineno +=3D 1
+
+    for i in range(max(lineno - n, 0), min(stop, lineno)):
+        yield lines[i % n]
=20
 register =3D template.Library()
=20
@@ -17,3 +68,29 @@ register =3D template.Library()
 @register.filter
 def ansi2text(value):
     return ''.join(logviewer.ansi2text(value))
+
+@register.simple_tag
+@register.filter
+def tail_lines(value, n):
+    lines =3D deque(lines_iter(value), n)
+    return '\n'.join(lines)
+
+@register.simple_tag
+@register.filter
+def grep(value, regex, sep=3DNone):
+    return '\n'.join(grep_iter(value, regex, 0, 0, sep))
+
+@register.simple_tag
+@register.filter
+def grep_A(value, regex, n=3D3, sep=3D'---'):
+    return '\n'.join(grep_iter(value, regex, 0, n, sep))
+
+@register.simple_tag
+@register.filter
+def grep_B(value, regex, n=3D3, sep=3D'---'):
+    return '\n'.join(grep_iter(value, regex, n, 0, sep))
+
+@register.simple_tag
+@register.filter
+def grep_C(value, regex, n=3D3, sep=3D'---'):
+    return '\n'.join(grep_iter(value, regex, n, n, sep))
diff --git a/tests/test_custom_tags.py b/tests/test_custom_tags.py
index ec875c8..aa828be 100755
--- a/tests/test_custom_tags.py
+++ b/tests/test_custom_tags.py
@@ -9,6 +9,7 @@
 # http://opensource.org/licenses/MIT.
=20
 from django.template import Context, Template
+from patchew.tags import tail_lines, grep_A, grep_B, grep_C, grep
 import patchewtest
 import unittest
=20
@@ -19,9 +20,110 @@ class CustomTagsTest(unittest.TestCase):
=20
     def test_template_filters(self):
         self.assertTemplate('{{s|ansi2text}}', 'dbc', s=3D'abc\rd')
+        self.assertTemplate('{{s|grep:"[0-9]"}}', '0\n9', s=3D'0\na\n9')
+        self.assertTemplate('{{s|grep_A:"b"}}',
+                            'b\nc\nd\ne\n---\nb',
+                             s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+        self.assertTemplate('{{s|grep_B:"b"}}',
+                            'a\nb\n---\nx\ny\nz\nb',
+                             s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+        self.assertTemplate('{{s|grep_C:"b"}}',
+                            'a\nb\nc\nd\ne\n---\nx\ny\nz\nb',
+                             s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+        self.assertTemplate('{{s|tail_lines:3}}', 'b\nc\nd', s=3D'a\nb\nc\=
nd')
=20
     def test_template_tags(self):
         self.assertTemplate('{% ansi2text s %}', 'dbc', s=3D'abc\rd')
+        self.assertTemplate('{% grep s "[0-9]" %}', '0\n9', s=3D'0\na\n9')
+        self.assertTemplate('{% grep_A s regex=3D"[bc]" n=3D1 %}', 'b\nc\n=
d', s=3D'a\nb\nc\nd')
+        self.assertTemplate('{% grep_B s regex=3D"[bc]" n=3D1 %}', 'a\nb\n=
c', s=3D'a\nb\nc\nd')
+        self.assertTemplate('{% grep_C s "b" n=3D1 %}', 'a\nb\nc', s=3D'a\=
nb\nc\nd')
+        self.assertTemplate('{% tail_lines s n=3D3 %}', 'b\nc\nd', s=3D'a\=
nb\nc\nd')
+
+    def test_grep(self):
+        self.assertEqual(grep('0\na\n9', '[0-9]'), '0\n9')
+        self.assertEqual(grep('0\na\n9', '[0-9]', '---'), '0\n---\n9')
+
+    def test_grep_A(self):
+        self.assertEqual(grep_A('a\nb\nc\nd', 'b', 1, None), 'b\nc')
+        self.assertEqual(grep_A('a\nb\nc\nd', 'b', 2, None), 'b\nc\nd')
+        self.assertEqual(grep_A('a\nb\nc\nd\nb\ne', 'b', 1, None), 'b\nc\n=
b\ne')
+        self.assertEqual(grep_A('a\nb\nc\nd\nb\ne', 'b', 2, None), 'b\nc\n=
d\nb\ne')
+        self.assertEqual(grep_A('a\nb\nc\nd\nz\nb\ne', 'b', 1, None), 'b\n=
c\nb\ne')
+        self.assertEqual(grep_A('a\nb\nc\nd\nz\nb\ne', 'b', 2, None), 'b\n=
c\nd\nb\ne')
+        self.assertEqual(grep_A('a\nb\nc\nz\nb\nb\ne', 'b', 1, None), 'b\n=
c\nb\nb\ne')
+        self.assertEqual(grep_A('b\nc\nz\nb\nb\ne', 'b', 1, None), 'b\nc\n=
b\nb\ne')
+        self.assertEqual(grep_A('b\n', 'b', 1, None), 'b')
+
+    def test_grep_A_sep(self):
+        self.assertEqual(grep_A('a\nb\nc\nd', 'b', 1), 'b\nc')
+        self.assertEqual(grep_A('a\nb\nc\nd', 'b', 2), 'b\nc\nd')
+        self.assertEqual(grep_A('a\nb\nc\nd\nb\ne', 'b', 1), 'b\nc\n---\nb=
\ne')
+        self.assertEqual(grep_A('a\nb\nc\nd\nb\ne', 'b', 2), 'b\nc\nd\nb\n=
e')
+        self.assertEqual(grep_A('a\nb\nc\nd\nz\nb\ne', 'b', 1), 'b\nc\n---=
\nb\ne')
+        self.assertEqual(grep_A('a\nb\nc\nd\nz\nb\nb\ne', 'b', 1), 'b\nc\n=
---\nb\nb\ne')
+        self.assertEqual(grep_A('b\nc\nz\nb\nb\ne', 'b', 1), 'b\nc\n---\nb=
\nb\ne')
+        self.assertEqual(grep_A('b\n', 'b', 1), 'b')
+
+    def test_grep_B(self):
+        self.assertEqual(grep_B('a\nb\nc\nd', 'b', 1, None), 'a\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd', 'b', 2, None), 'a\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nb\ne', 'b', 1, None), 'a\nb\n=
d\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nz\nb\ne', 'b', 1, None), 'a\n=
b\nz\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nz\nb\ne', 'b', 2, None), 'a\n=
b\nd\nz\nb')
+        self.assertEqual(grep_B('a\nb\nc\nz\nb\nb\ne', 'b', 1, None), 'a\n=
b\nz\nb\nb')
+        self.assertEqual(grep_B('b\nc\nz\nb\nb\ne', 'b', 1, None), 'b\nz\n=
b\nb')
+        self.assertEqual(grep_B('b\n', 'b', 1, None), 'b')
+
+    def test_grep_B_sep(self):
+        self.assertEqual(grep_B('a\nb\nc\nd', 'b', 1), 'a\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd', 'b', 2), 'a\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nb\ne', 'b', 1), 'a\nb\n---\nd=
\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nz\nb\ne', 'b', 1), 'a\nb\n---=
\nz\nb')
+        self.assertEqual(grep_B('a\nb\nc\nd\nz\nb\ne', 'b', 2), 'a\nb\n---=
\nd\nz\nb')
+        self.assertEqual(grep_B('a\nb\nc\nz\nb\nb\ne', 'b', 1), 'a\nb\n---=
\nz\nb\nb')
+        self.assertEqual(grep_B('b\nc\nz\nb\nb\ne', 'b', 1), 'b\n---\nz\nb=
\nb')
+        self.assertEqual(grep_B('b\n', 'b', 1), 'b')
+
+    def test_grep_C(self):
+        self.assertEqual(grep_C('a\nb\nc\nd', 'b', 1, None), 'a\nb\nc')
+        self.assertEqual(grep_C('a\nb\nc\nd', 'b', 2, None), 'a\nb\nc\nd')
+        self.assertEqual(grep_C('a\nb\nc\nd\nb\ne', 'b', 1, None), 'a\nb\n=
c\nd\nb\ne')
+        self.assertEqual(grep_C('a\nb\nc\nd\nz\nb\ne', 'b', 1, None), 'a\n=
b\nc\nz\nb\ne')
+        self.assertEqual(grep_C('a\nb\nc\nd\nz\nb\ne', 'b', 2, None), 'a\n=
b\nc\nd\nz\nb\ne')
+        self.assertEqual(grep_C('a\nb\nc\nz\nb\nb\ne', 'b', 1, None), 'a\n=
b\nc\nz\nb\nb\ne')
+        self.assertEqual(grep_C('b\nc\nz\nb\nb\ne', 'b', 1, None), 'b\nc\n=
z\nb\nb\ne')
+        self.assertEqual(grep_C('b\n', 'b', 1, None), 'b')
+
+    def test_grep_C_sep(self):
+        self.assertEqual(grep_C('a\nb\nc\nd', 'b', 1), 'a\nb\nc')
+        self.assertEqual(grep_C('a\nb\nc\nd', 'b', 2), 'a\nb\nc\nd')
+        self.assertEqual(grep_C('a\nb\nc\nd\nb\ne', 'b', 1), 'a\nb\nc\nd\n=
b\ne')
+        self.assertEqual(grep_C('a\nb\nc\nd\nz\nb\ne', 'b', 1), 'a\nb\nc\n=
---\nz\nb\ne')
+        self.assertEqual(grep_C('a\nb\nc\nd\nz\nb\ne', 'b', 2), 'a\nb\nc\n=
d\nz\nb\ne')
+        self.assertEqual(grep_C('a\nb\nc\nz\nb\nb\ne', 'b', 1), 'a\nb\nc\n=
z\nb\nb\ne')
+        self.assertEqual(grep_C('b\nc\nz\nb\nb\ne', 'b', 1), 'b\nc\nz\nb\n=
b\ne')
+        self.assertEqual(grep_C('b\n', 'b', 1), 'b')
+
+    def test_tail_lines(self):
+        self.assertEqual(tail_lines('', 0), '')
+        self.assertEqual(tail_lines('', 1), '')
+        self.assertEqual(tail_lines('', 2), '')
+        self.assertEqual(tail_lines('', 4), '')
+
+        self.assertEqual(tail_lines('a\nb\n', 0), '')
+        self.assertEqual(tail_lines('a\nb\n', 1), 'b')
+        self.assertEqual(tail_lines('a\nb\n', 2), 'a\nb')
+
+        self.assertEqual(tail_lines('a\nb\nc\n', 2), 'b\nc')
+        self.assertEqual(tail_lines('a\nb\nc\n', 4), 'a\nb\nc')
+
+        self.assertEqual(tail_lines('a\nb\nc\nd\n', 2), 'c\nd')
+
+        self.assertEqual(tail_lines('\n\n\n', 2), '\n')
+        self.assertEqual(tail_lines('\n\n\nbc', 2), '\nbc')
+        self.assertEqual(tail_lines('\n\nbc', 3), '\n\nbc')
+        self.assertEqual(tail_lines('\n\n\n\nbc', 3), '\n\nbc')
=20
 if __name__ =3D=3D '__main__':
     unittest.main()
--=20
2.14.3


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
From nobody Fri May  3 06:52:24 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;
	dkim=fail;
	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 1520496055951914.9412712547806;
 Thu, 8 Mar 2018 00:00:55 -0800 (PST)
Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com
 [10.5.11.14])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id 073D6C04BE07;
	Thu,  8 Mar 2018 08:00:55 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
 (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id EB1E017D1C;
	Thu,  8 Mar 2018 08:00:54 +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 E13C04CA99;
	Thu,  8 Mar 2018 08:00:54 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com
	[10.5.11.12])
	by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id w2880siq032363 for ;
	Thu, 8 Mar 2018 03:00:54 -0500
Received: by smtp.corp.redhat.com (Postfix)
	id 2507E9F73; Thu,  8 Mar 2018 08:00:54 +0000 (UTC)
Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com
	[10.5.110.31])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DE4E9F72
	for ; Thu,  8 Mar 2018 08:00:54 +0000 (UTC)
Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com
 [74.125.82.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id DA76EC04AC4B
	for ; Thu,  8 Mar 2018 08:00:52 +0000 (UTC)
Received: by mail-wm0-f66.google.com with SMTP id x7so9281804wmc.0
	for ; Thu, 08 Mar 2018 00:00:52 -0800 (PST)
Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it.
	[94.36.191.219]) by smtp.gmail.com with ESMTPSA id
	b9sm21755912wrh.68.2018.03.08.00.00.49 for 
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 08 Mar 2018 00:00:50 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=sender:from:to:subject:date:message-id:in-reply-to:references;
	bh=iJqLnYTNpTpXBPTFDu7Pv1bb7QZJPS1ExevtXSX+FcU=;
	b=IcUz8J5l5XxxQ/uFI2blrX++Fh4mupGc4CFeIAsfrK6pR9iz5oQwS4WKNYd2xNH/rr
	9W6bFnwHjBvAY/IIqCr9KJCdq4IxqQsyNtsVH1kkFjAH2/viL8HURkB0bSG8IN/75O9h
	Q8DjqucWkIRfGme0hfssp2djRsqoIHMbLmrj5QxF25x+cto7oQPLngiFtcvQ5vwRd5w+
	6Z+WxkaklMqFnyqn8FGsdEnG5ufpJitOmOhwc0hq7D2iHciYXtsKVvXFvNTFHMzhD5yN
	2srxrgkLD8sE4gmygaLKPSTfr3WvIWFaiRmVvQFvM2BJogoQkEnS6XCbjvyIbUEvInjp
	RheA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:sender:from:to:subject:date:message-id
	:in-reply-to:references;
	bh=iJqLnYTNpTpXBPTFDu7Pv1bb7QZJPS1ExevtXSX+FcU=;
	b=SiaxByypz7eejTmjvEO7MSvoxQYd3SNISnUZnOGcCJ3F9ibM6yxbat+5tFPwuu8/h5
	1q+a46VnMQsMG5CknhyHknHWRkT9idSWAUA5Iv2bKNV2ATnPDuoJqINI6VEkv70xcgIf
	ap/qvvmqlPoWTsSL/gVhIxtpK5VJJYP2k5BH6zWvTvB8ESVHAkVC4jg6BSur7iHp8S75
	8FZ0zTYGK+2I1ln8lJbdWqW+JFnaGxcLPjX0PP8soChsLPAuo6j6ecRx4LcN2g3pu53d
	x+Jey82WQqugMm4yTAI0eTmf5TQ+sEfEoSvTHdavafYnoIbzs0bwznrYWCaxeFoX7nd1
	h8VQ==
X-Gm-Message-State: AElRT7GrQ7OlzWIugQJujr+T87tnRZSoYixgn/cAp1y1n0U5ADbf45FC
	HPNtglWdj3snmWEVF17lFaHxPcyp
X-Google-Smtp-Source: 
 AG47ELuBmiB9wGiFdjypgMFETuG5rRr/tv6QUU8uHJ2xq6yFS7x5iW5CDRqFuK+7a/DcSgdQScUa2w==
X-Received: by 10.28.193.134 with SMTP id r128mr16042382wmf.85.1520496051101;
	Thu, 08 Mar 2018 00:00:51 -0800 (PST)
From: Paolo Bonzini 
To: patchew-devel@redhat.com
Date: Thu,  8 Mar 2018 09:00:40 +0100
Message-Id: <20180308080042.19342-6-pbonzini@redhat.com>
In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com>
References: <20180308080042.19342-1-pbonzini@redhat.com>
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(mx1.redhat.com [10.5.110.31]);
	Thu, 08 Mar 2018 08:00:53 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com
 [10.5.110.31]);
	Thu, 08 Mar 2018 08:00:53 +0000 (UTC) for IP:'74.125.82.66'
	DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com'
	FROM:'paolo.bonzini@gmail.com' RCPT:''
X-RedHat-Spam-Score: 0.469  (DKIM_SIGNED, DKIM_VALID,
	FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,
	SPF_PASS) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66
	mail-wm0-f66.google.com 
X-RedHat-Possible-Forgery:  Paolo Bonzini
	
X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12
X-loop: patchew-devel@redhat.com
Subject: [Patchew-devel] [PATCH 5/7] rest: pass request to hooks
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.14
X-Greylist: Sender IP whitelisted,
 not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]);
 Thu, 08 Mar 2018 08:00:55 +0000 (UTC)
X-ZohoMail-DKIM: fail (Header signature does not verify)
X-ZohoMail: RDKM_2  RSF_0  Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"

The request is needed by rest_framework.reverse.reverse.  It is already
passed to the plugins via PluginMethodField, pass it to the hooks as
well.

Signed-off-by: Paolo Bonzini 
---
 api/rest.py     | 12 +++++++++---
 mods/diff.py    |  2 +-
 mods/git.py     |  2 +-
 mods/tags.py    |  2 +-
 mods/testing.py |  2 +-
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/api/rest.py b/api/rest.py
index be774a9..7c131a4 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -171,12 +171,16 @@ class SeriesSerializer(BaseMessageSerializer):
=20
     def get_fields(self):
         fields =3D super(SeriesSerializer, self).get_fields()
-        dispatch_module_hook("rest_series_fields_hook", fields=3Dfields, d=
etailed=3Dself.detailed)
+        request =3D self.context['request']
+        dispatch_module_hook("rest_series_fields_hook", request=3Drequest,
+                             fields=3Dfields, detailed=3Dself.detailed)
         return fields
=20
     def get_results(self, message):
         results =3D {}
-        dispatch_module_hook("rest_results_hook", message=3Dmessage, resul=
ts=3Dresults)
+        request =3D self.context['request']
+        dispatch_module_hook("rest_results_hook", request=3Drequest,
+                             message=3Dmessage, results=3Dresults)
         return results
=20
     def get_total_patches(self, obj):
@@ -276,7 +280,9 @@ class MessageSerializer(BaseMessageSerializer):
=20
     def get_fields(self):
         fields =3D super(MessageSerializer, self).get_fields()
-        dispatch_module_hook("rest_message_fields_hook", fields=3Dfields)
+        request =3D self.context['request']
+        dispatch_module_hook("rest_message_fields_hook", request=3Drequest,
+                             fields=3Dfields)
         return fields
=20
 class StaticTextRenderer(renderers.BaseRenderer):
diff --git a/mods/diff.py b/mods/diff.py
index eb8dfb8..38404e0 100644
--- a/mods/diff.py
+++ b/mods/diff.py
@@ -60,7 +60,7 @@ class DiffModule(PatchewModule):
                  for o in sorted(other_versions, key=3Dlambda y: y.version)
                  if o.message_id !=3D message.message_id]
=20
-    def rest_series_fields_hook(self, fields, detailed):
+    def rest_series_fields_hook(self, request, fields, detailed):
         fields['version'] =3D rest_framework.fields.IntegerField()
         if detailed:
             fields['other_versions'] =3D PluginMethodField(obj=3Dself)
diff --git a/mods/git.py b/mods/git.py
index b0df7e8..2489f5a 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -113,7 +113,7 @@ class GitModule(PatchewModule):
             raise Exception("Project git repo invalid: %s" % project_git)
         return upstream, branch
=20
-    def rest_results_hook(self, message, results):
+    def rest_results_hook(self, request, message, results):
         l =3D message.get_property("git.apply-log")
         if l:
             if message.get_property("git.apply-failed"):
diff --git a/mods/tags.py b/mods/tags.py
index 5a776ed..5ec5bc2 100644
--- a/mods/tags.py
+++ b/mods/tags.py
@@ -123,7 +123,7 @@ series cover letter, patch mail body and their replies.
     def get_tags(self, m, request, format):
         return m.get_property("tags", [])
=20
-    def rest_message_fields_hook(self, fields):
+    def rest_message_fields_hook(self, request, fields):
         fields['tags'] =3D PluginMethodField(obj=3Dself)
=20
     def prepare_message_hook(self, request, message, detailed):
diff --git a/mods/testing.py b/mods/testing.py
index 47933e2..b822a34 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -257,7 +257,7 @@ class TestingModule(PatchewModule):
         return reverse("testing-get-prop",
                        kwargs=3D{"project_or_series": obj.message_id})
=20
-    def rest_results_hook(self, message, results):
+    def rest_results_hook(self, request, message, results):
         for pn, p in message.get_properties().items():
             if not pn.startswith("testing.report."):
                 continue
--=20
2.14.3


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
From nobody Fri May  3 06:52:24 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;
	dkim=fail;
	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 1520496058035154.87694374580292;
 Thu, 8 Mar 2018 00:00:58 -0800 (PST)
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 2A01581DEA;
	Thu,  8 Mar 2018 08:00:57 +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 15E285C259;
	Thu,  8 Mar 2018 08:00:57 +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 08E47180613A;
	Thu,  8 Mar 2018 08:00:57 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com
	[10.5.11.13])
	by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id w2880tM0032382 for ;
	Thu, 8 Mar 2018 03:00:55 -0500
Received: by smtp.corp.redhat.com (Postfix)
	id 99FB6608F2; Thu,  8 Mar 2018 08:00:55 +0000 (UTC)
Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com
	[10.5.110.28])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 931C8614D0
	for ; Thu,  8 Mar 2018 08:00:55 +0000 (UTC)
Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com
 [74.125.82.67])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id 719E880461
	for ; Thu,  8 Mar 2018 08:00:54 +0000 (UTC)
Received: by mail-wm0-f67.google.com with SMTP id w128so9550898wmw.0
	for ; Thu, 08 Mar 2018 00:00:54 -0800 (PST)
Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it.
	[94.36.191.219]) by smtp.gmail.com with ESMTPSA id
	b9sm21755912wrh.68.2018.03.08.00.00.51 for 
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 08 Mar 2018 00:00:51 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=sender:from:to:subject:date:message-id:in-reply-to:references;
	bh=RtZu3nXQxYkEFoJbVuHwFeF/x+DI+yF7QWnj//Kw8ss=;
	b=dk9L7PddEtRq4v1/1wsaYMzQVAccXTvLbOvO++aUpae50BauTWplsrK3PWfQCBgTkC
	NtVivracDtO0HPnILOLTuCfUWgtYwtovO1N4VYOGyFj41t4W+RZ104nlFg1O4lOmJkFY
	2B8MmHK9LcaP6/3t3DOwWno6tF35x0zpZbN79/GBvQTrLbgsorHAicrPRjvDoghwcHeO
	+jjlH0GbImvhVWL44is9NsW7GSJ9ytn1IYDVduvTf1uN79gPhWqRmVzmNXvVw2AA5iC+
	SVKnAwMqHfUwWMlwKan4sT9qrsf6ZhpIsyLUCM9qdcdGTDB8bcpelwWSDI0eqixhoVpi
	msig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:sender:from:to:subject:date:message-id
	:in-reply-to:references;
	bh=RtZu3nXQxYkEFoJbVuHwFeF/x+DI+yF7QWnj//Kw8ss=;
	b=pyjX5YMupQKTaey0iJNHd0lSzUyXXz/8O4BWeqABsbf1xAhPTGltX8ccli4JnFu00D
	Abi61ss7OPh9XljqhUNUqKMdt+JmCTBrIYfV8euF5qcQbdeK53PyPvCRjT8ci8HhkkNQ
	SnenXYV5r4mtTjlcsmxnihBerJP57A/p5wZLp/TOq2AVn4ckOOJFRp1emoGFnZueQnl0
	znJHnnQMXIJkW7+maQ2Xrn8sqFxN0Q9CVxu0rCGqz11F4hYakDVPOvZBR5gCu+XqPOFM
	xgWkkJevIag6GACYuaUidekkInTV7iFOguzb8qgkig7/mUVAZSKFXzOHQ7es5/HQpVoN
	lVIQ==
X-Gm-Message-State: AElRT7HdvMe334m1pAELCrKP/LujcoTTdbdK5ova+4L7mVGUKGAT+IQY
	PAZGuZqCJec/mVTxbvyzeHLRKZW4
X-Google-Smtp-Source: 
 AG47ELtEIyUBvKrglIQKZDJAU1bTAQwtIcV+4sopmpwZzTLWNzLONmBCfC4kOhVqnzvSv+s7ghMv0g==
X-Received: by 10.28.232.89 with SMTP id f86mr17479814wmh.72.1520496052682;
	Thu, 08 Mar 2018 00:00:52 -0800 (PST)
From: Paolo Bonzini 
To: patchew-devel@redhat.com
Date: Thu,  8 Mar 2018 09:00:41 +0100
Message-Id: <20180308080042.19342-7-pbonzini@redhat.com>
In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com>
References: <20180308080042.19342-1-pbonzini@redhat.com>
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(mx1.redhat.com [10.5.110.28]);
	Thu, 08 Mar 2018 08:00:54 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com
 [10.5.110.28]);
	Thu, 08 Mar 2018 08:00:54 +0000 (UTC) for IP:'74.125.82.67'
	DOMAIN:'mail-wm0-f67.google.com' HELO:'mail-wm0-f67.google.com'
	FROM:'paolo.bonzini@gmail.com' RCPT:''
X-RedHat-Spam-Score: 0.469  (DKIM_SIGNED, DKIM_VALID,
	FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,
	SPF_PASS) 74.125.82.67 mail-wm0-f67.google.com 74.125.82.67
	mail-wm0-f67.google.com 
X-RedHat-Possible-Forgery:  Paolo Bonzini
	
X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13
X-loop: patchew-devel@redhat.com
Subject: [Patchew-devel] [PATCH 6/7] testing: add reverse_testing_log
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.25]);
 Thu, 08 Mar 2018 08:00:57 +0000 (UTC)
X-ZohoMail-DKIM: fail (Header signature does not verify)
X-ZohoMail: RDKM_2  RSF_0  Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"

Abstract the creation of testing log URLs.

Signed-off-by: Paolo Bonzini 
---
 mods/testing.py | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/mods/testing.py b/mods/testing.py
index b822a34..ea6fdf5 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -146,6 +146,24 @@ class TestingModule(PatchewModule):
                                TestingLogViewer.as_view(),
                                name=3D"testing-log"))
=20
+    def reverse_testing_log(self, obj, test, request=3DNone, html=3DFalse):
+        if isinstance(obj, Message):
+            log_url =3D reverse("testing-log",
+                              kwargs=3D{"project_or_series": obj.message_i=
d,
+                                      "testing_name": test}) + "?type=3Dme=
ssage"
+        else:
+            assert(isinstance(obj, Project))
+            log_url =3D reverse.reverse("testing-log",
+                              kwargs=3D{"project_or_series": obj.name,
+                                      "testing_name": test}) + "?type=3Dpr=
oject"
+        if html:
+            log_url +=3D "&html=3D1"
+        # Generate a full URL, including the host and port, for use in ema=
il
+        # notifications and REST API responses.
+        if request:
+            log_url =3D request.build_absolute_uri(log_url)
+        return log_url
+
     def add_test_report(self, user, project, tester, test, head,
                         base, identity, passed, log, is_timeout):
         # Find a project or series depending on the test type and assign i=
t to obj
@@ -203,20 +221,8 @@ class TestingModule(PatchewModule):
                 continue
             tn =3D pn[len("testing.report."):]
             failed =3D not p["passed"]
-            log_prop =3D "testing.log." + tn
-            if isinstance(obj, Message):
-                typearg =3D "type=3Dmessage"
-                log_url =3D reverse("testing-log",
-                                  kwargs=3D{"project_or_series": obj.messa=
ge_id,
-                                          "testing_name": tn})
-            else:
-                assert(isinstance(obj, Project))
-                typearg =3D "type=3Dproject"
-                log_url =3D reverse("testing-log",
-                                  kwargs=3D{"project_or_series": obj.name,
-                                          "testing_name": tn})
-            log_url +=3D "?" + typearg
-            html_log_url =3D log_url + "&html=3D1"
+            log_url =3D self.reverse_testing_log(obj, tn, html=3DFalse)
+            html_log_url =3D self.reverse_testing_log(obj, tn, html=3DTrue)
             passed_str =3D "failed" if failed else "passed"
             html =3D format_html('Test {} {}',
                                tn, html_log_url, log_url, passed_str)
@@ -263,12 +269,7 @@ class TestingModule(PatchewModule):
                 continue
             tn =3D pn[len("testing.report."):]
             failed =3D not p["passed"]
-            log_prop =3D "testing.log." + tn
-            typearg =3D "type=3Dmessage"
-            log_url =3D reverse("testing-log",
-                              kwargs=3D{"project_or_series": message.messa=
ge_id,
-                                      "testing_name": tn})
-            log_url +=3D "?" + typearg
+            log_url =3D self.reverse_testing_log(message, tn, request=3Dre=
quest, html=3DFalse)
             passed_str =3D "failure" if failed else "success"
             result =3D {
                 'status': passed_str,
--=20
2.14.3


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
From nobody Fri May  3 06:52:24 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;
	dkim=fail;
	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 1520496061403344.3602264412283;
 Thu, 8 Mar 2018 00:01:01 -0800 (PST)
Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com
 [10.5.11.11])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id 859FB5D678;
	Thu,  8 Mar 2018 08:01:00 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
 (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B909620A0;
	Thu,  8 Mar 2018 08:01:00 +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 736F34CA99;
	Thu,  8 Mar 2018 08:01:00 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com
	[10.5.11.11])
	by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id w2880w1a032414 for ;
	Thu, 8 Mar 2018 03:00:59 -0500
Received: by smtp.corp.redhat.com (Postfix)
	id F16249CC7; Thu,  8 Mar 2018 08:00:58 +0000 (UTC)
Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com
	[10.5.110.31])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id EC0356134B
	for ; Thu,  8 Mar 2018 08:00:57 +0000 (UTC)
Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com
 [74.125.82.65])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by mx1.redhat.com (Postfix) with ESMTPS id 99EF5C04BE0D
	for ; Thu,  8 Mar 2018 08:00:55 +0000 (UTC)
Received: by mail-wm0-f65.google.com with SMTP id h21so9487462wmd.1
	for ; Thu, 08 Mar 2018 00:00:55 -0800 (PST)
Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it.
	[94.36.191.219]) by smtp.gmail.com with ESMTPSA id
	b9sm21755912wrh.68.2018.03.08.00.00.52 for 
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 08 Mar 2018 00:00:53 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=sender:from:to:subject:date:message-id:in-reply-to:references;
	bh=rZNBzlO/xgwsr7NZN/SlH0RGOuTvtjPtWcwVknSq6Y0=;
	b=hlSTFYNiosV3zxdL3pGl/H68HMEPBqrkz27V9fFmWKlpw//3IEERgkWbTSZk7ln2RS
	bzpoGuKaGmNwBh6sDZ8EcGp5S+F0w/uciz0Pu5wNLlnqRYqbsWawMQKZOnCHCb6LPDTy
	jWEX/8oP4J5f8xerB+Iv+hT8BDZEbM8zWecx56DN+r07fYWdA4LBKpqrryhAKNYwHSAx
	oJpK+MjLEh2IqDaAYG0Da2Ch/si02K/cnCXwyeCMg8WWRS+j5P23B28SMVZHR+rIlnEs
	AARmJGgEaUfTfLxPnekcUi1B27PFFJKyv1+Vv2W9Tz2woJByUatAR29RnmMGXQ5XblF3
	X01Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:sender:from:to:subject:date:message-id
	:in-reply-to:references;
	bh=rZNBzlO/xgwsr7NZN/SlH0RGOuTvtjPtWcwVknSq6Y0=;
	b=JgQeHjXa9Ugs9S/IxMQoYuH/x62QczDeJSp/+9luqM3kEIXxuvGcHEgy21Qwp2/VpP
	AzuEWqkpKxR2/cKMhflruziteTTpbY2eufmdcQ5id26faCJMk4Lr/7EWNN9dpirmKgOl
	Qxmtz+9ULUyXNa1YJevn8XDcJNCWlEWUnA5ix0A5YAtEddfxByv65F3Ap1yKGpI5IbPc
	02UMbEgiioU5h3ssK4mONhvlZTyOaudhW7r8vs02g3fv9/RELFQbvcZ7qpSM+0tUlOl1
	vhXUqEmaEpk8Ro71LR2IRNcEw81PInBi+BfwXkVe9NcM8yzbAOGHvXIv8ErFZQorY1wC
	xFcg==
X-Gm-Message-State: AElRT7F5hGpExCij7jfvrWWssedn11nq/z5QmoF1bsHLDs4oBdPpt7vS
	r7INa8JKSZ3q7dQzgo5fRr1GEpHd
X-Google-Smtp-Source: 
 AG47ELsCGEC8KR87R/Ue+TcZDHGJr9MY7rw/E4cR8mJpiXA3VwkWK7fIf9bGxGWSJ6MKWKmM3NCPgg==
X-Received: by 10.28.85.7 with SMTP id j7mr12460706wmb.38.1520496053813;
	Thu, 08 Mar 2018 00:00:53 -0800 (PST)
From: Paolo Bonzini 
To: patchew-devel@redhat.com
Date: Thu,  8 Mar 2018 09:00:42 +0100
Message-Id: <20180308080042.19342-8-pbonzini@redhat.com>
In-Reply-To: <20180308080042.19342-1-pbonzini@redhat.com>
References: <20180308080042.19342-1-pbonzini@redhat.com>
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(mx1.redhat.com [10.5.110.31]);
	Thu, 08 Mar 2018 08:00:55 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com
 [10.5.110.31]);
	Thu, 08 Mar 2018 08:00:55 +0000 (UTC) for IP:'74.125.82.65'
	DOMAIN:'mail-wm0-f65.google.com' HELO:'mail-wm0-f65.google.com'
	FROM:'paolo.bonzini@gmail.com' RCPT:''
X-RedHat-Spam-Score: 0.469  (DKIM_SIGNED, DKIM_VALID,
	FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,
	SPF_PASS) 74.125.82.65 mail-wm0-f65.google.com 74.125.82.65
	mail-wm0-f65.google.com 
X-RedHat-Possible-Forgery:  Paolo Bonzini
	
X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11
X-loop: patchew-devel@redhat.com
Subject: [Patchew-devel] [PATCH 7/7] testing: pass log URL in the
	TestingReport event
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.11
X-Greylist: Sender IP whitelisted,
 not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]);
 Thu, 08 Mar 2018 08:01:00 +0000 (UTC)
X-ZohoMail-DKIM: fail (Header signature does not verify)
X-ZohoMail: RDKM_2  RSF_0  Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"

Signed-off-by: Paolo Bonzini 
---
 mods/testing.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mods/testing.py b/mods/testing.py
index ea6fdf5..32e7d86 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -164,20 +164,21 @@ class TestingModule(PatchewModule):
             log_url =3D request.build_absolute_uri(log_url)
         return log_url
=20
-    def add_test_report(self, user, project, tester, test, head,
+    def add_test_report(self, request, project, tester, test, head,
                         base, identity, passed, log, is_timeout):
         # Find a project or series depending on the test type and assign i=
t to obj
         if identity["type"] =3D=3D "project":
             obj =3D Project.objects.get(name=3Dproject)
-            is_proj_report =3D True
             project =3D obj.name
         elif identity["type"] =3D=3D "series":
             message_id =3D identity["message-id"]
             obj =3D Message.objects.find_series(message_id, project)
             if not obj:
                 raise Exception("Series doesn't exist")
-            is_proj_report =3D False
             project =3D obj.project.name
+        user =3D request.user
+        log_url =3D self.reverse_testing_log(obj, test, request=3Drequest)
+        html_log_url =3D self.reverse_testing_log(obj, test, request=3Dreq=
uest, html=3DTrue)
         obj.set_property("testing.report." + test,
                          {"passed": passed,
                           "is_timeout": is_timeout,
@@ -195,8 +196,8 @@ class TestingModule(PatchewModule):
         if all_tests.issubset(done_tests):
             obj.set_property("testing.tested-head", head)
         emit_event("TestingReport", tester=3Dtester, user=3Duser.username,
-                    obj=3Dobj, passed=3Dpassed, test=3Dtest, log=3Dlog,
-                    is_timeout=3Dis_timeout)
+                    obj=3Dobj, passed=3Dpassed, test=3Dtest, log=3Dlog, lo=
g_url=3Dlog_url,
+                    html_log_url=3Dhtml_log_url, is_timeout=3Dis_timeout)
=20
     def get_tests(self, obj):
         ret =3D {}
@@ -475,7 +476,7 @@ class TestingReportView(APILoginRequiredView):
                head, base, passed, log, identity,
                is_timeout=3DFalse):
         _instance.tester_check_in(project, tester or request.user.username)
-        _instance.add_test_report(request.user, project, tester,
+        _instance.add_test_report(request, project, tester,
                                   test, head, base, identity, passed, log,
                                   is_timeout)
=20
--=20
2.14.3

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel