From nobody Sat Nov 15 12:19:36 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=1752506392; cv=none; d=zohomail.com; s=zohoarc; b=iFLiQsrfCdWimVNehFohWNA7kXihnUa1cKL1pIXzbia3Gu3dXaSDUUe4SWQ7ReIKi5kuW3MiYX65dg9oS8F63Mpo17vy4RHa2F0CVrhZ6PQnjV4ieJFbkX4Z3kC3VERabm3u0e9x2DlK5oeVX+jJrrNGE0rcpBS5wJ7uXnrmUfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752506392; 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=IOfhy2vu4VJSGhrF9ymJH05tgR5NONeAUTxL/TY8qJU=; b=ignHpfykej69i/b+FIOR0/cmtkcEFTsxdDrWeC6k1KnKIL7OhtEmmHsCOl4TORQCKsgfH/671ONEJLRwt+E17aAmEmyFA4n3CysC5DUv3kMyWpQn8AYWId9JMk72g1clUy3moKmbhO//eIeI/0wrsTMBOpLaSJkN6phEnwqqLQE= 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 1752506392643402.4490887835584; Mon, 14 Jul 2025 08:19:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubKrH-0008CF-GM; Mon, 14 Jul 2025 11:12:49 -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 1ubJUn-0000PR-8b for qemu-devel@nongnu.org; Mon, 14 Jul 2025 09:45:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubJUX-0003dN-J6 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 09:45:28 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-6SBFdQjNOVS4WMhtcfJOig-1; Mon, 14 Jul 2025 09:45:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1DC018011EE; Mon, 14 Jul 2025 13:45:09 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D07530001B5; Mon, 14 Jul 2025 13:45:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3C51821E60FD; Mon, 14 Jul 2025 15:44:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752500712; 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=IOfhy2vu4VJSGhrF9ymJH05tgR5NONeAUTxL/TY8qJU=; b=PgsFVvTIE6jH1efXarD5ygH6kxgiN0Eb4d9ylQh/g/GR7a0k7XFzPYeBvbo2fdKlKmmPXT 55B7zBaE0u+RqQCGkvtmaZuw+ECW+3svx0Q4O30XAzISJTGPw9ri62L/SeClPVe5U+SZ3G 4hStKevSKWd2yi3cTKaQ7vz2KFZg/7Q= X-MC-Unique: 6SBFdQjNOVS4WMhtcfJOig-1 X-Mimecast-MFC-AGG-ID: 6SBFdQjNOVS4WMhtcfJOig_1752500709 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Steve Sistare Subject: [PULL 31/32] python: use qom-list-get Date: Mon, 14 Jul 2025 15:44:57 +0200 Message-ID: <20250714134458.2991097-32-armbru@redhat.com> In-Reply-To: <20250714134458.2991097-1-armbru@redhat.com> References: <20250714134458.2991097-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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.129.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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1752506394891116600 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 Signed-off-by: Markus Armbruster --- python/qemu/utils/qom.py | 43 +++++++++++++++----------- python/qemu/utils/qom_common.py | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 18 deletions(-) diff --git a/python/qemu/utils/qom.py b/python/qemu/utils/qom.py index 426a0f245f..337ae29b8c 100644 --- a/python/qemu/utils/qom.py +++ b/python/qemu/utils/qom.py @@ -224,28 +224,35 @@ 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: [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 =3D=3D None: + value =3D f"" + 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..e471f1d2ec 100644 --- a/python/qemu/utils/qom_common.py +++ b/python/qemu/utils/qom_common.py @@ -65,6 +65,50 @@ 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 + """ + def __init__(self, properties): + 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 +189,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[ObjectPropertiesValues]: + """ + :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