[libvirt] [PATCH v5 15/23] tests: rewrite test argv line wrapper in Python
Ján Tomko
jtomko at redhat.com
Tue Nov 26 13:59:18 UTC 2019
On Mon, Nov 11, 2019 at 02:38:18PM +0000, Daniel P. Berrangé wrote:
>As part of an goal to eliminate Perl from libvirt build tools,
a goal? the goal?
>rewrite the test-wrap-argv.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é <berrange at redhat.com>
>---
> Makefile.am | 1 +
> build-aux/syntax-check.mk | 4 +-
> scripts/test-wrap-argv.py | 170 +++++++++++++++++++++++++++++++++++++
> tests/test-wrap-argv.pl | 174 --------------------------------------
> tests/testutils.c | 16 ++--
> 5 files changed, 181 insertions(+), 184 deletions(-)
> create mode 100755 scripts/test-wrap-argv.py
> delete mode 100755 tests/test-wrap-argv.pl
>
>+def rewrap_line(line):
>+ bits = line.split(" ")
>+
>+ # bits contains env vars, then the command line
>+ # and then the arguments
>+ env = []
>+ cmd = None
>+ args = []
>+
>+ if bits[0].find("=") == -1:
if "=" not in bits[0]:
>+ cmd = bits[0]
>+ bits = bits[1:]
>+
[...]
>+
>+ # Now each 'lines' entry represents a single command, we
>+ # can process them
>+ new_lines = []
>+ for line in lines:
>+ new_lines.append(rewrap_line(line))
>+
>+ if in_place:
>+ with open(filename, "w") as fh:
>+ for line in new_lines:
>+ print(line, file=fh)
This print needs an end='' to match the perl script behavior.
>+ elif check:
>+ orig = "".join(orig_lines)
>+ new = "".join(new_lines)
>+ if new != orig:
>+ diff = subprocess.Popen(["diff", "-u", filename, "-"],
>+ stdin=subprocess.PIPE)
>+ diff.communicate(input=new.encode('utf-8'))
>+
>+ print("Incorrect line wrapping in $file",
>+ file=sys.stderr)
>+ print("Use test-wrap-argv.py to wrap test data files",
>+ file=sys.stderr)
>+ return False
>+ else:
>+ for line in new_lines:
>+ print(line)
Same here.
>+
>+ return True
>+
>+
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191126/8d013cc2/attachment-0001.sig>
More information about the libvir-list
mailing list