Now returns both the count and a notification body
This commit is contained in:
parent
616c68b0f0
commit
7fb0794f45
@ -1,11 +1,14 @@
|
|||||||
from i3pystatus.core.command import run_through_shell
|
from i3pystatus.core.command import run_through_shell
|
||||||
from i3pystatus.updates import Backend
|
from i3pystatus.updates import Backend
|
||||||
from re import split
|
from re import split, sub
|
||||||
|
|
||||||
|
|
||||||
class Dnf(Backend):
|
class Dnf(Backend):
|
||||||
"""
|
"""
|
||||||
Gets update count for RPM-based distributions with dnf.
|
Gets updates for RPM-based distributions with `dnf check-update`.
|
||||||
|
|
||||||
|
The notification body consists of the status line followed by the package
|
||||||
|
name and version for each update.
|
||||||
|
|
||||||
https://dnf.readthedocs.org/en/latest/command_ref.html#check-update-command
|
https://dnf.readthedocs.org/en/latest/command_ref.html#check-update-command
|
||||||
"""
|
"""
|
||||||
@ -14,12 +17,14 @@ class Dnf(Backend):
|
|||||||
def updates(self):
|
def updates(self):
|
||||||
command = ["dnf", "check-update"]
|
command = ["dnf", "check-update"]
|
||||||
dnf = run_through_shell(command)
|
dnf = run_through_shell(command)
|
||||||
|
raw = dnf.out
|
||||||
|
|
||||||
update_count = 0
|
update_count = 0
|
||||||
if dnf.rc == 100:
|
if dnf.rc == 100:
|
||||||
lines = dnf.out.splitlines()[2:]
|
lines = raw.splitlines()[2:]
|
||||||
lines = [l for l in lines if len(split("\s{2,}", l.rstrip())) == 3]
|
lines = [l for l in lines if len(split("\s{2,}", l.rstrip())) == 3]
|
||||||
update_count = len(lines)
|
update_count = len(lines)
|
||||||
return update_count
|
notif_body = sub(r"(\S+)\s+(\S+)\s+\S+\s*\n", r"\1: \2\n", raw)
|
||||||
|
return update_count, notif_body
|
||||||
|
|
||||||
Backend = Dnf
|
Backend = Dnf
|
||||||
|
Loading…
Reference in New Issue
Block a user