From 16801435582d9bc3f15644673b22ee664cb3b1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Tue, 2 Apr 2013 11:43:09 +0200 Subject: [PATCH] libnm-glib: adapt example to python 3.x It now works with sufficiently recent python 2.x or python 3.x, whatever is the distribution default. This patch fixes 'make check' for distributions where 'python' means python 3.x, like Gentoo. --- .../tests/test-remote-settings-service.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libnm-glib/tests/test-remote-settings-service.py b/libnm-glib/tests/test-remote-settings-service.py index 8654200550..f0103b97e2 100755 --- a/libnm-glib/tests/test-remote-settings-service.py +++ b/libnm-glib/tests/test-remote-settings-service.py @@ -1,8 +1,9 @@ #!/usr/bin/env python # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -import glib -import gobject +from __future__ import print_function + +from gi.repository import GLib, GObject import sys import dbus import dbus.service @@ -21,7 +22,7 @@ class UnknownPropertyException(dbus.DBusException): class PermissionDeniedException(dbus.DBusException): _dbus_error_name = IFACE_SETTINGS + '.PermissionDenied' -mainloop = gobject.MainLoop() +mainloop = GObject.MainLoop() class Connection(dbus.service.Object): def __init__(self, bus, object_path, settings, remove_func): @@ -72,10 +73,10 @@ class Settings(dbus.service.Object): @dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='a{sa{sv}}', out_signature='o') def AddConnection(self, settings): - path = "/org/freedesktop/NetworkManager/Settings/Connection/%d" % self.counter + path = "/org/freedesktop/NetworkManager/Settings/Connection/{0}".format(self.counter) self.counter = self.counter + 1 self.connections[path] = Connection(self.bus, path, settings, self.delete_connection) - print "Added connection %s" % path + print("Added connection {0}".format(path)) return path def delete_connection(self, connection): @@ -114,16 +115,16 @@ def main(): if not bus.request_name("org.freedesktop.NetworkManager"): sys.exit(1) - print "Service started" + print("Service started") - gobject.timeout_add_seconds(20, quit_cb, None) + GLib.timeout_add_seconds(20, quit_cb, None) try: mainloop.run() - except Exception, e: + except Exception as e: pass - print "Service stopped" + print("Service stopped") sys.exit(0) if __name__ == '__main__':