summaryrefslogtreecommitdiffstats
path: root/py3status/modules/bluetooth.py
diff options
context:
space:
mode:
authorJ.M. Dana <jmdana@gmail.com>2015-02-24 21:38:44 +0000
committerJ.M. Dana <jmdana@gmail.com>2015-02-24 21:38:44 +0000
commit602b99f314512552861c7d6f35fe46a5f4776f8e (patch)
tree3b5031af34f20b1575aeb5172fcdf9271e912281 /py3status/modules/bluetooth.py
parent98d149f5c424bff4c03bdd2c9abe7f97d4660555 (diff)
sed dependency removed by using Python regular expressions
Diffstat (limited to 'py3status/modules/bluetooth.py')
-rw-r--r--py3status/modules/bluetooth.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py
index ee33b09..3585c4d 100644
--- a/py3status/modules/bluetooth.py
+++ b/py3status/modules/bluetooth.py
@@ -6,16 +6,18 @@ Module for displaying bluetooth status
Requires:
- hcitool
- - sed
@author jmdana <https://github.com/jmdana>
@license GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt>
"""
+import re
import shlex
-import subprocess
+from subprocess import check_output
from time import time
+BTMAC_RE = re.compile(r"[0-9A-F:]{17}")
+
class Py3status:
# configuration parameters
cache_timeout = 10
@@ -26,22 +28,16 @@ class Py3status:
# The whole command:
# hcitool name `hcitool con | sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'`
- cmd1 = shlex.split("hcitool con")
- cmd2 = shlex.split("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"))
output = "BT: "
color = self.color_bad or i3s_config['color_bad']
- p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
- p2 = subprocess.Popen(cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
-
- macs = p2.communicate()[0].strip().decode("utf-8").split()
-
if macs != []:
names = []
for mac in macs:
- cmd3 = shlex.split("hcitool name %s" % mac)
- p3 = subprocess.Popen(cmd3, stdout=subprocess.PIPE)
- names.append(p3.communicate()[0].strip().decode("utf-8"))
+ out = check_output(shlex.split("hcitool name %s" % mac))
+ names.append(out.strip().decode("utf-8"))
output += "|".join(names)