From 7d905742121169de5414ff348275659cdf33f29d Mon Sep 17 00:00:00 2001 From: Kenny Keslar Date: Wed, 2 Mar 2016 15:40:16 -0500 Subject: [PATCH 1/2] Pulseaudio - use execute helper & fix program check --- i3pystatus/pulseaudio/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/i3pystatus/pulseaudio/__init__.py b/i3pystatus/pulseaudio/__init__.py index dc1e920..09f9977 100644 --- a/i3pystatus/pulseaudio/__init__.py +++ b/i3pystatus/pulseaudio/__init__.py @@ -4,8 +4,8 @@ from i3pystatus.core.color import ColorRangeModule from i3pystatus.core.util import make_vertical_bar, make_bar from .pulse import * +from i3pystatus.core.command import execute from i3pystatus import Module -import subprocess class PulseAudio(Module, ColorRangeModule): @@ -80,7 +80,7 @@ class PulseAudio(Module, ColorRangeModule): self.colors = self.get_hex_color_range(self.color_muted, self.color_unmuted, 100) # Check that we have amixer for toggling mute/unmute and incrementing/decrementing volume - self.has_amixer = shutil.which('alsamixer') is not None + self.has_amixer = shutil.which('amixer') is not None def request_update(self, context): """Requests a sink info update (sink_info_cb is called)""" @@ -172,14 +172,14 @@ class PulseAudio(Module, ColorRangeModule): command += 'unmute' else: command += 'mute' - subprocess.run(command.split()) + execute(command) def increase_volume(self): if self.has_amixer: command = "amixer -q -D pulse sset Master %s%%+" % self.step - subprocess.run(command.split()) + execute(command) def decrease_volume(self): if self.has_amixer: command = "amixer -q -D pulse sset Master %s%%-" % self.step - subprocess.run(command.split()) + execute(command) From 693d2ebdb702be536cdc393f66384f0451966904 Mon Sep 17 00:00:00 2001 From: Kenny Keslar Date: Wed, 2 Mar 2016 15:57:57 -0500 Subject: [PATCH 2/2] Catch exceptions in button handlers --- i3pystatus/core/modules.py | 41 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index f60ac3e..952b221 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -94,25 +94,28 @@ class Module(SettingsBase): else: args = [] - our_method = is_method_of(cb, self) - if callable(cb) and not our_method: - self.__log_button_event(button, cb, args, "Python callback") - cb(*args) - elif our_method: - cb(self, *args) - elif hasattr(self, cb): - if cb is not "run": - # CommandEndpoint already calls run() after every - # callback to instantly update any changed state due - # to the callback's actions. - self.__log_button_event(button, cb, args, "Member callback") - getattr(self, cb)(*args) - else: - self.__log_button_event(button, cb, args, "External command") - if hasattr(self, "data"): - args = [arg.format(**self.data) for arg in args] - cb = cb.format(**self.data) - execute(cb + " " + " ".join(args), detach=True) + try: + our_method = is_method_of(cb, self) + if callable(cb) and not our_method: + self.__log_button_event(button, cb, args, "Python callback") + cb(*args) + elif our_method: + cb(self, *args) + elif hasattr(self, cb): + if cb is not "run": + # CommandEndpoint already calls run() after every + # callback to instantly update any changed state due + # to the callback's actions. + self.__log_button_event(button, cb, args, "Member callback") + getattr(self, cb)(*args) + else: + self.__log_button_event(button, cb, args, "External command") + if hasattr(self, "data"): + args = [arg.format(**self.data) for arg in args] + cb = cb.format(**self.data) + execute(cb + " " + " ".join(args), detach=True) + except Exception as e: + self.logger.critical("Exception while processing button callback: {!r}".format(e)) # Notify status handler try: