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.
This commit is contained in:
Thomas Haller
2022-02-14 16:57:53 +01:00
parent 164840a33c
commit 95e6a0a6e2
3 changed files with 28 additions and 22 deletions

View File

@@ -15,23 +15,23 @@ main_loop = None
def handle_config(config): def handle_config(config):
print " ---- new configuration ----" print(" ---- new configuration ----")
for entry in config: 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() domains = entry.get_domains()
if domains and domains[0]: if domains and domains[0]:
print " domains: %s" % ", ".join(map(str, domains)) print(" domains: %s" % ", ".join(map(str, domains)))
if entry.get_interface(): 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(): if entry.get_vpn():
print " vpn: yes" print(" vpn: yes")
print "" print("")
def dns_config_changed(self, property): def dns_config_changed(self, property):

View File

@@ -15,22 +15,28 @@ if __name__ == "__main__":
client = NM.Client.new(None) client = NM.Client.new(None)
devices = client.get_all_devices() devices = client.get_all_devices()
print "Real devices" print("Real devices")
print "------------" print("------------")
for d in devices: for d in devices:
if d.is_real(): if d.is_real():
print "%s (%s): %s" % ( print(
d.get_iface(), "%s (%s): %s"
d.get_type_description(), % (
d.get_state(), d.get_iface(),
d.get_type_description(),
d.get_state(),
)
) )
print "\nUnrealized/placeholder devices" print("\nUnrealized/placeholder devices")
print "------------------------------" print("------------------------------")
for d in devices: for d in devices:
if not d.is_real(): if not d.is_real():
print "%s (%s): %s" % ( print(
d.get_iface(), "%s (%s): %s"
d.get_type_description(), % (
d.get_state(), d.get_iface(),
d.get_type_description(),
d.get_state(),
)
) )

View File

@@ -28,12 +28,12 @@ if __name__ == "__main__":
for neighbor in neighbors: for neighbor in neighbors:
ret, chassis = neighbor.get_attr_string_value("chassis-id") ret, chassis = neighbor.get_attr_string_value("chassis-id")
ret, port = neighbor.get_attr_string_value("port-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(): for attr in neighbor.get_attr_names():
attr_type = neighbor.get_attr_type(attr) attr_type = neighbor.get_attr_type(attr)
if attr_type.equal(GLib.VariantType.new("s")): if attr_type.equal(GLib.VariantType.new("s")):
ret, value = neighbor.get_attr_string_value(attr) 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")): elif attr_type.equal(GLib.VariantType.new("u")):
ret, value = neighbor.get_attr_uint_value(attr) ret, value = neighbor.get_attr_uint_value(attr)
print " %-32s: %u" % (attr, value) print(" %-32s: %u" % (attr, value))