From 44dcd4e9a5b717d1791e3ba989f180c67b914aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BD=D0=B0?= Date: Fri, 13 Dec 2013 02:46:17 +0600 Subject: Parrot Zik mac address search moved to separate file; Initial mac os x support --- BluetoothPairedDevices.py | 40 ++++++++++++++++++++++++++++++++++++++++ ParrotZikTray | 27 ++------------------------- 2 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 BluetoothPairedDevices.py diff --git a/BluetoothPairedDevices.py b/BluetoothPairedDevices.py new file mode 100644 index 0000000..d167068 --- /dev/null +++ b/BluetoothPairedDevices.py @@ -0,0 +1,40 @@ +#!/usr/bin/python + +import sys +import re + + +def ParrotZikMac(): + 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}') + if sys.platform == "linux2": + out = os.popen("bluez-test-device list").read() + res = p.findall(out) + if len(res)>0: + return res[0] + + elif sys.platform == "darwin": + fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb") + plist = binplist.BinaryPlist(file_obj=fd) + parsed_plist = plist.Parse() + for mac in parsed_plist['PairedDevices']: + if p.match(mac.replace("-",":")): + return mac.replace("-",":") + + elif sys.platform == "win32": + aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) + aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices') + for i in range(10): + try: + asubkey_name=_winreg.EnumKey(aKey,i) + mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2)) + res = self.p.findall(mac) + if len(res)>0: + return res[0] + + except EnvironmentError: + pass + +if sys.platform == "darwin": + from binplist import binplist +elif sys.platform == "win32": + import _winreg \ No newline at end of file diff --git a/ParrotZikTray b/ParrotZikTray index 571a76e..05285ef 100755 --- a/ParrotZikTray +++ b/ParrotZikTray @@ -5,6 +5,7 @@ import gtk import re import os import ParrotZik +import BluetoothPairedDevices UPDATE_FREQUENCY = 30 # seconds @@ -99,30 +100,6 @@ class ParrotZikIndicator: self.quit_item.show() self.menu.append(self.quit_item) - def ParrotZikMac(self): - if sys.platform == "linux2": - out = os.popen("bluez-test-device list").read() - res = self.p.findall(out) - if len(res)>0: - return res[0] - else: - return '' - else: - import _winreg - aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) - aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices') - for i in range(10): - try: - asubkey_name=_winreg.EnumKey(aKey,i) - mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2)) - res = self.p.findall(mac) - if len(res)>0: - return res[0] - - except EnvironmentError: - break - - def EstablishConnection(self): if self.connected: if not self.parrot.sock: @@ -131,7 +108,7 @@ class ParrotZikIndicator: else: print "Connection already established" else: - mac=self.ParrotZikMac() + mac=BluetoothPairedDevices.ParrotZikMac() if mac: self.parrot = ParrotZik.ParrotZik(mac) if not self.parrot.sock: -- cgit v1.2.1