From 2d12c083c9376c8e22878498570f7b05b1b73d50 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Mon, 13 Apr 2020 13:58:58 +0200 Subject: [PATCH] [modules] re-enable arch-update --- modules/contrib/arch-update.py | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 modules/contrib/arch-update.py diff --git a/modules/contrib/arch-update.py b/modules/contrib/arch-update.py new file mode 100644 index 0000000..f0bc70f --- /dev/null +++ b/modules/contrib/arch-update.py @@ -0,0 +1,51 @@ +"""Check updates to Arch Linux. + +Requires the following executable: + * checkupdates (from pacman-contrib) + +""" + + +import subprocess +import bumblebee.input +import bumblebee.output +import bumblebee.engine + + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + widget = bumblebee.output.Widget(full_text=self.utilization) + super(Module, self).__init__(engine, config, widget) + self.packages = self.check_updates() + + def check_updates(self): + p = subprocess.Popen( + "checkupdates", stdout=subprocess.PIPE, shell=True) + + p_status = p.wait() + + if p_status == 0: + (output, err) = p.communicate() + + output = output.decode('utf-8') + packages = output.split('\n') + packages.pop() + + return len(packages) + return 0 + + @property + def _format(self): + return self.parameter("format", "Update Arch: {}") + + def utilization(self, widget): + return self._format.format(self.packages) + + def hidden(self): + return self.check_updates() == 0 + + def update(self, widgets): + self.packages = self.check_updates() + + def state(self, widget): + return self.threshold_state(self.packages, 1, 100)