From patchwork Wed Nov 15 18:53:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 838300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ycYVD3Bfqz9s82 for ; Thu, 16 Nov 2017 05:55:32 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8244DC01; Wed, 15 Nov 2017 18:53:37 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id E0186B00 for ; Wed, 15 Nov 2017 18:53:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 39601113 for ; Wed, 15 Nov 2017 18:53:34 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1D35141C096; Wed, 15 Nov 2017 19:53:31 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Wed, 15 Nov 2017 10:53:13 -0800 Message-Id: <20171115185318.26841-4-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20171115185318.26841-1-blp@ovn.org> References: <20171115185318.26841-1-blp@ovn.org> X-Spam-Status: No, score=-0.2 required=5.0 tests=RCVD_IN_DNSWL_LOW, URI_NOVOWEL autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 4/9] tests: Convert dpdkstrip utility from Perl to Python. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Perl is unfashionable and Python is more widely available and understood, so this commit converts one of the OVS uses of Perl into Python. Signed-off-by: Ben Pfaff --- Makefile.am | 4 ++-- build-aux/automake.mk | 3 ++- build-aux/dpdkstrip.pl | 35 ------------------------------ build-aux/dpdkstrip.py | 48 +++++++++++++++++++++++++++++++++++++++++ rhel/openvswitch-fedora.spec.in | 2 +- 5 files changed, 53 insertions(+), 39 deletions(-) delete mode 100644 build-aux/dpdkstrip.pl create mode 100755 build-aux/dpdkstrip.py diff --git a/Makefile.am b/Makefile.am index 5d19f0833afc..c82a9e21ec36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,7 +86,7 @@ EXTRA_DIST = \ build-aux/cksum-schema-check \ build-aux/calculate-schema-cksum \ build-aux/dist-docs \ - build-aux/dpdkstrip.pl \ + build-aux/dpdkstrip.py \ build-aux/sodepends.pl \ build-aux/soexpand.pl \ build-aux/xml2nroff \ @@ -145,7 +145,7 @@ ro_shell = printf '\043 Generated automatically -- do not modify! -*- buffer- SUFFIXES += .in .in: $(AM_V_GEN)$(PERL) $(srcdir)/build-aux/soexpand.pl -I$(srcdir) < $< | \ - $(PERL) $(srcdir)/build-aux/dpdkstrip.pl $(DPDKSTRIP_FLAGS) | \ + $(PYTHON) $(srcdir)/build-aux/dpdkstrip.py $(DPDKSTRIP_FLAGS) | \ sed \ -e 's,[@]PKIDIR[@],$(PKIDIR),g' \ -e 's,[@]LOGDIR[@],$(LOGDIR),g' \ diff --git a/build-aux/automake.mk b/build-aux/automake.mk index 9500e3a69402..c0553e6edffb 100644 --- a/build-aux/automake.mk +++ b/build-aux/automake.mk @@ -1,3 +1,4 @@ # This file is purely used for checking the style of the python build tools. FLAKE8_PYFILES += \ - $(srcdir)/build-aux/xml2nroff + $(srcdir)/build-aux/xml2nroff \ + build-aux/dpdkstrip.py diff --git a/build-aux/dpdkstrip.pl b/build-aux/dpdkstrip.pl deleted file mode 100644 index 98539cce8241..000000000000 --- a/build-aux/dpdkstrip.pl +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2017 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -use strict; -use warnings; -use Getopt::Long; - -my ($check_dpdk) = 0; -my ($disabled_print) = 0; - -Getopt::Long::Configure ("bundling"); -GetOptions("dpdk!" => \$check_dpdk) or exit(1); - -OUTER: while () { - if (/@(begin|end)_dpdk@/) { - if (!$check_dpdk) { - $disabled_print = ! $disabled_print; - } - next; - } - - print $_ unless $disabled_print; -} -exit 0; diff --git a/build-aux/dpdkstrip.py b/build-aux/dpdkstrip.py new file mode 100755 index 000000000000..48c7f06934ef --- /dev/null +++ b/build-aux/dpdkstrip.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python +# Copyright (c) 2017 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import getopt +import sys + + +def strip_dpdk(check_dpdk, src, dst): + disabled_print = False + while True: + line = src.readline() + if not line: + break + if '@begin_dpdk@' in line or '@end_dpdk@' in line: + if not check_dpdk: + disabled_print = not disabled_print + continue + if not disabled_print: + dst.write(line) + + +if __name__ == '__main__': + check_dpdk = False + options, args = getopt.gnu_getopt(sys.argv[1:], '', ['dpdk', 'nodpdk']) + for key, value in options: + if key == '--dpdk': + check_dpdk = True + elif key == '--nodpdk': + check_dpdk = False + else: + assert False + if args: + for arg in args: + strip_dpdk(check_dpdk, open(arg), sys.stdout) + else: + strip_dpdk(check_dpdk, sys.stdin, sys.stdout) diff --git a/rhel/openvswitch-fedora.spec.in b/rhel/openvswitch-fedora.spec.in index b45e018f5ee9..e600a943cde6 100644 --- a/rhel/openvswitch-fedora.spec.in +++ b/rhel/openvswitch-fedora.spec.in @@ -229,7 +229,7 @@ Docker network plugins for OVN. --enable-ssl \ --with-pkidir=%{_sharedstatedir}/openvswitch/pki -/usr/bin/perl build-aux/dpdkstrip.pl \ +build-aux/dpdkstrip.py \ %if %{with dpdk} --dpdk \ %else