From nobody Sat Apr 20 05:56:42 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 152286084615674.44074527101975; Wed, 4 Apr 2018 09:54:06 -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 3B85881DF2; Wed, 4 Apr 2018 16:54:05 +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 2F5B5611B1; Wed, 4 Apr 2018 16:54:05 +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 26DB7180005A; Wed, 4 Apr 2018 16:54:05 +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 w34Gs31o019391 for ; Wed, 4 Apr 2018 12:54:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2071381887; Wed, 4 Apr 2018 16:54:03 +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 1818A80F93 for ; Wed, 4 Apr 2018 16:54:00 +0000 (UTC) Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) (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 0B21E36807 for ; Wed, 4 Apr 2018 16:53:59 +0000 (UTC) Received: by mail-wr0-f174.google.com with SMTP id n2so20489859wrj.7 for ; Wed, 04 Apr 2018 09:53:58 -0700 (PDT) Received: from donizetti.lan (94-36-194-48.adsl-ull.clienti.tiscali.it. [94.36.194.48]) by smtp.gmail.com with ESMTPSA id q90sm9623140wrb.6.2018.04.04.09.53.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Apr 2018 09:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id; bh=yijxSYODhneOWJs05+/vnVzv/CFL7QZQgOWKtug/VkU=; b=ti/r9yycxosR8KXgOuTzgBxyBu9rR9IrXV2/Cs40x4Fm19XTwEcNFRH2WeEI22fdpE cTF2Yp9FchcmnmJaHxa+07R0fSRP0haO9gcIA5/dXQOZSEogRdm37eHmkm1k3KJSyLQJ pe0mu8LeYwIDhXEFjWiIssi1Q94n1ejY4emnAg4g71jQ18FdwLkRZ2I4em0Ocw/im/mH +msm7c7l+2fwjgLdtyNimMsuenNcNp57IN1d0XFjh/0IxukuFJAJk/5MQw0LFBxFKq4x XGySxNI2GNCyVjixcbTg7AKuL3GWThDZveZHAXfAzJ9fj7sHPVztm9Wu/uW9DcW5d7Nk PIcA== 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; bh=yijxSYODhneOWJs05+/vnVzv/CFL7QZQgOWKtug/VkU=; b=Cxe9XH/exO6O1OU5RITjElUPWQ7Ql+OoygnskF6IO68RabmMEJ9pSsVxaEuPynUjjh O0Cb09m/WcpUnkau7PnxWqjKuOlGyIzec3GzWWefytID2IZoEFrpRTMAYx6v4+NNzPm5 KRk+22MpTE5xwg21W45+uG9IkoKb5Rd6SjzWqMFvZino4rbXfTUm9oSvk+42j+1rKW0z gdm1MvVbQ0BWdpc3svkK6XoE5G4vbvPcuLX2HgnapvZdkag9c5ivkkEy9HHTU8wClXBG ng1dkW7VXNCBmQw9+HK6B4YbCHq99NATLBqqtw45kGy+Dolhhz333AxRY4JkzDPbZjdk MVNA== X-Gm-Message-State: AElRT7GvDp9gy5spe6JCEPpkwi5KGejONnKmYKc4BSlv6IlhNKwTcd1t l5m0FejOm0AH0flPryBlKiIBmTOt X-Google-Smtp-Source: AIpwx4/u6Dov07l/2pVi1bmTduu7BGdf1fk9aBZ2wpPGq+h3EVFNL2uLDSE1sZBVfYMZxidqg1moSg== X-Received: by 10.223.150.161 with SMTP id u30mr13239302wrb.151.1522860837197; Wed, 04 Apr 2018 09:53:57 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 4 Apr 2018 18:53:40 +0200 Message-Id: <20180404165340.26967-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Apr 2018 16:53:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Apr 2018 16:53:59 +0000 (UTC) for IP:'209.85.128.174' DOMAIN:'mail-wr0-f174.google.com' HELO:'mail-wr0-f174.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.174 mail-wr0-f174.google.com 209.85.128.174 mail-wr0-f174.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.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] custom_tags: add lines_between tag 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.25]); Wed, 04 Apr 2018 16:54:05 +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 tag can be used to extract sections of the tester's log, for example the test script or the output. Fixes: https://github.com/patchew-project/patchew/issues/31 Signed-off-by: Paolo Bonzini --- patchew/tags.py | 23 +++++++++++++++++++++++ tests/test_custom_tags.py | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/patchew/tags.py b/patchew/tags.py index 4847cb4..93a6f7e 100644 --- a/patchew/tags.py +++ b/patchew/tags.py @@ -62,6 +62,25 @@ def grep_iter(value, regex, n_before, n_after, sep): for i in range(max(lineno - n, 0), min(stop, lineno)): yield lines[i % n] =20 +# Similar to sed "/abc/,/def/p" except that the last line can +# be excluded. +def lines_between_iter(value, start, stop, include_last=3DTrue): + inside =3D False + for line in lines_iter(value): + if inside and re.search(stop, line): + inside =3D False + if include_last: + yield line + continue + # If include_last is false, immediately look + # for the next range. + + if not inside and re.search(start, line): + inside =3D True + + if inside: + yield line + register =3D template.Library() =20 @register.simple_tag @@ -94,3 +113,7 @@ def grep_B(value, regex, n=3D3, sep=3D'---'): @register.filter def grep_C(value, regex, n=3D3, sep=3D'---'): return '\n'.join(grep_iter(value, regex, n, n, sep)) + +@register.simple_tag +def lines_between(value, start, stop, include_last=3DTrue): + return '\n'.join(lines_between_iter(value, start, stop, include_last)) diff --git a/tests/test_custom_tags.py b/tests/test_custom_tags.py index 9ed2117..c401d0e 100755 --- a/tests/test_custom_tags.py +++ b/tests/test_custom_tags.py @@ -9,7 +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 +from patchew.tags import tail_lines, grep_A, grep_B, grep_C, grep, lines_b= etween import unittest =20 class CustomTagsTest(unittest.TestCase): @@ -38,6 +38,7 @@ class CustomTagsTest(unittest.TestCase): 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') + self.assertTemplate('{% lines_between s start=3D"^b$" stop=3D"c" %= }', 'b\nc', s=3D'a\nb\nc\nd') =20 def test_grep(self): self.assertEqual(grep('0\na\n9', '[0-9]'), '0\n9') @@ -124,5 +125,12 @@ class CustomTagsTest(unittest.TestCase): self.assertEqual(tail_lines('\n\nbc', 3), '\n\nbc') self.assertEqual(tail_lines('\n\n\n\nbc', 3), '\n\nbc') =20 + def test_lines_between(self): + self.assertEqual(lines_between('a\nb\nc\nd', 'b', 'c'), 'b\nc') + self.assertEqual(lines_between('a\nb\nc\nd', 'b', 'c', False), 'b') + self.assertEqual(lines_between('a\nb\ncb\nd', 'b', 'c'), 'b\ncb') + self.assertEqual(lines_between('a\nb\ncb\nd', 'b', 'c', False), 'b= \ncb\nd') + self.assertEqual(lines_between('a\nb\n\n\na\nb', '.', '^$'), 'a\nb= \n\na\nb') + if __name__ =3D=3D '__main__': unittest.main() --=20 2.16.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel