diff options
author | Hunt, Preston <preston.hunt@intel.com> | 2018-05-04 14:59:18 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2018-05-07 11:26:33 +0300 |
commit | 4c73cc65091b0ee5c9cb0181c7d33962e400ca0c (patch) | |
tree | f8f31d6f855dfd3461f6b987d1876000a3d0eb56 /test | |
parent | 87f4b56b0150a620c2697b244c6353cb43f3fd13 (diff) | |
download | bluez-4c73cc65091b0ee5c9cb0181c7d33962e400ca0c.tar.gz |
test/example-advertisement: add python3 support
This adds support for python3 to the existing script. The script will
now work with either python2 or python3.
Diffstat (limited to 'test')
-rwxr-xr-x | test/example-advertisement | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/test/example-advertisement b/test/example-advertisement index d9b5b42d8..fd84eacf8 100755 --- a/test/example-advertisement +++ b/test/example-advertisement @@ -1,12 +1,18 @@ #!/usr/bin/python +from __future__ import print_function + import dbus import dbus.exceptions import dbus.mainloop.glib import dbus.service import array -import gobject + +try: + from gi.repository import GObject # python3 +except ImportError: + import gobject as GObject # python2 from random import randint @@ -118,17 +124,17 @@ class Advertisement(dbus.service.Object): in_signature='s', out_signature='a{sv}') def GetAll(self, interface): - print 'GetAll' + print('GetAll') if interface != LE_ADVERTISEMENT_IFACE: raise InvalidArgsException() - print 'returning props' + print('returning props') return self.get_properties()[LE_ADVERTISEMENT_IFACE] @dbus.service.method(LE_ADVERTISEMENT_IFACE, in_signature='', out_signature='') def Release(self): - print '%s: Released!' % self.path + print('%s: Released!' % self.path) class TestAdvertisement(Advertisement): @@ -144,11 +150,11 @@ class TestAdvertisement(Advertisement): def register_ad_cb(): - print 'Advertisement registered' + print('Advertisement registered') def register_ad_error_cb(error): - print 'Failed to register advertisement: ' + str(error) + print('Failed to register advertisement: ' + str(error)) mainloop.quit() @@ -157,7 +163,7 @@ def find_adapter(bus): DBUS_OM_IFACE) objects = remote_om.GetManagedObjects() - for o, props in objects.iteritems(): + for o, props in objects.items(): if LE_ADVERTISING_MANAGER_IFACE in props: return o @@ -173,7 +179,7 @@ def main(): adapter = find_adapter(bus) if not adapter: - print 'LEAdvertisingManager1 interface not found' + print('LEAdvertisingManager1 interface not found') return adapter_props = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), @@ -186,7 +192,7 @@ def main(): test_advertisement = TestAdvertisement(bus, 0) - mainloop = gobject.MainLoop() + mainloop = GObject.MainLoop() ad_manager.RegisterAdvertisement(test_advertisement.get_path(), {}, reply_handler=register_ad_cb, |