[ovs-dev] [PATCH 4/9] tests: Convert dpdkstrip utility from Perl to Python.
Ben Pfaff
blp at ovn.org
Wed Nov 15 18:53:13 UTC 2017
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 <blp at ovn.org>
---
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 (<STDIN>) {
- 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
--
2.10.2
More information about the dev
mailing list