From nobody Fri May 3 06:05:30 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=1587362542; cv=none;
d=zohomail.com; s=zohoarc;
b=cKAru/fKWhRAk42laKwakfe02wd6a2zBKLIMdv3rCsLXZONRcWJAb1gNG4J6rybEWDnAXBC1DvwdwTXIodFtVK9mTjdTrp/aTWxR+S6CDqrqGUVTUcZu5ROfeyvtvL0y5bI0Kci4B/fGfBoccSNZ9CapoRxfPoE/G6ZGJs7pyPA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
s=zohoarc;
t=1587362542;
h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To;
bh=JALltIsncJNLi1LeSTtD3+RVcqBhXc3h22+0zZoUvuM=;
b=Dc0VJ15sK7BmUvkieXmO7GZ+b8eKBhXfS9i9Q5p8v0eMRPXK01l/kg7oG4ClFKjPfYQB6YGlrNVdArLqic8bIpxUDhM3L64PEhxjYdd/lF9TI0RoSV71KvsSBA+a79fGZ1cmL/f5qTfBXCIRD8TqOVYgQ8bn+XCye+l8mPh5qyA=
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 1587362542547140.28354412601925;
Sun, 19 Apr 2020 23:02:22 -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-420-_yOgYFKTO5aC3AMpUWcxWA-1; Mon, 20 Apr 2020 02:02:18 -0400
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD9CE18C35A1;
Mon, 20 Apr 2020 06:02:12 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
(colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21])
by smtp.corp.redhat.com (Postfix) with ESMTPS id CB8D71001DDE;
Mon, 20 Apr 2020 06:02:10 +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 0716493901;
Mon, 20 Apr 2020 06:02:08 +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 03K626WG025043 for ;
Mon, 20 Apr 2020 02:02:07 -0400
Received: by smtp.corp.redhat.com (Postfix)
id C20E8AF7BC; Mon, 20 Apr 2020 06:02:06 +0000 (UTC)
Received: from mimecast-mx02.redhat.com
(mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17])
by smtp.corp.redhat.com (Postfix) with ESMTPS id BE867AF7A7
for ; Mon, 20 Apr 2020 06:02:04 +0000 (UTC)
Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com
[205.139.110.120])
(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 728A18EE319
for ; Mon, 20 Apr 2020 06:02:04 +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-232-UWYew7feOJCfuoRItKFYbg-1; Mon, 20 Apr 2020 02:02:01 -0400
Received: from localhost (localhost [127.0.0.1])
by solig.knut.univention.de (Postfix) with ESMTP id 155CA8E320BA
for ; Mon, 20 Apr 2020 08:01:59 +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 bfiKy7hDejHK; Mon, 20 Apr 2020 08:01:55 +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 451918E320B0;
Mon, 20 Apr 2020 08:01:55 +0200 (CEST)
Received: by fixa.knut.univention.de (Postfix, from userid 2260)
id C482715F6A7; Mon, 20 Apr 2020 08:01:54 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
s=mimecast20190719; t=1587362541;
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:list-id:list-help:
list-unsubscribe:list-subscribe:list-post;
bh=JALltIsncJNLi1LeSTtD3+RVcqBhXc3h22+0zZoUvuM=;
b=i7Oszju96zXV8HSTWfgDVsre2406kJOOjV3nSCoPeGiauUa7D8rgPn0OXgfBsXaro+aTyF
NWwQK86BaG61t7xfQMXxs6Gs4UPDJrzUJHdZ5DiZCPHgl3y6CotOw2AeDFP2ZXZ6ubciXb
ZU35KOZoZ7JUKDJ+dgLden85U9VoFmo=
X-MC-Unique: _yOgYFKTO5aC3AMpUWcxWA-1
X-MC-Unique: UWYew7feOJCfuoRItKFYbg-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] doc/python: Update to Python 3
Date: Mon, 20 Apr 2020 08:01:54 +0200
Message-Id:
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 03K626WG025043
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.84 on 10.5.11.22
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
---
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
- state: one of the state values (virDomainState)
- maxMem=
ory: the maximum memory used by the domain
- memory: the current amou=
nt of memory used by the domain
- nbVirtCPU: the number of virtual CP=
U
- 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=
span>.libvirtError:
+ print('Failed to open connection to the hypervisor')
sys.exit(1)
=20
try:
dom0 =3D conn.lookupByName("Domain-0")
-except:
- print 'Failed to find the main domain'
+except libvirt=
span>.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: