All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fixed scripts to run with python 3
@ 2016-02-24 19:46 Kurt McAlpine
  2016-02-26 12:03 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 4+ messages in thread
From: Kurt McAlpine @ 2016-02-24 19:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Kurt McAlpine

---
 test/example-gatt-client | 13 ++++++++-----
 test/example-gatt-server | 20 ++++++++++++--------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/test/example-gatt-client b/test/example-gatt-client
index 724a45d..5a02505 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 67dee1a..f2ddb2b 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,
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fixed scripts to run with python 3
  2016-02-24 19:46 [PATCH] Fixed scripts to run with python 3 Kurt McAlpine
@ 2016-02-26 12:03 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-26 12:03 UTC (permalink / raw)
  To: Kurt McAlpine; +Cc: linux-bluetooth

Hi,

On Wed, Feb 24, 2016 at 9:46 PM, Kurt McAlpine <kurt@linux.com> wrote:
> ---
>  test/example-gatt-client | 13 ++++++++-----
>  test/example-gatt-server | 20 ++++++++++++--------
>  2 files changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/test/example-gatt-client b/test/example-gatt-client
> index 724a45d..5a02505 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 67dee1a..f2ddb2b 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,
> --
> 2.7.1

Applied, thanks.



-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fixed scripts to run with python 3
  2016-02-23  1:44 Kurt McAlpine
@ 2016-02-24  9:11 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-24  9:11 UTC (permalink / raw)
  To: Kurt McAlpine; +Cc: linux-bluetooth

Hi Kurt,

On Tue, Feb 23, 2016 at 3:44 AM, Kurt McAlpine <kurt@linux.com> wrote:
> Hello,
>
> I created a patch to fix example-gatt-server and example-gatt-client
> since they used a mix of python 2 and 3 syntax.
>

Could you please send a proper patch, by using git send-email, also
please make sure that you do follow the guidelines under HACKING and
set a proper author with your email, etc.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Fixed scripts to run with python 3
@ 2016-02-23  1:44 Kurt McAlpine
  2016-02-24  9:11 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 4+ messages in thread
From: Kurt McAlpine @ 2016-02-23  1:44 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 132 bytes --]

Hello,

I created a patch to fix example-gatt-server and example-gatt-client
since they used a mix of python 2 and 3 syntax.

	Kurt

[-- Attachment #2: 0001-Fixed-scripts-to-run-with-python-3.patch --]
[-- Type: text/x-diff, Size: 3566 bytes --]

Subject: [PATCH] Fixed scripts to run with python 3

Fix up syntax problems so that this code actually runs.

---
 test/example-gatt-client | 13 ++++++++-----
 test/example-gatt-server | 20 ++++++++++++--------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/test/example-gatt-client b/test/example-gatt-client
index 724a45d..5a02505 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 67dee1a..f2ddb2b 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,
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-26 12:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-24 19:46 [PATCH] Fixed scripts to run with python 3 Kurt McAlpine
2016-02-26 12:03 ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2016-02-23  1:44 Kurt McAlpine
2016-02-24  9:11 ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.