[libvirt PATCH 01/11] scripts: group-qemu-caps: read file separately in load_caps_flags
Pavel Hrdina
phrdina at redhat.com
Wed Aug 25 12:10:33 UTC 2021
On Tue, Aug 24, 2021 at 04:25:04PM +0200, Ján Tomko wrote:
> Split the file by lines and store it in a list.
> Switch the rest of the function to operate on this list,
> to prepare for splitting out the fire reading logic.
>
> Signed-off-by: Ján Tomko <jtomko at redhat.com>
> ---
> scripts/group-qemu-caps.py | 30 ++++++++++++++++--------------
> 1 file changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
> index 8a899a76c2..ec10f24384 100755
> --- a/scripts/group-qemu-caps.py
> +++ b/scripts/group-qemu-caps.py
> @@ -30,24 +30,26 @@ import sys
> def load_caps_flags(filename, start_regex, end_regex):
> capsflags = []
> game_on = False
> + lines = []
>
> with open(filename, "r") as fh:
> - for line in fh:
> - line = line.rstrip("\n")
> - 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)
> + lines = fh.read().splitlines()
you can use fh.readlines() directly
> - if match:
> - capsflags.append(match[1])
> + 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 re.search(start_regex, line):
> - game_on = True
> - elif game_on and re.search(end_regex, line):
> - game_on = False
> + if match:
> + capsflags.append(match[1])
> +
> + if re.search(start_regex, line):
> + game_on = True
> + elif game_on and re.search(end_regex, line):
> + game_on = False
>
> return capsflags
>
> --
> 2.31.1
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210825/6976c762/attachment-0001.sig>
More information about the libvir-list
mailing list