From nobody Thu May 2 04:33:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587387701; cv=none; d=zohomail.com; s=zohoarc; b=V7wAWIJUvQPt05Kr8I3sZNwOpOLBqy2LP3m9Dv83w0m2tTp0trNdL3I9z1l6dUD+rWk0GtbDCyr3WYL3xqpZaJXQSVTunsz0hh/EtCbipjta+IbRZ+X9QyutR4WsqP7vokAORUAozTq8MjPL4M8IzaraU+7MmacRDuktEAn3mAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587387701; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kfIztzq8Vznia2GUiSs1Y0plmK0tucgD9VI3EiQ7wSQ=; b=UQXSegkkCSAuIVzYhR7yW8OF3tu9ndRyo1GcWssD0EQJ0ZXodwEJZpUwEBKq9Tc00f6DPJwk2fNRB0bEPZ44YTRQWU2I8CaoKvGfq7GZ3kG3gDftCCMazihQYg29WJUUi5GkXvSnemLn/CFlFTp9SgpYyzN1Ve0nGDLxAvcksg8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1587387701733995.3184145099575; Mon, 20 Apr 2020 06:01:41 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-9VGKngotO5KcUqK1JemfAA-1; Mon, 20 Apr 2020 09:01:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 350AB107ACC9; Mon, 20 Apr 2020 13:01:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF5415DA7C; Mon, 20 Apr 2020 13:01:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7D6CD18089CE; Mon, 20 Apr 2020 13:01:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03KD1Kru021312 for ; Mon, 20 Apr 2020 09:01:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 553331D0BA; Mon, 20 Apr 2020 13:01:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 515F6B5790 for ; Mon, 20 Apr 2020 13:01:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 310C28FF686 for ; Mon, 20 Apr 2020 13:01:18 +0000 (UTC) Received: from mail.univention.de (mail.univention.de [82.198.197.8]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196--oeYkYl-P_CK6rACCDIQ0g-1; Mon, 20 Apr 2020 09:01:15 -0400 Received: from localhost (localhost [127.0.0.1]) by solig.knut.univention.de (Postfix) with ESMTP id 261488E41991 for ; Mon, 20 Apr 2020 15:01:14 +0200 (CEST) Received: from mail.univention.de ([127.0.0.1]) by localhost (solig.knut.univention.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v925PxbhO7AP; Mon, 20 Apr 2020 15:01:12 +0200 (CEST) Received: from fixa.knut.univention.de (p5B21E7E0.dip0.t-ipconnect.de [91.33.231.224]) by solig.knut.univention.de (Postfix) with ESMTPSA id 842228E41987; Mon, 20 Apr 2020 15:01:12 +0200 (CEST) Received: by fixa.knut.univention.de (Postfix, from userid 2260) id 103A51671BB; Mon, 20 Apr 2020 15:01:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587387693; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kfIztzq8Vznia2GUiSs1Y0plmK0tucgD9VI3EiQ7wSQ=; b=aHbUWSMYiAW9XNYPOnHEv2aY5LupAWlipU97byIc9W/CUU3UHPOg0jI1cf6YP364b/C8N9 XIZCMD0kJJo61sMYtObUUhtzTwjtljqy/q5aPBniybSfWle6/FIzfriplUc7XKEZvukR6H UYyDtsCoWxHklY/5XYOnETnA17CDVN0= X-MC-Unique: 9VGKngotO5KcUqK1JemfAA-1 X-MC-Unique: -oeYkYl-P_CK6rACCDIQ0g-1 X-Virus-Scanned: by amavisd-new-2.10.1 (20141025) (Debian) at knut.univention.de From: Philipp Hahn To: libvir-list@redhat.com Subject: [PATCH v2] doc/python: Update to Python 3 Date: Mon, 20 Apr 2020 15:01:11 +0200 Message-Id: In-Reply-To: <20200420121745.GQ346737@redhat.com> References: <20200420121745.GQ346737@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03KD1Kru021312 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Convert the simple example to Python 3 syntax: - print() is a function - do not use bare except - libvirt.open*() does not return None but raises an exception The referenced source for the example was removed with 5bb2a245abbde4c0a407f631660e2f2c81bc4c02 Signed-off-by: Philipp Hahn Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/python.html.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/python.html.in b/docs/python.html.in index e6e8cfade9..0f804da8c3 100644 --- a/docs/python.html.in +++ b/docs/python.html.in @@ -38,24 +38,24 @@ specificities in their argument conversions:

is replaced by virDomain::info() which returns a list of
  1. state: one of the state values (virDomainState)
  2. maxMem= ory: the maximum memory used by the domain
  3. memory: the current amou= nt of memory used by the domain
  4. nbVirtCPU: the number of virtual CP= U
  5. cpuTime: the time used by the domain in nanoseconds
-

So let's look at a simple example inspired from the basic.py<= /code> -test found in python/tests/ in the source tree:

+

So let's look at a simple example:

import =
libvirt
 import sys
=20
-conn =3D libvirt=
.openReadOnly(None)
-if conn =3D=3D None:
-    print 'Failed to open connection to the hypervisor'
+try:
+    conn =3D lib=
virt.openReadOnly(None)
+except libvirt.libvirtError:
+    print('Failed to open connection to the hypervisor')
     sys.exit(1)
=20
 try:
     dom0 =3D conn.libvirt.libvirtError:
+    print('Failed to find the main domain')
     sys.exit(1)
=20
-print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())
-print dom0.info<=
/span>()
+print("Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())) +print(dom0.info<= /span>())

There is not much to comment about it, it really is a straight mapp= ing from the C API, the only points to notice are:

    --=20 2.20.1