From feac48c21e390cbf4e2ecf3b3c7a12d89c1e3436 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 20:39:17 +0200 Subject: Ignore dbus exception. --- parrot_zik/bluetooth_paired_devices.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'parrot_zik/bluetooth_paired_devices.py') diff --git a/parrot_zik/bluetooth_paired_devices.py b/parrot_zik/bluetooth_paired_devices.py index f06286a..cec6d8e 100644 --- a/parrot_zik/bluetooth_paired_devices.py +++ b/parrot_zik/bluetooth_paired_devices.py @@ -1,3 +1,4 @@ +import dbus import sys import re import os @@ -17,16 +18,24 @@ def get_parrot_zik_mac(): p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}|' 'A0:14:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}') if sys.platform == "linux2": - bluetooth_on = int(os.popen('bluez-test-adapter powered').read()) - if bluetooth_on == 1: - out = os.popen("bluez-test-device list").read() - res = p.findall(out) - if len(res) > 0: - return res[0] - else: - raise DeviceNotConnected + try: + bluetooth_on = int(os.popen('bluez-test-adapter powered').read()) + except dbus.exceptions.DBusException: + pass else: - raise BluetoothIsNotOn + if bluetooth_on == 1: + try: + out = os.popen("bluez-test-device list").read() + except dbus.exceptions.DBusException: + pass + else: + res = p.findall(out) + if len(res) > 0: + return res[0] + else: + raise DeviceNotConnected + else: + raise BluetoothIsNotOn elif sys.platform == "darwin": fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb") plist = binplist.BinaryPlist(file_obj=fd) -- cgit v1.2.1