As part of an goal to eliminate Perl from libvirt build tools,
rewrite the augeas-gentest.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.
The use of $(AUG_GENTEST) as a dependancy in the makefiles needed
to be fixed, because this was assumed to be the filename of the
script, but is in fact a full shell command line.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
Makefile.am | 2 +-
build-aux/augeas-gentest.pl | 60 ---------------------------
build-aux/augeas-gentest.py | 72 +++++++++++++++++++++++++++++++++
src/Makefile.am | 3 +-
src/bhyve/Makefile.inc.am | 4 +-
src/interface/Makefile.inc.am | 2 +-
src/libxl/Makefile.inc.am | 4 +-
src/locking/Makefile.inc.am | 6 +--
src/logging/Makefile.inc.am | 2 +-
src/lxc/Makefile.inc.am | 4 +-
src/network/Makefile.inc.am | 2 +-
src/node_device/Makefile.inc.am | 2 +-
src/nwfilter/Makefile.inc.am | 2 +-
src/qemu/Makefile.inc.am | 4 +-
src/remote/Makefile.inc.am | 4 +-
src/secret/Makefile.inc.am | 2 +-
src/storage/Makefile.inc.am | 2 +-
src/vbox/Makefile.inc.am | 2 +-
src/vz/Makefile.inc.am | 2 +-
19 files changed, 97 insertions(+), 84 deletions(-)
delete mode 100755 build-aux/augeas-gentest.pl
create mode 100755 build-aux/augeas-gentest.py
diff --git a/Makefile.am b/Makefile.am
index 711f365504..17448a914e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,7 +41,7 @@ EXTRA_DIST = \
run.in \
README.md \
AUTHORS.in \
- build-aux/augeas-gentest.pl \
+ build-aux/augeas-gentest.py \
build-aux/check-spacing.pl \
build-aux/gitlog-to-changelog \
build-aux/header-ifdef.pl \
diff --git a/build-aux/augeas-gentest.pl b/build-aux/augeas-gentest.pl
deleted file mode 100755
index 65834b533b..0000000000
--- a/build-aux/augeas-gentest.pl
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env perl
-#
-# augeas-gentest.pl: Generate an augeas test file, from an
-# example config file + test file template
-#
-# 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
-# <
http://www.gnu.org/licenses/>.
-
-use strict;
-use warnings;
-
-die "syntax: $0 CONFIG TEMPLATE\n" unless @ARGV == 2;
-
-my $config = shift @ARGV;
-my $template = shift @ARGV;
-
-open CONFIG, "<", $config or die "cannot read $config: $!";
-open TEMPLATE, "<", $template or die "cannot read $template: $!";
-
-my $group = 0;
-while (<TEMPLATE>) {
- if (/\@CONFIG\@/) {
- my $group = 0;
- print " let conf = \"";
- while (<CONFIG>) {
- if (/^#\w/) {
- s/^#//;
- s/\"/\\\"/g;
- print $_;
- $group = /\[\s$/;
- } elsif ($group) {
- s/\"/\\\"/g;
- if (/#\s*\]/) {
- $group = 0;
- }
- if (/^#/) {
- s/^#//;
- print $_;
- }
- }
- }
- print "\"\n";
- } else {
- print $_;
- }
-}
-
-close TEMPLATE;
-close CONFIG;
diff --git a/build-aux/augeas-gentest.py b/build-aux/augeas-gentest.py
new file mode 100755
index 0000000000..b7f343ef42
--- /dev/null
+++ b/build-aux/augeas-gentest.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2012-2019 Red Hat, Inc.
+#
+# augeas-gentest.py: Generate an augeas test file, from an
+# example config file + test file template
+#
+# 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
+# <
http://www.gnu.org/licenses/>.
+
+from __future__ import print_function
+
+import re
+import sys
+
+if len(sys.argv) != 3:
+ print("syntax: %s CONFIG TEMPLATE" % sys.argv[0], file=sys.stderr)
+ sys.exit(1)
+
+config = sys.argv[1]
+template = sys.argv[2]
+
+def expand_config(config):
+ with open(config) as fh:
+ optprog = re.compile(r'''^#\w.*''')
+ groupstartprog = re.compile(r'''.*\[\s$''')
+ groupendprog = re.compile(r'''#\s*\].*$''')
+
+ group = False
+ for line in fh:
+ if optprog.match(line) is not None:
+ line = line[1:]
+ line = line.replace('"', '\\"')
+ print(line, end='')
+ if groupstartprog.match(line):
+ group = True
+ elif group:
+ line = line.replace('"', '\\"')
+
+ if groupendprog.match(line):
+ group = False
+
+ if line[0] == '#':
+ line = line[1:]
+ print(line, end='')
+
+
+def expand_template(template, config):
+ with open(template) as fh:
+ group = 0
+
+ markerprog = re.compile(r'''\s*@CONFIG@\s*''')
+ for line in fh:
+ if markerprog.match(line) is not None:
+ print(' let conf = "', end='')
+ expand_config(config)
+ print('"')
+ else:
+ print(line, end='')
+
+expand_template(template, config)
diff --git a/src/Makefile.am b/src/Makefile.am
index f5093b9c90..7a4de2aa53 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -422,7 +422,8 @@ check-augeas: $(augeas_DATA) $(augeastest_DATA)
fi
.PHONY: check-augeas
-AUG_GENTEST = $(PERL) $(top_srcdir)/build-aux/augeas-gentest.pl
+AUG_GENTEST_SCRIPT = $(top_srcdir)/build-aux/augeas-gentest.py
+AUG_GENTEST = $(RUNUTF8) $(PYTHON) $(AUG_GENTEST_SCRIPT)
#
diff --git a/src/bhyve/Makefile.inc.am b/src/bhyve/Makefile.inc.am
index 195069872a..7e49a8bb5c 100644
--- a/src/bhyve/Makefile.inc.am
+++ b/src/bhyve/Makefile.inc.am
@@ -77,7 +77,7 @@ bhyve/virtbhyved.aug: remote/libvirtd.aug.in
$< > $@
bhyve/test_virtbhyved.aug: remote/test_libvirtd.aug.in \
- bhyve/virtbhyved.conf $(AUG_GENTEST)
+ bhyve/virtbhyved.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) bhyve/virtbhyved.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
@@ -91,7 +91,7 @@ augeas_DATA += bhyve/libvirtd_bhyve.aug
augeastest_DATA += bhyve/test_libvirtd_bhyve.aug
bhyve/test_libvirtd_bhyve.aug: bhyve/test_libvirtd_bhyve.aug.in \
- $(srcdir)/bhyve/bhyve.conf $(AUG_GENTEST)
+ $(srcdir)/bhyve/bhyve.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/bhyve/bhyve.conf $< > $@
endif WITH_BHYVE
diff --git a/src/interface/Makefile.inc.am b/src/interface/Makefile.inc.am
index a88df0bd11..b042da4c57 100644
--- a/src/interface/Makefile.inc.am
+++ b/src/interface/Makefile.inc.am
@@ -95,7 +95,7 @@ interface/virtinterfaced.aug: remote/libvirtd.aug.in
$< > $@
interface/test_virtinterfaced.aug: remote/test_libvirtd.aug.in \
- interface/virtinterfaced.conf $(AUG_GENTEST)
+ interface/virtinterfaced.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) interface/virtinterfaced.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/libxl/Makefile.inc.am b/src/libxl/Makefile.inc.am
index a2151162e6..617b2a9019 100644
--- a/src/libxl/Makefile.inc.am
+++ b/src/libxl/Makefile.inc.am
@@ -108,7 +108,7 @@ libxl/virtxend.aug: remote/libvirtd.aug.in
$< > $@
libxl/test_virtxend.aug: remote/test_libvirtd.aug.in \
- libxl/virtxend.conf $(AUG_GENTEST)
+ libxl/virtxend.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) libxl/virtxend.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
@@ -122,7 +122,7 @@ augeas_DATA += libxl/libvirtd_libxl.aug
augeastest_DATA += libxl/test_libvirtd_libxl.aug
libxl/test_libvirtd_libxl.aug: libxl/test_libvirtd_libxl.aug.in \
- $(srcdir)/libxl/libxl.conf $(AUG_GENTEST)
+ $(srcdir)/libxl/libxl.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/libxl/libxl.conf $< > $@
INSTALL_DATA_DIRS += libxl
diff --git a/src/locking/Makefile.inc.am b/src/locking/Makefile.inc.am
index fae92a6e45..df0c51aaf6 100644
--- a/src/locking/Makefile.inc.am
+++ b/src/locking/Makefile.inc.am
@@ -219,7 +219,7 @@ endif WITH_SANLOCK
if WITH_SANLOCK
if WITH_QEMU
locking/test_libvirt_sanlock.aug: locking/test_libvirt_sanlock.aug.in \
- locking/qemu-sanlock.conf $(AUG_GENTEST)
+ locking/qemu-sanlock.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) locking/qemu-sanlock.conf $< > $@
endif WITH_QEMU
@@ -227,12 +227,12 @@ endif WITH_SANLOCK
if WITH_QEMU
locking/test_libvirt_lockd.aug: locking/test_libvirt_lockd.aug.in \
- locking/qemu-lockd.conf $(AUG_GENTEST)
+ locking/qemu-lockd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) locking/qemu-lockd.conf $< > $@
endif WITH_QEMU
locking/test_virtlockd.aug: locking/test_virtlockd.aug.in \
- locking/virtlockd.conf $(AUG_GENTEST)
+ locking/virtlockd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/locking/virtlockd.conf $< > $@
endif WITH_LIBVIRTD
diff --git a/src/logging/Makefile.inc.am b/src/logging/Makefile.inc.am
index 7e441dbffb..ce777e278a 100644
--- a/src/logging/Makefile.inc.am
+++ b/src/logging/Makefile.inc.am
@@ -101,7 +101,7 @@ augeas_DATA += logging/virtlogd.aug
augeastest_DATA += logging/test_virtlogd.aug
logging/test_virtlogd.aug: logging/test_virtlogd.aug.in \
- logging/virtlogd.conf $(AUG_GENTEST)
+ logging/virtlogd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/logging/virtlogd.conf $< > $@
endif WITH_LIBVIRTD
diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am
index b4d560702c..0e12800886 100644
--- a/src/lxc/Makefile.inc.am
+++ b/src/lxc/Makefile.inc.am
@@ -164,7 +164,7 @@ lxc/virtlxcd.aug: remote/libvirtd.aug.in
$< > $@
lxc/test_virtlxcd.aug: remote/test_libvirtd.aug.in \
- lxc/virtlxcd.conf $(AUG_GENTEST)
+ lxc/virtlxcd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) lxc/virtlxcd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
@@ -222,7 +222,7 @@ augeas_DATA += lxc/libvirtd_lxc.aug
augeastest_DATA += lxc/test_libvirtd_lxc.aug
lxc/test_libvirtd_lxc.aug: lxc/test_libvirtd_lxc.aug.in \
- $(srcdir)/lxc/lxc.conf $(AUG_GENTEST)
+ $(srcdir)/lxc/lxc.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/lxc/lxc.conf $< > $@
INSTALL_DATA_DIRS += lxc
diff --git a/src/network/Makefile.inc.am b/src/network/Makefile.inc.am
index 9f20dad7b3..31e4b1fbe4 100644
--- a/src/network/Makefile.inc.am
+++ b/src/network/Makefile.inc.am
@@ -102,7 +102,7 @@ network/virtnetworkd.aug: remote/libvirtd.aug.in
$< > $@
network/test_virtnetworkd.aug: remote/test_libvirtd.aug.in \
- network/virtnetworkd.conf $(AUG_GENTEST)
+ network/virtnetworkd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) network/virtnetworkd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/node_device/Makefile.inc.am b/src/node_device/Makefile.inc.am
index 5a6525d843..dfe16d62d6 100644
--- a/src/node_device/Makefile.inc.am
+++ b/src/node_device/Makefile.inc.am
@@ -118,7 +118,7 @@ node_device/virtnodedevd.aug: remote/libvirtd.aug.in
$< > $@
node_device/test_virtnodedevd.aug: remote/test_libvirtd.aug.in \
- node_device/virtnodedevd.conf $(AUG_GENTEST)
+ node_device/virtnodedevd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) node_device/virtnodedevd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/nwfilter/Makefile.inc.am b/src/nwfilter/Makefile.inc.am
index 7693634e29..476768ef11 100644
--- a/src/nwfilter/Makefile.inc.am
+++ b/src/nwfilter/Makefile.inc.am
@@ -103,7 +103,7 @@ nwfilter/virtnwfilterd.aug: remote/libvirtd.aug.in
$< > $@
nwfilter/test_virtnwfilterd.aug: remote/test_libvirtd.aug.in \
- nwfilter/virtnwfilterd.conf $(AUG_GENTEST)
+ nwfilter/virtnwfilterd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) nwfilter/virtnwfilterd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am
index d16b315ebc..caa79cae6a 100644
--- a/src/qemu/Makefile.inc.am
+++ b/src/qemu/Makefile.inc.am
@@ -165,7 +165,7 @@ qemu/virtqemud.aug: remote/libvirtd.aug.in
$< > $@
qemu/test_virtqemud.aug: remote/test_libvirtd.aug.in \
- qemu/virtqemud.conf $(AUG_GENTEST)
+ qemu/virtqemud.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) qemu/virtqemud.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
@@ -180,7 +180,7 @@ augeas_DATA += qemu/libvirtd_qemu.aug
augeastest_DATA += qemu/test_libvirtd_qemu.aug
qemu/test_libvirtd_qemu.aug: qemu/test_libvirtd_qemu.aug.in \
- $(srcdir)/qemu/qemu.conf $(AUG_GENTEST)
+ $(srcdir)/qemu/qemu.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/qemu/qemu.conf $< > $@
INSTALL_DATA_DIRS += qemu
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index abf04d998a..0c5e2fd376 100644
--- a/src/remote/Makefile.inc.am
+++ b/src/remote/Makefile.inc.am
@@ -285,7 +285,7 @@ remote/virtproxyd.aug: remote/libvirtd.aug.in
$< > $@
remote/test_libvirtd.aug: remote/test_libvirtd.aug.in \
- remote/libvirtd.conf $(AUG_GENTEST)
+ remote/libvirtd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) remote/libvirtd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
@@ -298,7 +298,7 @@ remote/test_libvirtd.aug: remote/test_libvirtd.aug.in \
$@ || rm -f $@
remote/test_virtproxyd.aug: remote/test_libvirtd.aug.in \
- remote/virtproxyd.conf $(AUG_GENTEST)
+ remote/virtproxyd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) remote/virtproxyd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/secret/Makefile.inc.am b/src/secret/Makefile.inc.am
index 37f816406e..1e25993225 100644
--- a/src/secret/Makefile.inc.am
+++ b/src/secret/Makefile.inc.am
@@ -91,7 +91,7 @@ secret/virtsecretd.aug: remote/libvirtd.aug.in
$< > $@
secret/test_virtsecretd.aug: remote/test_libvirtd.aug.in \
- secret/virtsecretd.conf $(AUG_GENTEST)
+ secret/virtsecretd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) secret/virtsecretd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/storage/Makefile.inc.am b/src/storage/Makefile.inc.am
index fd0d57d2b6..3542ee52e8 100644
--- a/src/storage/Makefile.inc.am
+++ b/src/storage/Makefile.inc.am
@@ -195,7 +195,7 @@ storage/virtstoraged.aug: remote/libvirtd.aug.in
$< > $@
storage/test_virtstoraged.aug: remote/test_libvirtd.aug.in \
- storage/virtstoraged.conf $(AUG_GENTEST)
+ storage/virtstoraged.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) storage/virtstoraged.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/vbox/Makefile.inc.am b/src/vbox/Makefile.inc.am
index 178c360b99..1f2bcb5488 100644
--- a/src/vbox/Makefile.inc.am
+++ b/src/vbox/Makefile.inc.am
@@ -117,7 +117,7 @@ vbox/virtvboxd.aug: remote/libvirtd.aug.in
$< > $@
vbox/test_virtvboxd.aug: remote/test_libvirtd.aug.in \
- vbox/virtvboxd.conf $(AUG_GENTEST)
+ vbox/virtvboxd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) vbox/virtvboxd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
diff --git a/src/vz/Makefile.inc.am b/src/vz/Makefile.inc.am
index f56fceb8f7..fa7b8b79dd 100644
--- a/src/vz/Makefile.inc.am
+++ b/src/vz/Makefile.inc.am
@@ -91,7 +91,7 @@ vz/virtvzd.aug: remote/libvirtd.aug.in
$< > $@
vz/test_virtvzd.aug: remote/test_libvirtd.aug.in \
- vz/virtvzd.conf $(AUG_GENTEST)
+ vz/virtvzd.conf $(AUG_GENTEST_SCRIPT)
$(AM_V_GEN)$(AUG_GENTEST) vz/virtvzd.conf \
$(srcdir)/remote/test_libvirtd.aug.in | \
$(SED) \
--
2.21.0