diff options
author | Mikel Astiz <mikel.astiz@bmw-carit.de> | 2012-12-05 13:51:29 +0100 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-12-05 16:39:26 +0200 |
commit | 6e5459128be74eed55307da4a8af99d7192100ad (patch) | |
tree | ddcc3d47d6d6f29522aa71a1d15a049a6b230003 /test/bluezutils.py | |
parent | e5fa4dd5e8a72642b68c45f1b07da0f55c4f19ab (diff) | |
download | bluez-6e5459128be74eed55307da4a8af99d7192100ad.tar.gz |
test: Add utility library for python scripts
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.
Diffstat (limited to 'test/bluezutils.py')
-rw-r--r-- | test/bluezutils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/bluezutils.py b/test/bluezutils.py new file mode 100644 index 000000000..0b8aec3f6 --- /dev/null +++ b/test/bluezutils.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 is None: + continue + if not pattern 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") |