mirror of
https://github.com/liberatedsystems/Sideband_CE.git
synced 2024-09-03 04:13:27 +02:00
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
'''
|
|
Module of MacOS API for plyer.bluetooth.
|
|
'''
|
|
|
|
from subprocess import Popen, PIPE
|
|
from plyer.facades import Bluetooth
|
|
from plyer.utils import whereis_exe
|
|
|
|
from os import environ
|
|
|
|
|
|
class OSXBluetooth(Bluetooth):
|
|
'''
|
|
Implementation of MacOS bluetooth API.
|
|
'''
|
|
|
|
def _get_info(self):
|
|
old_lang = environ.get('LANG')
|
|
environ['LANG'] = 'C'
|
|
|
|
sys_profiler_process = Popen(
|
|
["system_profiler", "SPBluetoothDataType"],
|
|
stdout=PIPE
|
|
)
|
|
|
|
stdout = sys_profiler_process.communicate()[0].decode('utf-8')
|
|
output = stdout.splitlines()
|
|
|
|
lines = []
|
|
for line in output:
|
|
if 'Bluetooth Power' not in line:
|
|
continue
|
|
lines.append(line)
|
|
|
|
if old_lang is None:
|
|
environ.pop('LANG')
|
|
else:
|
|
environ['LANG'] = old_lang
|
|
|
|
if output and len(lines) == 1:
|
|
return lines[0].split()[2]
|
|
else:
|
|
return None
|
|
|
|
|
|
def instance():
|
|
'''
|
|
Instance for facade proxy.
|
|
'''
|
|
import sys
|
|
if whereis_exe('system_profiler'):
|
|
return OSXBluetooth()
|
|
sys.stderr.write("system_profiler not found.")
|
|
return Bluetooth()
|