From nobody Sun Feb 8 16:30:59 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=1569337490; cv=none; d=zoho.com; s=zohoarc; b=lmk+V++XPFiuHqdsqZMdIeMwwEJmFUbkR3fzEEN9+8YQLLVG+r6Sl3KDMgh8edEnx0i1VJPjflLwm1QoesjEWzzQggR7rM6kQi/qd1ANnNaaz7QLz3hKIKtIrwBXqeLY+yj/fYbX/Zt8Q98Ikee82O5sxdVvIp7LHGRI4X1qLp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337490; 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=i+ruSwte2uVAgVsiTApq5nlqyfCkA4EIM7AdEWlJeDo=; b=gfNp+0bGqZ0bScHdMh5u7xaMf4TDfhRQnj4QTQaAi0LaNChHQWTRZgUQV6afnPVGwfCB9mup+y5rDO1ZSeRZyoHJIluQe5wU+htn8WvUmR/eV1lrEbZI9mnIC2dzkuar1DcyS7f0JlrXB4xNU/E1C8A6cCm5IlJfFs0c5nJTLxI= 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 156933749070169.72797055902993; Tue, 24 Sep 2019 08:04:50 -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 867A863704; Tue, 24 Sep 2019 15:04:48 +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 59E25608C0; Tue, 24 Sep 2019 15:04:48 +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 088AD4EE96; Tue, 24 Sep 2019 15:04:48 +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 x8OF4XbG027961 for ; Tue, 24 Sep 2019 11:04:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF78A5D9DC; Tue, 24 Sep 2019 15:04:33 +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 5DA9A5DAAC; Tue, 24 Sep 2019 15:04:33 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:55 +0100 Message-Id: <20190924145903.17123-15-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 14/22] src: rewrite driver impl checker 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Sep 2019 15:04:49 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the check-driverimpls.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 --- src/Makefile.am | 4 +- src/check-driverimpls.pl | 80 ------------------------------ src/check-driverimpls.py | 102 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 82 deletions(-) delete mode 100755 src/check-driverimpls.pl create mode 100755 src/check-driverimpls.py diff --git a/src/Makefile.am b/src/Makefile.am index 0d387a1335..1066f7f7cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -358,7 +358,7 @@ check-drivername: EXTRA_DIST +=3D check-drivername.py =20 check-driverimpls: - $(AM_V_GEN)$(PERL) $(srcdir)/check-driverimpls.pl \ + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/check-driverimpls.py \ $(filter /%,$(DRIVER_SOURCE_FILES)) \ $(filter $(srcdir)/%,$(DRIVER_SOURCE_FILES)) \ $(addprefix $(srcdir)/,$(filter-out $(srcdir)/%, \ @@ -374,7 +374,7 @@ check-aclperms: $(srcdir)/access/viraccessperm.h \ $(srcdir)/access/viraccessperm.c =20 -EXTRA_DIST +=3D check-driverimpls.pl check-aclrules.pl check-aclperms.py +EXTRA_DIST +=3D check-driverimpls.py check-aclrules.pl check-aclperms.py =20 check-local: check-protocol check-symfile check-symsorting \ check-drivername check-driverimpls check-aclrules \ diff --git a/src/check-driverimpls.pl b/src/check-driverimpls.pl deleted file mode 100755 index 3c0d54724c..0000000000 --- a/src/check-driverimpls.pl +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2013 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 -# . -# - -use strict; -use warnings; - -my $intable =3D 0; -my $table; -my $mainprefix; - -my $status =3D 0; -while (<>) { - if ($intable) { - if (/}/) { - $intable =3D 0; - $table =3D undef; - $mainprefix =3D undef; - } elsif (/\.(\w+)\s*=3D\s*(\w+),?/) { - my $api =3D $1; - my $impl =3D $2; - - next if $api eq "no"; - next if $api eq "name"; - next if $impl eq "NULL"; - - my $suffix =3D $impl; - my $prefix =3D $impl; - $prefix =3D~ s/^([a-z]+)(.*?)$/$1/; - - if (defined $mainprefix) { - if ($mainprefix ne $prefix) { - print "$ARGV:$. Bad prefix '$prefix' for API '$api', e= xpecting '$mainprefix'\n"; - $status =3D 1; - } - } else { - $mainprefix =3D $prefix; - } - - if ($api !~ /^$mainprefix/) { - $suffix =3D~ s/^[a-z]+//; - $suffix =3D~ s/^([A-Z]+)/lc $1/e; - } - - if ($api ne $suffix) { - my $want =3D $api; - $want =3D~ s/^nwf/NWF/; - if ($api !~ /^$mainprefix/) { - $want =3D~ s/^([a-z])/uc $1/e; - $want =3D $mainprefix . $want; - } - print "$ARGV:$. Bad impl name '$impl' for API '$api', expe= cting '$want'\n"; - $status =3D 1; - } - } - } elsif (/^(?:static\s+)?(vir(?:\w+)?Driver)\s+(?!.*;)/) { - next if $1 eq "virNWFilterCallbackDriver" || - $1 eq "virNWFilterTechDriver" || - $1 eq "virConnectDriver"; - $intable =3D 1; - $table =3D $1; - } -} - -exit $status; diff --git a/src/check-driverimpls.py b/src/check-driverimpls.py new file mode 100755 index 0000000000..30c92698b3 --- /dev/null +++ b/src/check-driverimpls.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Copyright (C) 2013-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 + + +def checkdriverimpls(filename): + intable =3D False + mainprefix =3D None + + errs =3D False + with open(filename, "r") as fh: + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + if intable: + if line.find("}") !=3D -1: + intable =3D False + mainprefix =3D None + continue + + m =3D re.match(r'''\s*\.(\w+)\s*=3D\s*(\w+),?\s*/''', line) + if m is not None: + api =3D m.group(1) + impl =3D m.group(2) + + if api in ["no", "name"]: + continue + if impl in ["NULL"]: + continue + + suffix =3D impl + prefix =3D re.sub(r'''^([a-z]+)(.*?)$''', r'''\1''', i= mpl) + + if mainprefix is not None: + if mainprefix !=3D prefix: + print("%s:%d Bad prefix '%s' for API '%s', " + + "expecting '%s'" % + (filename, lineno, prefix, api, mainpref= ix), + file=3Dsys.stderr) + errs =3D True + else: + mainprefix =3D prefix + + if not api.startswith(mainprefix): + suffix =3D re.sub(r'''^[a-z]+''', "", suffix) + suffix =3D re.sub(r'''^([A-Z]+)''', + lambda m: m.group(1).lower(), suff= ix) + + if api !=3D suffix: + want =3D api + if want.startswith("nwf"): + want =3D "NWF" + want[3:] + + if not api.startswith(mainprefix): + want =3D re.sub(r'''^([a-z])''', + lambda m: m.group(1).upper(), wa= nt) + want =3D mainprefix + want + + print("%s:%d Bad impl name '%s' for API " + + "'%s', expecting '%s'" % + (filename, lineno, impl, api, want), + file=3Dsys.stderr) + errs =3D True + else: + m =3D re.match(r'''^(?:static\s+)?(vir(?:\w+)?Driver)''' + + r'''\s+(?!.*;)''', line) + if m is not None: + drv =3D m.group(1) + if drv in ["virNWFilterCallbackDriver", + "virNWFilterTechDriver", + "virConnectDriver"]: + continue + intable =3D True + + return errs + + +status =3D 0 +for filename in sys.argv[1:]: + if checkdriverimpls(filename): + status =3D 1 +sys.exit(status) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list