This removes some newline handling at the cost of adding it elsewhere.
Signed-off-by: Ján Tomko <jtomko(a)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 a43cd1de45..34823931df 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -67,14 +67,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
@@ -82,8 +80,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
@@ -98,7 +96,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
@@ -108,11 +106,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)
@@ -126,7 +124,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.45.2