From 34163f4435a46984f6193c676928fe842f139362 Mon Sep 17 00:00:00 2001 From: Jonathan Cave Date: Thu, 20 Dec 2018 14:37:37 +0000 Subject: bluetooth: create bluetooth detect job --- bin/bt_list_adapters.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 bin/bt_list_adapters.py (limited to 'bin') diff --git a/bin/bt_list_adapters.py b/bin/bt_list_adapters.py new file mode 100755 index 0000000..e791442 --- /dev/null +++ b/bin/bt_list_adapters.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# +# This file is part of Checkbox. +# +# Copyright 2018 Canonical Ltd. +# +# Authors: +# Jonathan Cave +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . + +import os + + +def main(): + rfkill = '/sys/class/rfkill' + found_adatper = False + for rfdev in os.listdir(rfkill): + typef = os.path.join(rfkill, rfdev, 'type') + type = '' + with open(typef, 'r') as f: + type = f.read().strip() + if type != 'bluetooth': + continue + found_adatper = True + namef = os.path.join(rfkill, rfdev, 'name') + name = '' + with open(namef, 'r') as f: + name = f.read().strip() + print(rfdev, name) + if found_adatper == False: + raise SystemExit('No bluetooth adatpers registered with rfkill') + + +if __name__ == "__main__": + main() -- cgit v1.2.3