From eb1c28b09b79479a9cfc7bd475e6c5876541f8c3 Mon Sep 17 00:00:00 2001 From: JezerM Date: Sun, 19 Dec 2021 18:51:59 -0600 Subject: [PATCH] Battery bugfix --- web-greeter/utils/battery.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web-greeter/utils/battery.py b/web-greeter/utils/battery.py index ece7242..255dd2f 100644 --- a/web-greeter/utils/battery.py +++ b/web-greeter/utils/battery.py @@ -49,7 +49,8 @@ class Battery: capacity = 0, )) else: - self.ac = re.match(r"A\w+", line).group() or self.ac + match = re.match(r"A\w+", line) + self.ac = match.group() if match else self.ac # Based on "bat" widget from "lain" awesome-wm library # * (c) 2013, Luca CPZ @@ -106,7 +107,7 @@ class Battery: sum_charge_full = sum_charge_full + charge_full sum_charge_design = sum_charge_design + charge_design - self.capacity = math.floor(min(100, sum_charge_full / sum_charge_design * 100)) + self.capacity = math.floor(min(100, sum_charge_full / (sum_charge_design or 1) * 100)) self.status = len(self._batteries) > 0 and self._batteries[0]["status"] or "N/A" for i in range(len(self._batteries)): @@ -189,6 +190,7 @@ def acpi_listen(callback, onerror): awky = subprocess.Popen(shlex.split("grep --line-buffered -E 'battery|ac_adapter'"), stdout=subprocess.PIPE, stdin=main.stdout, text=True) while True: + if (awky.stdout == None): continue output = awky.stdout.readline() if output == "" and awky.poll() != None: break @@ -209,6 +211,7 @@ def scandir_line(path, callback): main = subprocess.Popen(shlex.split("ls -1 {}".format(path)), stdout=subprocess.PIPE, text=True) while True: + if (main.stdout == None): continue line = main.stdout.readline() if line == "" and main.poll() != None: break