diff options
| author | Ultrabug <ultrabug@gentoo.org> | 2015-03-02 11:30:09 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@gentoo.org> | 2015-03-02 11:30:09 +0100 |
| commit | cf646922b57e60cdd6dbc67b0d561228d0671197 (patch) | |
| tree | 0367ac934db02220908f2e3ef8745e26245024c9 | |
| parent | 8538fd563d21d4fa4611c8861794044c058ed158 (diff) | |
bluetooth module QA formatting
| -rw-r--r-- | py3status/modules/bluetooth.py | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py index eed7692..cd09945 100644 --- a/py3status/modules/bluetooth.py +++ b/py3status/modules/bluetooth.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python -# encoding: utf-8 - +# -*- coding: utf8 -*- """ -Module for displaying bluetooth status +This module displays bluetooth status. Requires: - hcitool @@ -13,49 +11,62 @@ Requires: import re import shlex + from subprocess import check_output from time import time -BTMAC_RE = re.compile(r"[0-9A-F:]{17}") +BTMAC_RE = re.compile(r'[0-9A-F:]{17}') + class Py3status: - # configuration parameters + """ + Confiuration parameters: + - format : format when there is a connected device + - format_no_conn : format when there is no connected device + - format_no_conn_prefix : prefix when there is no connected device + - format_prefix : prefix when there is a connected device + + Format of status string placeholders + {name} : device name + {mac} : device MAC address + """ + # available configuration parameters cache_timeout = 10 - color_good = None color_bad = None - format_prefix = "BT: " - # both {name} and {mac} are accepted - format = "{name}" - format_no_conn_prefix = "BT: " - format_no_conn = "OFF" + color_good = None + format = '{name}' + format_no_conn = 'OFF' + format_no_conn_prefix = 'BT: ' + format_prefix = 'BT: ' separator = '|' def bluetooth(self, i3s_output_list, i3s_config): - # The whole command: - # hcitool name `hcitool con | sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'` - - out = check_output(shlex.split("hcitool con")) - macs = re.findall(BTMAC_RE, out.decode("utf-8")) + """ + The whole command: + hcitool name `hcitool con | sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'` + """ + out = check_output(shlex.split('hcitool con')) + macs = re.findall(BTMAC_RE, out.decode('utf-8')) color = self.color_bad or i3s_config['color_bad'] if macs != []: data = [] for mac in macs: - out = check_output(shlex.split("hcitool name %s" % mac)) + out = check_output(shlex.split('hcitool name %s' % mac)) fmt_str = self.format.format( - name=out.strip().decode("utf-8"), + name=out.strip().decode('utf-8'), mac=mac ) data.append(fmt_str) - output = "{format_prefix}{data}".format( + output = '{format_prefix}{data}'.format( format_prefix=self.format_prefix, data=self.separator.join(data) ) color = self.color_good or i3s_config['color_good'] else: - output = "{format_prefix}{format}".format( + output = '{format_prefix}{format}'.format( format_prefix=self.format_no_conn_prefix, format=self.format_no_conn ) @@ -75,10 +86,9 @@ if __name__ == "__main__": from time import sleep x = Py3status() config = { - "color_good": "#00FF00", - "color_bad": "#FF0000", - } - + 'color_good': '#00FF00', + 'color_bad': '#FF0000', + } while True: print(x.bluetooth([], config)) sleep(1) |
