diff options
| author | Pavel Hrdina <phrdina@redhat.com> | 2014-11-26 18:47:17 +0100 |
|---|---|---|
| committer | Pavel Hrdina <phrdina@redhat.com> | 2014-12-01 17:34:31 +0100 |
| commit | 39f19f0a2db57ff2e852c3ff97582f4832884986 (patch) | |
| tree | d88f10b98554330d023d85bac565c75e51918193 /examples | |
| parent | acc47bcb71dd523264ba7e626624746017a052bc (diff) | |
| download | libvirt-python-39f19f0a2db57ff2e852c3ff97582f4832884986.tar.gz | |
fix examples
The dhcpleases example had an old usage of print function. The formating
of leases record was also wrong.
The event-test example had an old usage of exceptions.
It's mainly to make examples compatible with python3.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/dhcpleases.py | 30 | ||||
| -rwxr-xr-x | examples/event-test.py | 4 |
2 files changed, 22 insertions, 12 deletions
diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py index c172dc2..da51f52 100755 --- a/examples/dhcpleases.py +++ b/examples/dhcpleases.py @@ -6,8 +6,8 @@ import sys import time def usage(): - print "Usage: %s [URI] NETWORK" % sys.argv[0] - print " Print leases info for a given virtual network" + print("Usage: %s [URI] NETWORK" % sys.argv[0]) + print(" Print leases info for a given virtual network") uri = None network = None @@ -24,18 +24,18 @@ else: conn = libvirt.open(uri) if conn == None: - print "Unable to open connection to libvirt" + print("Unable to open connection to libvirt") sys.exit(1) try: net = conn.networkLookupByName(network) except libvirt.libvirtError: - print "Network %s not found" % network + print("Network %s not found" % network) sys.exit(0) leases = net.DHCPLeases(); if (leases == None): - print "Failed to get leases for %s" % net.name() + print("Failed to get leases for %s" % net.name()) sys.exit(0) def toIPAddrType(addrType): @@ -44,10 +44,20 @@ def toIPAddrType(addrType): elif addrType == libvirt.VIR_IP_ADDR_TYPE_IPV6: return "ipv6" -print " {0:20} {1:18} {2:9} {3:25} {4:15} {5}".format("Expiry Time", "MAC address", "Protocol", "IP address", "Hostname", "Client ID or DUID") -print "-"*115 +print(" {0:20} {1:18} {2:9} {3:25} {4:15} {5}".format("Expiry Time", + "MAC address", + "Protocol", + "IP address", + "Hostname", + "Client ID or DUID")) +print("-"*115) for lease in leases: - print " {0:20}".format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lease['expirytime']))), - print "{0:18} {1:9}".format(lease['mac'], toIPAddrType(lease['type'])), - print "{0:<25} {1:15} {2}".format("{}/{}".format(lease['ipaddr'], lease['prefix']), lease['hostname'], lease['clientid']) + print(" {0:20} {1:18} {2:9} {3:25} {4:15} {5}".format( + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lease['expirytime'])), + lease['mac'], + toIPAddrType(lease['type']), + "{}/{}".format(lease['ipaddr'], lease['prefix']), + lease['hostname'], + lease['clientid'] + )) diff --git a/examples/event-test.py b/examples/event-test.py index 6cc33ce..452f659 100755 --- a/examples/event-test.py +++ b/examples/event-test.py @@ -220,7 +220,7 @@ class virEventLoopPure: t.set_last_fired(now) t.dispatch() - except (os.error, select.error), e: + except (os.error, select.error) as e: if e.args[0] != errno.EINTR: raise finally: @@ -576,7 +576,7 @@ def usage(): def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hdl", ["help", "debug", "loop"]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" usage() |
