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é <berra...@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 <jto...@redhat.com>

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to