[libvirt PATCH 03/11] scripts: group-qemu-caps: remove cryptic bool from load_caps_flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Enumerate over lines early to find out the position of the starting
and ending markers.

Then run the actual function on the lines between those markers.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 scripts/group-qemu-caps.py | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
index bd22dd992a..e56c306d10 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -29,27 +29,29 @@ import sys
 
 def load_caps_flags(filename, start_regex, end_regex):
     capsflags = []
-    game_on = False
     lines = []
+    start = 0
+    end = 0
 
     with open(filename, "r") as fh:
         lines = fh.read().splitlines()
 
-    for line in lines:
-        if game_on:
-            if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
-                continue
-            if re.search(r'''^\s*$''', line):
-                continue
-            match = re.search(r'''[ ]+([A-Z0-9_]+)''', line)
-
-            if match:
-                capsflags.append(match[1])
-
+    for idx, line in enumerate(lines):
         if re.search(start_regex, line):
-            game_on = True
-        elif game_on and re.search(end_regex, line):
-            game_on = False
+            start = idx
+        elif re.search(end_regex, line):
+            end = idx
+            break
+
+    for line in lines[start:end]:
+        if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
+            continue
+        if re.search(r'''^\s*$''', line):
+            continue
+        match = re.search(r'''[ ]+([A-Z0-9_]+)''', line)
+
+        if match:
+            capsflags.append(match[1])
 
     return capsflags
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux