aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik
diff options
context:
space:
mode:
authorEsteban Sánchez <esteban.sanchez@gmail.com>2015-07-03 12:07:31 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-07-03 13:40:37 +0200
commit0973bb1a2f8e46d7dffe67063f0d1415b3397619 (patch)
tree885e40b6d635c28d971e92ca7011cca0c13a2fb7 /parrot_zik
parentb7e96b1e6a73c84aa6e051d8c20d03e4d3a224b9 (diff)
downloadpyParrotZikTCP-0973bb1a2f8e46d7dffe67063f0d1415b3397619.tar.xz
pyParrotZikTCP-0973bb1a2f8e46d7dffe67063f0d1415b3397619.zip
Use other method to get bluetooth devices list in linux
Diffstat (limited to 'parrot_zik')
-rw-r--r--parrot_zik/bluetooth_paired_devices.py42
1 files changed, 38 insertions, 4 deletions
diff --git a/parrot_zik/bluetooth_paired_devices.py b/parrot_zik/bluetooth_paired_devices.py
index e518161..8eba2ce 100644
--- a/parrot_zik/bluetooth_paired_devices.py
+++ b/parrot_zik/bluetooth_paired_devices.py
@@ -1,7 +1,7 @@
import dbus
import sys
import re
-import os
+from subprocess import Popen, PIPE, STDOUT
from .resource_manager import GenericResourceManager
@@ -17,15 +17,28 @@ else:
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}')
-def get_parrot_zik_mac_linux():
+
+def get_parrot_zik_mac_linux_using_bluez_test():
try:
- bluetooth_on = int(os.popen('bluez-test-adapter powered').read())
+ pipe = Popen(
+ ['bluez-test-adapter', 'powered'],
+ stdout=PIPE,
+ stdin=PIPE,
+ stderr=STDOUT
+ )
+ bluetooth_on = int(pipe.communicate())
except dbus.exceptions.DBusException:
pass
else:
if bluetooth_on == 1:
try:
- out = os.popen("bluez-test-device list").read()
+ pipe = Popen(
+ ['bluez-test-device', 'list'],
+ stdout=PIPE,
+ stdin=PIPE,
+ stderr=STDOUT
+ )
+ out = pipe.communicate()
except dbus.exceptions.DBusException:
pass
else:
@@ -38,6 +51,27 @@ def get_parrot_zik_mac_linux():
raise BluetoothIsNotOn
+def get_parrot_zik_mac_linux_using_bluetoothcmd():
+ pipe = Popen(['bluetoothctl'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
+ res = pipe.communicate("exit")
+ if len(res) > 0 and res[0]:
+ match = p.search(res[0])
+ if match:
+ return match.group(0)
+
+ raise DeviceNotConnected
+
+
+def get_parrot_zik_mac_linux():
+ try:
+ get_parrot_zik_mac_linux_using_bluez_test()
+ except OSError as e:
+ if e.errno == 2:
+ # File not found, probably it means that bluez utils are not
+ # installed
+ return get_parrot_zik_mac_linux_using_bluetoothcmd()
+
+
def get_parrot_zik_mac_darwin():
fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb")
plist = binplist.BinaryPlist(file_obj=fd)