From nobody Sun Feb 8 12:37:41 2026 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=libvir-list-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=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569337475; cv=none; d=zoho.com; s=zohoarc; b=Jp421vHRI1W0AvegKNJmopGC22y4A/7pbW3u3bYo4/VmdjNNFbVZSWH+UmMkI4nCgSRDNc/7giBW+3QHXBihwO5uN1wTPscPdpxrUIsTovTiscWYfgNDjUJUPGtFEe63eMaAhdzlBrJKP7wkvDSlszA3aZ0EG3uKJD8rvaaArho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337475; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ouf3bcfkE0m/YGWVLf3mpJkp01s3d8tv7SVdaoyYPKE=; b=ER6d81NZ5RqEWmMyLkiFOsayxBUDuaPx8G8XkuOENg15ra+qO7tOlQ7pR52lS1mQPTf/1Ot18UzSF6rQmW0rzgL1f/gHVwz0sdNRjozJpwIfKlGS5bozNX4TO7rlkpntDqa411TWaK2UJR6aTebt/6LCK7GCDjWM80W9N13UPFY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156933747562331.26717819008195; Tue, 24 Sep 2019 08:04:35 -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 044F910C0947; Tue, 24 Sep 2019 15:04:34 +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 C93CE5C21F; Tue, 24 Sep 2019 15:04:33 +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 74F774EE6D; Tue, 24 Sep 2019 15:04:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8OF47oL027825 for ; Tue, 24 Sep 2019 11:04:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 084AC5D9E1; Tue, 24 Sep 2019 15:04:07 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D5D75D9D5; Tue, 24 Sep 2019 15:04:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:44 +0100 Message-Id: <20190924145903.17123-4-berrange@redhat.com> In-Reply-To: <20190924145903.17123-1-berrange@redhat.com> References: <20190924145903.17123-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/22] build-aux: rewrite po file minimizer in Python X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-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.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 24 Sep 2019 15:04:34 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the minimize-po.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- Makefile.am | 2 +- build-aux/minimize-po.pl | 37 ------------------------- build-aux/minimize-po.py | 60 ++++++++++++++++++++++++++++++++++++++++ po/Makefile.am | 2 +- 4 files changed, 62 insertions(+), 39 deletions(-) delete mode 100755 build-aux/minimize-po.pl create mode 100755 build-aux/minimize-po.py diff --git a/Makefile.am b/Makefile.am index 17448a914e..8f688d40d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,7 @@ EXTRA_DIST =3D \ build-aux/check-spacing.pl \ build-aux/gitlog-to-changelog \ build-aux/header-ifdef.pl \ - build-aux/minimize-po.pl \ + build-aux/minimize-po.py \ build-aux/mock-noinline.pl \ build-aux/prohibit-duplicate-header.pl \ build-aux/useless-if-before-free \ diff --git a/build-aux/minimize-po.pl b/build-aux/minimize-po.pl deleted file mode 100755 index 497533a836..0000000000 --- a/build-aux/minimize-po.pl +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl - -my @block; -my $msgstr =3D 0; -my $empty =3D 0; -my $unused =3D 0; -my $fuzzy =3D 0; -while (<>) { - if (/^$/) { - if (!$empty && !$unused && !$fuzzy) { - print @block; - } - @block =3D (); - $msgstr =3D 0; - $fuzzy =3D 0; - push @block, $_; - } else { - if (/^msgstr/) { - $msgstr =3D 1; - $empty =3D 1; - } - if (/^#.*fuzzy/) { - $fuzzy =3D 1; - } - if (/^#~ msgstr/) { - $unused =3D 1; - } - if ($msgstr && /".+"/) { - $empty =3D 0; - } - push @block, $_; - } -} - -if (@block && !$empty && !$unused) { - print @block; -} diff --git a/build-aux/minimize-po.py b/build-aux/minimize-po.py new file mode 100755 index 0000000000..5046bacede --- /dev/null +++ b/build-aux/minimize-po.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# +# Copyright (C) 2018-2019 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . + +from __future__ import print_function + +import re +import sys + +block =3D [] +msgstr =3D False +empty =3D False +unused =3D False +fuzzy =3D False + +strprog =3D re.compile(r'''.*".+".*''') + +for line in sys.stdin: + line =3D line.rstrip("\n") + + if line =3D=3D "": + if not empty and not unused and not fuzzy: + for b in block: + print(b) + + block =3D [] + msgstr =3D False + fuzzy =3D False + block.append(line) + else: + if line.startswith("msgstr"): + msgstr =3D True + empty =3D True + + if line[0] =3D=3D '#' and line.find("fuzzy") !=3D -1: + fuzzy =3D True + if line.startswith("#~ msgstr"): + unused =3D True + if msgstr and strprog.match(line): + empty =3D False + + block.append(line) + +if not empty and not unused and not fuzzy: + for b in block: + print(b) diff --git a/po/Makefile.am b/po/Makefile.am index da117edbd5..90025b15dd 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -58,7 +58,7 @@ update-mini-po: $(POTFILE) $(MSGMERGE) --no-location --no-fuzzy-matching --sort-output \ $$lang.po $(POTFILE) | \ $(SED) $(SED_PO_FIXUP_ARGS) | \ - $(PERL) $(top_srcdir)/build-aux/minimize-po.pl > \ + $(RUNUTF8) $(PYTHON) $(top_srcdir)/build-aux/minimize-po.py > \ $(srcdir)/$$lang.mini.po ; \ done =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list