aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik/bluetooth_paired_devices.py
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 20:39:17 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 20:44:20 +0200
commitfeac48c21e390cbf4e2ecf3b3c7a12d89c1e3436 (patch)
tree3df5535f14c96eaa5ae333a9fdee976ea95a8531 /parrot_zik/bluetooth_paired_devices.py
parent48a0498d56e54e01b9eed06af00b5ba127fe9134 (diff)
downloadpyParrotZikTCP-feac48c21e390cbf4e2ecf3b3c7a12d89c1e3436.tar.xz
pyParrotZikTCP-feac48c21e390cbf4e2ecf3b3c7a12d89c1e3436.zip
Ignore dbus exception.
Diffstat (limited to 'parrot_zik/bluetooth_paired_devices.py')
-rw-r--r--parrot_zik/bluetooth_paired_devices.py27
1 files changed, 18 insertions, 9 deletions
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)