On Tue, Sep 24, 2019 at 03:58:43PM +0100, Daniel P. Berrangé wrote:
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
s/dependancy/dependency/
to be fixed, because this was assumed to be the filename of the
script, but is in fact a full shell command line.
This is the case regardless of the Perl->Python conversion
and can be done upfront to reduce the churn in this patch.
Introduced by commit fb59cf7a5824b9c876737dcbf6aac97c29b1444a
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
Since this is a new file with clean history, it might actually deserve
a better location than build-aux and we can leave this directory to
Automake and gnulib to do whatever magic they do there.
Also note that the directory is in .gitignore. (I added the exception
for .pl files back when I added files here)
Would 'scripts' be too vague? Could be a good place to put the helper
scripts for generating QEMU caps files since I never seem to remember
its name and tests/ is growing quite big.
[...]
+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:
+ markerprog = re.compile(r'''\s*@CONFIG@\s*''')
+ for line in fh:
+ if markerprog.match(line) is not None:
Simpler as:
if '@CONFIG@' in line:
There's no need to use a regex here
+ print(' let conf = "', end='')
This uses three spaces instead of two like the original Perl script.
Three match the rest of the .aug files, but by including that change
here, this rewrite generates a different output.
+ expand_config(config)
+ print('"')
+ else:
+ print(line, end='')
+
+
+expand_template(template, config)
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano