From nobody Thu Oct 31 00:19:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1722432238390147.51333497523626; Wed, 31 Jul 2024 06:23:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F85713E5; Wed, 31 Jul 2024 09:23:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 98E4D13B8; Wed, 31 Jul 2024 09:22:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A656713F0; Wed, 31 Jul 2024 09:21:54 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E4437140E for ; Wed, 31 Jul 2024 09:21:45 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-Dw9vYFGzNSyNh3Kn41DT5w-1; Wed, 31 Jul 2024 09:21:44 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 731D61956046 for ; Wed, 31 Jul 2024 13:21:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17F3A1955E8C for ; Wed, 31 Jul 2024 13:21:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722432105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p6jiNRTnxIufoJ/aKVo6Y/nJvqm/tirLyuekJvKsVxY=; b=ZvxgWEjuS0O8XH/ifu5BZKycVaSZ2oihSbKW698B3h1DGpTSdjH92Qn14FsXectY0dVZ/C BCopkek+SqY9QFn6t83d2UU0nr7Dy+vUklf5N9d1gH5QuOga57aWkfzcofrzKgbC8p6xCl 3/coIBD9H3Lwsbz/wjLT0tKhUt17fv4= X-MC-Unique: Dw9vYFGzNSyNh3Kn41DT5w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: devel@lists.libvirt.org Subject: [libvirt PATCH 6/6] scripts: group-qemu-caps: separate file operations from the check Date: Wed, 31 Jul 2024 15:20:52 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LKH7QEQA3FY44CVM75BSFCIWC6CZSTE7 X-Message-ID-Hash: LKH7QEQA3FY44CVM75BSFCIWC6CZSTE7 X-MailFrom: jtomko@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1722432239402116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: J=C3=A1n Tomko --- scripts/group-qemu-caps.py | 50 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py index 34823931df..e4161f5bb5 100755 --- a/scripts/group-qemu-caps.py +++ b/scripts/group-qemu-caps.py @@ -61,14 +61,9 @@ def load_caps_flags(lines): return capsflags =20 =20 -def regroup_caps(check, filename, start_regex, end_regex, +def regroup_caps(original, start_regex, end_regex, trailing_newline, counter_prefix, capsflags): step =3D 5 - - original =3D [] - with open(filename, "r") as fh: - original =3D fh.read().splitlines() - fixed =3D [] game_on =3D False counter =3D 0 @@ -107,7 +102,10 @@ def regroup_caps(check, filename, start_regex, end_reg= ex, line =3D flagname[0] + " /* %s */" % capsflags[counter - 1] =20 fixed.append(line) + return fixed =20 + +def check(check, filename, original, fixed): if check: orig =3D "\n".join(original) + "\n" new =3D "\n".join(fixed) + "\n" @@ -143,22 +141,32 @@ errs =3D False 'QEMU_CAPS_LAST /* this must') capsflags =3D load_caps_flags(header_lines[start:end]) =20 -if not regroup_caps(args.check, - args.prefix + 'src/qemu/qemu_capabilities.c', - r'virQEMUCaps grouping marker', - r'\);', - 0, - " ", - capsflags): +(source_lines, source_start, source_end) =3D load_file(args.prefix + 'src/= qemu/qemu_capabilities.c', + r'virQEMUCaps groupin= g marker', + r'\);') +fixed_source =3D regroup_caps(source_lines, + r'virQEMUCaps grouping marker', + r'\);', + 0, + " ", + capsflags) + +fixed_header =3D regroup_caps(header_lines, + r'virQEMUCapsFlags grouping marker', + r'QEMU_CAPS_LAST \/\* this must', + 1, + " ", + None) + +if not check(args.check, + args.prefix + 'src/qemu/qemu_capabilities.c', + source_lines, + fixed_source): errs =3D True - -if not regroup_caps(args.check, - args.prefix + 'src/qemu/qemu_capabilities.h', - r'virQEMUCapsFlags grouping marker', - r'QEMU_CAPS_LAST \/\* this must', - 1, - " ", - None): +if not check(args.check, + args.prefix + 'src/qemu/qemu_capabilities.h', + header_lines, + fixed_header): errs =3D True =20 if errs: --=20 2.45.2