Linux bluetooth development
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [RFC v2 02/15] test: Add utility library for python scripts
Date: Thu, 29 Nov 2012 13:47:23 +0100	[thread overview]
Message-ID: <1354193256-30610-3-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1354193256-30610-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Several convenience functions/features will be removed from BlueZ's
D-Bus API, and therefore a utility library is required to avoid
boilerplate code in the test scripts.
---
 Makefile.tools    |  3 +--
 test/testutils.py | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 test/testutils.py

diff --git a/Makefile.tools b/Makefile.tools
index 689b4d2..5409432 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -1,4 +1,3 @@
-
 if TOOLS
 bin_PROGRAMS += tools/rfcomm tools/l2ping \
 				tools/hcitool tools/sdptool tools/ciptool
@@ -199,7 +198,7 @@ else
 EXTRA_DIST += test/rctest.1 test/hciemu.1 test/bdaddr.8
 endif
 
-EXTRA_DIST += test/sap_client.py test/hsplay test/hsmicro \
+EXTRA_DIST += test/sap_client.py test/hsplay test/hsmicro test/testutils.py \
 		test/dbusdef.py test/monitor-bluetooth test/list-devices \
 		test/test-discovery test/test-manager test/test-adapter \
 		test/test-device test/test-service test/simple-agent \
diff --git a/test/testutils.py b/test/testutils.py
new file mode 100644
index 0000000..a74ef35
--- /dev/null
+++ b/test/testutils.py
@@ -0,0 +1,25 @@
+import dbus
+
+SERVICE_NAME = "org.bluez"
+ADAPTER_INTERFACE = SERVICE_NAME + ".Adapter"
+
+def get_managed_objects():
+	bus = dbus.SystemBus()
+	manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+				"org.freedesktop.DBus.ObjectManager")
+	return manager.GetManagedObjects()
+
+def find_adapter(pattern=None):
+	return find_adapter_in_objects(get_managed_objects(), pattern)
+
+def find_adapter_in_objects(objects, pattern=None):
+	bus = dbus.SystemBus()
+	for path, ifaces in objects.iteritems():
+		adapter = ifaces.get(ADAPTER_INTERFACE)
+		if adapter == None:
+			continue
+		if (pattern == None or pattern == adapter["Address"] or
+							path.endswith(pattern)):
+			obj = bus.get_object(SERVICE_NAME, path)
+			return dbus.Interface(obj, ADAPTER_INTERFACE)
+	raise Exception("Bluetooth adapter not found")
-- 
1.7.11.7


  parent reply	other threads:[~2012-11-29 12:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-29 12:47 [RFC v2 00/15] Manager/Adapter transition to ObjectManager Mikel Astiz
2012-11-29 12:47 ` [RFC v2 01/15] cups: Remove unnecessary code Mikel Astiz
2012-11-29 12:47 ` Mikel Astiz [this message]
2012-11-30 12:28   ` [RFC v2 02/15] test: Add utility library for python scripts Anderson Lizardo
2012-11-29 12:47 ` [RFC v2 03/15] test: Avoid using DefaultAdapter() Mikel Astiz
2012-11-29 12:47 ` [RFC v2 04/15] test: Update monitor script to ObjectManager Mikel Astiz
2012-11-29 12:47 ` [RFC v2 05/15] test: Update test-manager " Mikel Astiz
2012-11-29 12:47 ` [RFC v2 06/15] test: Use ObjectManager instead of Adapters property Mikel Astiz
2012-11-29 12:47 ` [RFC v2 07/15] dbus: Remove org.bluez.Manager Mikel Astiz
2012-11-29 12:47 ` [RFC v2 08/15] test: Use ObjectManager instead of Devices property Mikel Astiz
2012-11-29 12:47 ` [RFC v2 09/15] test: Add helper function to find devices Mikel Astiz
2012-11-29 12:47 ` [RFC v2 10/15] adapter: Remove DeviceCreated/DeviceRemoved signals Mikel Astiz
2012-11-29 12:47 ` [RFC v2 11/15] adapter: Remove redundant Devices property Mikel Astiz
2012-11-29 12:47 ` [RFC v2 12/15] test: Avoid using Adapter.FindDevice() Mikel Astiz
2012-11-29 12:47 ` [RFC v2 13/15] adapter: Remove FindDevice method from D-Bus API Mikel Astiz
2012-11-29 12:47 ` [RFC v2 14/15] dbus: Rename to org.bluez.Device1 Mikel Astiz
2012-11-29 12:47 ` [RFC v2 15/15] dbus: Rename to org.bluez.Adapter1 Mikel Astiz
2012-11-29 18:12 ` [RFC v2 00/15] Manager/Adapter transition to ObjectManager Lucas De Marchi
2012-11-30 11:38   ` Mikel Astiz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354193256-30610-3-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox