Re: [PATCH v5 16/23] tests: rewrite qemu capability grouper in Python

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

 



On 11/11/19 9:38 AM, Daniel P. Berrangé wrote:
> As part of an goal to eliminate Perl from libvirt build tools,
> rewrite the group-qemu-caps.pl tool in Python.
> 
> This was a straight conversion, manually going line-by-line to
> change the syntax from Perl to Python. Thus the overall structure
> of the file and approach is the same.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
> ---
>  Makefile.am                |   1 +
>  build-aux/syntax-check.mk  |   3 +-
>  scripts/group-qemu-caps.py | 123 ++++++++++++++++++++++++++++++++++++
>  tests/group-qemu-caps.pl   | 124 -------------------------------------
>  4 files changed, 126 insertions(+), 125 deletions(-)
>  create mode 100755 scripts/group-qemu-caps.py
>  delete mode 100755 tests/group-qemu-caps.pl
> 
> diff --git a/Makefile.am b/Makefile.am
> index 6f6cead526..769cd4ce64 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -57,6 +57,7 @@ EXTRA_DIST = \
>    scripts/dtrace2systemtap.py \
>    scripts/genpolkit.py \
>    scripts/gensystemtap.py \
> +  scripts/group-qemu-caps.py \
>    scripts/header-ifdef.py \
>    scripts/minimize-po.py \
>    scripts/mock-noinline.py \
> diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
> index 7d54df182a..44639f499e 100644
> --- a/build-aux/syntax-check.mk
> +++ b/build-aux/syntax-check.mk
> @@ -2176,7 +2176,8 @@ test-wrap-argv:
>  	$(PYTHON) $(top_srcdir)/scripts/test-wrap-argv.py --check
>  
>  group-qemu-caps:
> -	$(AM_V_GEN)$(PERL) $(top_srcdir)/tests/group-qemu-caps.pl --check $(top_srcdir)/
> +	$(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/group-qemu-caps.py \
> +		--check --prefix $(top_srcdir)/
>  
>  # List all syntax-check exemptions:
>  exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$
> diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
> new file mode 100755
> index 0000000000..3edaf5d09f
> --- /dev/null
> +++ b/scripts/group-qemu-caps.py
> @@ -0,0 +1,123 @@
> +#!/usr/bin/env python
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library.  If not, see
> +# <http://www.gnu.org/licenses/>.
> +#
> +#
> +# Regroup array values into smaller groups separated by numbered comments.
> +#
> +# If --check is the first parameter, the script will return
> +# a non-zero value if a file is not grouped correctly.
> +# Otherwise the files are regrouped in place.
> +
> +from __future__ import print_function
> +
> +import argparse
> +import re
> +import subprocess
> +import sys
> +
> +
> +def regroup_caps(check, filename, start_regex, end_regex,
> +                 trailing_newline, counter_prefix):
> +    step = 5
> +
> +    original = []
> +    with open(filename, "r") as fh:
> +        for line in fh:
> +            original.append(line)
> +
> +    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
> +            if re.search(r'''^\s*$''', line):
> +                continue
> +            if counter % step == 0:
> +                if counter != 0:
> +                    fixed.append("\n")
> +                fixed.append("%s/* %d */\n" % (counter_prefix, counter))
> +
> +            if not (line.find("/*") != -1 and line.find("*/") == -1):
> +                # count two-line comments as one line
> +                counter = counter + 1
> +
> +        if re.search(start_regex, line):
> +            game_on = True
> +        elif game_on and re.search(end_regex, line):
> +            if (counter - 1) % step == 0:
> +                fixed = fixed[:-1]  # /* $counter */
> +                if counter != 1:
> +                    fixed = fixed[:-1]  # \n
> +
> +            if trailing_newline:
> +                fixed.append("\n")
> +
> +            game_on = False
> +
> +        fixed.append(line + "\n")
> +
> +    if check:
> +        orig = "".join(original)
> +        new = "".join(fixed)
> +        if new != orig:
> +            diff = subprocess.Popen(["diff", "-u", filename, "-"],
> +                                    stdin=subprocess.PIPE)
> +            diff.communicate(input=new.encode('utf-8'))
> +
> +            print("Incorrect line wrapping in $file",
> +                  file=sys.stderr)
> +            print("Use test-wrap-argv.py to wrap test data files",
> +                  file=sys.stderr)

test-wrap-arg reference here

> +            return False
> +    else:
> +        with open(filename, "w") as fh:
> +            for line in fixed:
> +                print(line, file=fh, end='')
> +
> +    return True
> +
> +
> +parser = argparse.ArgumentParser(description='Test arg line wrapper')

test-wrap-arg reference here, should be group-qemu-caps

Otherwise it seems to work as expected

Tested-by: Cole Robinson <crobinso@xxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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