[libvirt PATCH 05/11] scripts: group-qemu-caps: split lines in regroup_caps

Ján Tomko jtomko at redhat.com
Tue Aug 24 14:25:08 UTC 2021


For consistency, operate on split lines and re-add the newlines later.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 scripts/group-qemu-caps.py | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
index ee33f1cf16..ca5f9b7247 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -58,14 +58,12 @@ def regroup_caps(check, filename, start_regex, end_regex,
 
     original = []
     with open(filename, "r") as fh:
-        for line in fh:
-            original.append(line)
+        original = fh.read().splitlines()
 
     fixed = []
     game_on = False
     counter = 0
     for line in original:
-        line = line.rstrip("\n")
         if game_on:
             if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
                 continue
@@ -73,8 +71,8 @@ def regroup_caps(check, filename, start_regex, end_regex,
                 continue
             if counter % step == 0:
                 if counter != 0:
-                    fixed.append("\n")
-                fixed.append("%s/* %d */\n" % (counter_prefix, counter))
+                    fixed.append("")
+                fixed.append("%s/* %d */" % (counter_prefix, counter))
 
             if not (line.find("/*") != -1 and line.find("*/") == -1):
                 # count two-line comments as one line
@@ -89,7 +87,7 @@ def regroup_caps(check, filename, start_regex, end_regex,
                     fixed = fixed[:-1]  # \n
 
             if trailing_newline:
-                fixed.append("\n")
+                fixed.append("")
 
             game_on = False
 
@@ -99,11 +97,11 @@ def regroup_caps(check, filename, start_regex, end_regex,
             if flagname:
                 line = flagname[0] + " /* %s */" % capsflags[counter - 1]
 
-        fixed.append(line + "\n")
+        fixed.append(line)
 
     if check:
-        orig = "".join(original)
-        new = "".join(fixed)
+        orig = "\n".join(original) + "\n"
+        new = "\n".join(fixed) + "\n"
         if new != orig:
             diff = subprocess.Popen(["diff", "-u", filename, "-"],
                                     stdin=subprocess.PIPE)
@@ -117,7 +115,7 @@ def regroup_caps(check, filename, start_regex, end_regex,
     else:
         with open(filename, "w") as fh:
             for line in fixed:
-                print(line, file=fh, end='')
+                print(line, file=fh)
 
     return True
 
-- 
2.31.1




More information about the libvir-list mailing list