[libvirt PATCH 07/11] scripts: group-qemu-caps: introduce find_markers

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


Get indexes of the two marker strings.

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

diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
index 2eaaf06bb4..29ab268c4c 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -35,19 +35,24 @@ def load_file(filename):
     return lines
 
 
-def load_caps_flags(lines, start_regex, end_regex):
-    capsflags = []
+def find_markers(lines, start_marker, end_marker):
     start = 0
     end = 0
 
     for idx, line in enumerate(lines):
-        if re.search(start_regex, line):
+        if start_marker in line:
             start = idx
-        elif re.search(end_regex, line):
+        elif end_marker in line:
             end = idx
             break
 
-    for line in lines[start:end]:
+    return (start, end)
+
+
+def load_caps_flags(lines):
+    capsflags = []
+
+    for line in lines:
         match = re.search(r'''[ ]+([A-Z0-9_]+),''', line)
 
         if match:
@@ -137,9 +142,10 @@ header_path = args.prefix + 'src/qemu/qemu_capabilities.h'
 source_path = args.prefix + 'src/qemu/qemu_capabilities.c'
 
 header_lines = load_file(header_path)
-capsflags = load_caps_flags(header_lines,
-                            r'virQEMUCapsFlags grouping marker',
-                            r'QEMU_CAPS_LAST \/\* this must')
+(start, end) = find_markers(header_lines,
+                            'virQEMUCapsFlags grouping marker',
+                            'QEMU_CAPS_LAST /* this must')
+capsflags = load_caps_flags(header_lines[start:end])
 
 if not regroup_caps(args.check,
                     source_path,
-- 
2.31.1




More information about the libvir-list mailing list