From 09669f0045ce2baf70983ca8860970c87575aaab Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Feb 2022 16:57:53 +0100 Subject: [PATCH] examples/python: avoid Python2 "print" statement Recent python-black (22.0) dropped support for Python 2 and thus fail for those files. Make the examples Python3 compatible. (cherry picked from commit 95e6a0a6e253dfdcd77ebc65d629fb3789f5f0e3) (cherry picked from commit 2e4d1e8dc6eab48e73e0c08a98c10f4fa1e8db4a) (cherry picked from commit b78ca328d29e1ed2793fe698dc201e97125d40ed) (cherry picked from commit 25062ff17bfff3039db2b418b81ac2132c6be82a) --- examples/python/gi/dns.py | 14 +++++------ examples/python/gi/get-devices.py | 30 ++++++++++++++---------- examples/python/gi/get-lldp-neighbors.py | 6 ++--- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/python/gi/dns.py b/examples/python/gi/dns.py index 6b42a339e0..483fe25f7d 100755 --- a/examples/python/gi/dns.py +++ b/examples/python/gi/dns.py @@ -15,23 +15,23 @@ main_loop = None def handle_config(config): - print " ---- new configuration ----" + print(" ---- new configuration ----") for entry in config: - print " * servers: %s" % ", ".join(map(str, entry.get_nameservers())) + print(" * servers: %s" % ", ".join(map(str, entry.get_nameservers()))) domains = entry.get_domains() if domains and domains[0]: - print " domains: %s" % ", ".join(map(str, domains)) + print(" domains: %s" % ", ".join(map(str, domains))) if entry.get_interface(): - print " interface: %s" % entry.get_interface() + print(" interface: %s" % entry.get_interface()) - print " priority: %d" % entry.get_priority() + print(" priority: %d" % entry.get_priority()) if entry.get_vpn(): - print " vpn: yes" + print(" vpn: yes") - print "" + print("") def dns_config_changed(self, property): diff --git a/examples/python/gi/get-devices.py b/examples/python/gi/get-devices.py index 5d753d80bb..43fd934372 100755 --- a/examples/python/gi/get-devices.py +++ b/examples/python/gi/get-devices.py @@ -15,22 +15,28 @@ if __name__ == "__main__": client = NM.Client.new(None) devices = client.get_all_devices() - print "Real devices" - print "------------" + print("Real devices") + print("------------") for d in devices: if d.is_real(): - print "%s (%s): %s" % ( - d.get_iface(), - d.get_type_description(), - d.get_state(), + print( + "%s (%s): %s" + % ( + d.get_iface(), + d.get_type_description(), + d.get_state(), + ) ) - print "\nUnrealized/placeholder devices" - print "------------------------------" + print("\nUnrealized/placeholder devices") + print("------------------------------") for d in devices: if not d.is_real(): - print "%s (%s): %s" % ( - d.get_iface(), - d.get_type_description(), - d.get_state(), + print( + "%s (%s): %s" + % ( + d.get_iface(), + d.get_type_description(), + d.get_state(), + ) ) diff --git a/examples/python/gi/get-lldp-neighbors.py b/examples/python/gi/get-lldp-neighbors.py index f5ae83006e..2907dfa475 100755 --- a/examples/python/gi/get-lldp-neighbors.py +++ b/examples/python/gi/get-lldp-neighbors.py @@ -28,12 +28,12 @@ if __name__ == "__main__": for neighbor in neighbors: ret, chassis = neighbor.get_attr_string_value("chassis-id") ret, port = neighbor.get_attr_string_value("port-id") - print "Neighbor: %s - %s" % (chassis, port) + print("Neighbor: %s - %s" % (chassis, port)) for attr in neighbor.get_attr_names(): attr_type = neighbor.get_attr_type(attr) if attr_type.equal(GLib.VariantType.new("s")): ret, value = neighbor.get_attr_string_value(attr) - print " %-32s: %s" % (attr, value) + print(" %-32s: %s" % (attr, value)) elif attr_type.equal(GLib.VariantType.new("u")): ret, value = neighbor.get_attr_uint_value(attr) - print " %-32s: %u" % (attr, value) + print(" %-32s: %u" % (attr, value))