[modules/arch-update] Better handling of errors in checkupdates
see #624
This commit is contained in:
parent
a8f4d3f9c6
commit
85ac953111
1 changed files with 7 additions and 3 deletions
|
@ -20,26 +20,30 @@ class Module(core.module.Module):
|
||||||
def __init__(self, config, theme):
|
def __init__(self, config, theme):
|
||||||
super().__init__(config, theme, core.widget.Widget(self.utilization))
|
super().__init__(config, theme, core.widget.Widget(self.utilization))
|
||||||
self.__packages = 0
|
self.__packages = 0
|
||||||
|
self.__error = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __format(self):
|
def __format(self):
|
||||||
return self.parameter("format", "Update Arch: {}")
|
return self.parameter("format", "Update Arch: {}")
|
||||||
|
|
||||||
def utilization(self, widget):
|
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):
|
def hidden(self):
|
||||||
return self.__packages == 0
|
return self.__packages == 0 and not self.__error
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
result = util.cli.execute("checkupdates")
|
result = util.cli.execute("checkupdates")
|
||||||
self.__packages = len(result.split("\n")) - 1
|
self.__packages = len(result.split("\n")) - 1
|
||||||
|
self.__error = False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
self.__packages = -1
|
self.__error = True
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
|
if self.__error:
|
||||||
|
return "warning"
|
||||||
return self.threshold_state(self.__packages, 1, 100)
|
return self.threshold_state(self.__packages, 1, 100)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue