From f236c24b92fb61d0c47580138942aee49f6201d1 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 11 Jan 2018 20:22:21 +0100 Subject: [PATCH] [modules/battery] Fix syntax error see #221 --- bumblebee/engine.py | 8 +++++++- bumblebee/modules/battery.py | 5 +++-- bumblebee/modules/spacer.py | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bumblebee/engine.py b/bumblebee/engine.py index df5b0da..9f31e06 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -40,6 +40,7 @@ class Module(object): self.id = self.name self._next = int(time.time()) self._default_interval = 0 + self.success = True self._configFile = None for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]: @@ -80,7 +81,12 @@ class Module(object): def update_wrapper(self, widgets): if self._next > int(time.time()): return - self.update(self._widgets) + try: + self.update(self._widgets) + self.success = True + except Exception as e: + log.error("failed to update module {}: {}".format(self.name, str(e))) + self.success = False self._next += int(self.parameter("interval", self._default_interval))*60 def interval(self, intvl): diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 57a12cc..5367d5f 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -105,8 +105,9 @@ class Module(bumblebee.engine.Module): state.append("AC") else: charge = "" - with open("{}/status".format(widget.name)) as f: - charge = f.read().strip() + try: + with open("{}/status".format(widget.name)) as f: + charge = f.read().strip() except IOError: pass if charge == "Discharging": diff --git a/bumblebee/modules/spacer.py b/bumblebee/modules/spacer.py index b89c233..adabcff 100644 --- a/bumblebee/modules/spacer.py +++ b/bumblebee/modules/spacer.py @@ -17,6 +17,9 @@ class Module(bumblebee.engine.Module): ) self._text = self.parameter("text", "") + def update(self, widgets): + raise Exception("test") + def text(self, widget): return self._text