[modules/arch-update] Better handling of errors in checkupdates

see #624
This commit is contained in:
tobi-wan-kenobi 2020-05-09 10:22:26 +02:00
parent a8f4d3f9c6
commit 85ac953111

View file

@ -20,26 +20,30 @@ class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.utilization))
self.__packages = 0
self.__error = False
@property
def __format(self):
return self.parameter("format", "Update Arch: {}")
def utilization(self, widget):
return self.__format.format(self.__packages if self.__packages >= 0 else "n/a")
return self.__format.format(self.__packages)
def hidden(self):
return self.__packages == 0
return self.__packages == 0 and not self.__error
def update(self):
try:
result = util.cli.execute("checkupdates")
self.__packages = len(result.split("\n")) - 1
self.__error = False
except Exception as e:
logging.exception(e)
self.__packages = -1
self.__error = True
def state(self, widget):
if self.__error:
return "warning"
return self.threshold_state(self.__packages, 1, 100)