From nobody Sat Nov 15 11:12:54 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752686824; cv=none; d=zohomail.com; s=zohoarc; b=KMBq0x7TWRv2oxAFeVxtxGKclUyKUhSaXiVcCkM15aXo+XDURJbfOrVA9Z9BaR572IQRHiK/k2c0qAPi28WvtKfe7Ns326rCyF50XghJJyXZqRyr0JqlBnlEz9YVlw1ZBzjbbEIbXJDJ11nKSwEz0hD56BJ1OLu1wF0AlFWhnXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752686824; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7gFio82H82XpXmL0jnSv5xvDWFvNWQ2OVJeSAKSdYbs=; b=jVNnw0WgmQTJp10f1/OYxNZ4r0HtGu6HNwMm3V1nZ6zOXN+P2MJA9ypHJAzYibSv4OrvVQcn5yfB4qV02JgFIGvq+LfXklbwsDY9/AHEZ2GTxwkBgfrvnpbV8PBZB65T1mGdu2uvFpawKtEeCZ8PEDE1IgNvZ70KQ6yvGe0PcoE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752686824175762.1644397609441; Wed, 16 Jul 2025 10:27:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uc5t6-0002yN-4a; Wed, 16 Jul 2025 13:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uc5t3-0002s8-4b for qemu-devel@nongnu.org; Wed, 16 Jul 2025 13:25:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uc5t0-00086t-DP for qemu-devel@nongnu.org; Wed, 16 Jul 2025 13:25:44 -0400 Received: from mx-prod-mc-01.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-176-g4M26thaN-CNtA7uhys6Sw-1; Wed, 16 Jul 2025 13:25:39 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E07B81956094; Wed, 16 Jul 2025 17:25:38 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4B1411977029; Wed, 16 Jul 2025 17:25:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6484F21E6925; Wed, 16 Jul 2025 19:25:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752686741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gFio82H82XpXmL0jnSv5xvDWFvNWQ2OVJeSAKSdYbs=; b=YTCTOMKQzGVYE2DCnyeLxFGenJ3bxp0EMuQQpSZ6CBIxSPe4Zx5TVZibTGEr4ULPCqKwuV PTiRC8oQe+QVN2UaqwR/NoYfVqgji8bihX+l8+2YM+cWcVQ/zyCDxatvImEBd96AoEvi7c yaC4zTlJtwLZeThxMjYwJT9VJ4U7LTU= X-MC-Unique: g4M26thaN-CNtA7uhys6Sw-1 X-Mimecast-MFC-AGG-ID: g4M26thaN-CNtA7uhys6Sw_1752686739 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Steve Sistare Subject: [PULL 2/6] python: use qom-list-get Date: Wed, 16 Jul 2025 19:25:31 +0200 Message-ID: <20250716172535.3520175-3-armbru@redhat.com> In-Reply-To: <20250716172535.3520175-1-armbru@redhat.com> References: <20250716172535.3520175-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752686826018116600 Content-Type: text/plain; charset="utf-8" From: Steve Sistare Use qom-list-get to speed up the qom-tree command. Signed-off-by: Steve Sistare Acked-by: Markus Armbruster Message-ID: <1752248703-217318-3-git-send-email-steven.sistare@oracle.com> Tested-by: Markus Armbruster [Lint picked off to mollify make check-minreqs] Signed-off-by: Markus Armbruster --- python/qemu/utils/qom.py | 45 +++++++++++++++------------ python/qemu/utils/qom_common.py | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 20 deletions(-) diff --git a/python/qemu/utils/qom.py b/python/qemu/utils/qom.py index 426a0f245f..05e5f14179 100644 --- a/python/qemu/utils/qom.py +++ b/python/qemu/utils/qom.py @@ -31,8 +31,7 @@ ## =20 import argparse - -from qemu.qmp import ExecuteError +from typing import List =20 from .qom_common import QOMCommand =20 @@ -224,28 +223,34 @@ def __init__(self, args: argparse.Namespace): super().__init__(args) self.path =3D args.path =20 - def _list_node(self, path: str) -> None: - print(path) - items =3D self.qom_list(path) - for item in items: - if item.child: - continue - try: - rsp =3D self.qmp.cmd('qom-get', path=3Dpath, - property=3Ditem.name) - print(f" {item.name}: {rsp} ({item.type})") - except ExecuteError as err: - print(f" {item.name}: ({item.type})") - print('') - for item in items: - if not item.child: - continue + def _list_nodes(self, paths: List[str]) -> None: + all_paths_props =3D self.qom_list_get(paths) + i =3D 0 + + for props in all_paths_props: + path =3D paths[i] + i =3D i + 1 + print(path) if path =3D=3D '/': path =3D '' - self._list_node(f"{path}/{item.name}") + newpaths =3D [] + + for item in props.properties: + if item.child: + newpaths +=3D [f"{path}/{item.name}"] + else: + value =3D item.value + if value is None: + value =3D "" + print(f" {item.name}: {value} ({item.type})") + + print('') + + if newpaths: + self._list_nodes(newpaths) =20 def run(self) -> int: - self._list_node(self.path) + self._list_nodes([self.path]) return 0 =20 =20 diff --git a/python/qemu/utils/qom_common.py b/python/qemu/utils/qom_common= .py index dd2c8b1908..ab21a4d364 100644 --- a/python/qemu/utils/qom_common.py +++ b/python/qemu/utils/qom_common.py @@ -65,6 +65,52 @@ def link(self) -> bool: return self.type.startswith('link<') =20 =20 +class ObjectPropertyValue: + """ + Represents a property return from e.g. qom-tree-get + """ + def __init__(self, name: str, type_: str, value: object): + self.name =3D name + self.type =3D type_ + self.value =3D value + + @classmethod + def make(cls, value: Dict[str, Any]) -> 'ObjectPropertyValue': + """ + Build an ObjectPropertyValue from a Dict with an unknown shape. + """ + assert value.keys() >=3D {'name', 'type'} + assert value.keys() <=3D {'name', 'type', 'value'} + return cls(value['name'], value['type'], value.get('value')) + + @property + def child(self) -> bool: + """Is this property a child property?""" + return self.type.startswith('child<') + + +class ObjectPropertiesValues: + """ + Represents the return type from e.g. qom-list-get + """ + # pylint: disable=3Dtoo-few-public-methods + + def __init__(self, properties: List[ObjectPropertyValue]) -> None: + self.properties =3D properties + + @classmethod + def make(cls, value: Dict[str, Any]) -> 'ObjectPropertiesValues': + """ + Build an ObjectPropertiesValues from a Dict with an unknown shape. + """ + assert value.keys() =3D=3D {'properties'} + props =3D [ObjectPropertyValue(item['name'], + item['type'], + item.get('value')) + for item in value['properties']] + return cls(props) + + CommandT =3D TypeVar('CommandT', bound=3D'QOMCommand') =20 =20 @@ -145,6 +191,15 @@ def qom_list(self, path: str) -> List[ObjectPropertyIn= fo]: assert isinstance(rsp, list) return [ObjectPropertyInfo.make(x) for x in rsp] =20 + def qom_list_get(self, paths: List[str]) -> List[ObjectPropertiesValue= s]: + """ + :return: a strongly typed list from the 'qom-list-get' command. + """ + rsp =3D self.qmp.cmd('qom-list-get', paths=3Dpaths) + # qom-list-get returns List[ObjectPropertiesValues] + assert isinstance(rsp, list) + return [ObjectPropertiesValues.make(x) for x in rsp] + @classmethod def command_runner( cls: Type[CommandT], --=20 2.49.0