summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKurt McAlpine <kurt@linux.com>2016-02-25 08:46:46 +1300
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2016-02-26 13:37:09 +0200
commit584e5f018d74b93b24aa0d9c59749a75a4df9fae (patch)
tree74b592106727bd629b042be6c47631f7122e9d74 /test
parente074cc1fa5e0a5ddd799aefd13aa16179821349a (diff)
downloadbluez-584e5f018d74b93b24aa0d9c59749a75a4df9fae.tar.gz
test: Fix scripts to run with python 3
Diffstat (limited to 'test')
-rwxr-xr-xtest/example-gatt-client13
-rwxr-xr-xtest/example-gatt-server20
2 files changed, 20 insertions, 13 deletions
diff --git a/test/example-gatt-client b/test/example-gatt-client
index 724a45d89..5a0250556 100755
--- a/test/example-gatt-client
+++ b/test/example-gatt-client
@@ -1,8 +1,11 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
import argparse
import dbus
-import gobject
+try:
+ from gi.repository import GObject
+except ImportError:
+ import gobject as GObject
import sys
from dbus.mainloop.glib import DBusGMainLoop
@@ -195,7 +198,7 @@ def main():
global bus
bus = dbus.SystemBus()
global mainloop
- mainloop = gobject.MainLoop()
+ mainloop = GObject.MainLoop()
om = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, '/'), DBUS_OM_IFACE)
om.connect_to_signal('InterfacesRemoved', interfaces_removed_cb)
@@ -204,10 +207,10 @@ def main():
if not process_hr_service(service_path):
sys.exit(1)
except dbus.DBusException as e:
- print e.message
+ print(e)
sys.exit(1)
- print 'Heart Rate Service ready'
+ print('Heart Rate Service ready')
start_client()
diff --git a/test/example-gatt-server b/test/example-gatt-server
index 67dee1ad2..f2ddb2bbd 100755
--- a/test/example-gatt-server
+++ b/test/example-gatt-server
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
import dbus
import dbus.exceptions
@@ -6,7 +6,11 @@ import dbus.mainloop.glib
import dbus.service
import array
-import gobject
+try:
+ from gi.repository import GObject
+except ImportError:
+ import gobject as GObject
+import sys
from random import randint
from collections import OrderedDict
@@ -285,7 +289,7 @@ class HeartRateMeasurementChrc(Characteristic):
if not self.notifying:
return
- gobject.timeout_add(1000, self.hr_msrmt_cb)
+ GObject.timeout_add(1000, self.hr_msrmt_cb)
def StartNotify(self):
if self.notifying:
@@ -372,7 +376,7 @@ class BatteryLevelCharacteristic(Characteristic):
service)
self.notifying = False
self.battery_lvl = 100
- gobject.timeout_add(5000, self.drain_battery)
+ GObject.timeout_add(5000, self.drain_battery)
def notify_battery_level(self):
if not self.notifying:
@@ -480,7 +484,7 @@ class CharacteristicUserDescriptionDescriptor(Descriptor):
def __init__(self, bus, index, characteristic):
self.writable = 'writable-auxiliaries' in characteristic.flags
- self.value = array.array('B', 'This is a characteristic for testing')
+ self.value = array.array('B', b'This is a characteristic for testing')
self.value = self.value.tolist()
Descriptor.__init__(
self, bus, index,
@@ -555,8 +559,8 @@ def find_adapter(bus):
DBUS_OM_IFACE)
objects = remote_om.GetManagedObjects()
- for o, props in objects.iteritems():
- if props.has_key(GATT_MANAGER_IFACE):
+ for o, props in objects.items():
+ if GATT_MANAGER_IFACE in props.keys():
return o
return None
@@ -579,7 +583,7 @@ def main():
app = Application(bus)
- mainloop = gobject.MainLoop()
+ mainloop = GObject.MainLoop()
service_manager.RegisterApplication(app.get_path(), {},
reply_handler=register_app_cb,