2020-04-24 16:22:10 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays DNF package update information (<security>/<bugfixes>/<enhancements>/<other>)
|
|
|
|
|
|
|
|
Requires the following executable:
|
|
|
|
* dnf
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2020-04-24 16:27:14 +02:00
|
|
|
import core.event
|
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.decorators
|
|
|
|
|
|
|
|
import util.cli
|
2020-04-24 16:22:10 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-24 16:27:14 +02:00
|
|
|
class Module(core.module.Module):
|
|
|
|
@core.decorators.every(minutes=30)
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.updates))
|
2020-04-24 16:22:10 +02:00
|
|
|
|
2020-08-27 20:06:33 +02:00
|
|
|
self.background = True
|
|
|
|
|
2020-04-24 16:22:10 +02:00
|
|
|
def updates(self, widget):
|
|
|
|
result = []
|
2020-05-03 11:15:52 +02:00
|
|
|
for t in ["security", "bugfixes", "enhancements", "other"]:
|
2020-04-24 16:22:10 +02:00
|
|
|
result.append(str(widget.get(t, 0)))
|
2020-05-03 11:15:52 +02:00
|
|
|
return "/".join(result)
|
2020-04-24 16:22:10 +02:00
|
|
|
|
2020-04-24 16:27:14 +02:00
|
|
|
def update(self):
|
2020-08-28 14:03:34 +02:00
|
|
|
widget = self.widget()
|
2020-08-27 20:06:33 +02:00
|
|
|
res = util.cli.execute("dnf updateinfo", ignore_errors=True)
|
|
|
|
|
|
|
|
security = 0
|
|
|
|
bugfixes = 0
|
|
|
|
enhancements = 0
|
|
|
|
other = 0
|
|
|
|
for line in res.split("\n"):
|
|
|
|
if not line.startswith(" "):
|
|
|
|
continue
|
|
|
|
elif "ecurity" in line:
|
|
|
|
for s in line.split():
|
|
|
|
if s.isdigit():
|
|
|
|
security += int(s)
|
|
|
|
elif "ugfix" in line:
|
|
|
|
for s in line.split():
|
|
|
|
if s.isdigit():
|
|
|
|
bugfixes += int(s)
|
|
|
|
elif "hancement" in line:
|
|
|
|
for s in line.split():
|
|
|
|
if s.isdigit():
|
|
|
|
enhancements += int(s)
|
|
|
|
else:
|
|
|
|
for s in line.split():
|
|
|
|
if s.isdigit():
|
|
|
|
other += int(s)
|
|
|
|
|
|
|
|
widget.set("security", security)
|
|
|
|
widget.set("bugfixes", bugfixes)
|
|
|
|
widget.set("enhancements", enhancements)
|
|
|
|
widget.set("other", other)
|
|
|
|
|
2020-04-24 16:22:10 +02:00
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
cnt = 0
|
2020-05-03 11:15:52 +02:00
|
|
|
for t in ["security", "bugfixes", "enhancements", "other"]:
|
2020-04-24 16:22:10 +02:00
|
|
|
cnt += widget.get(t, 0)
|
|
|
|
if cnt == 0:
|
2020-05-03 11:15:52 +02:00
|
|
|
return "good"
|
|
|
|
if cnt > 50 or widget.get("security", 0) > 0:
|
|
|
|
return "critical"
|
|
|
|
|
2020-04-24 16:22:10 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|