<commit_before>from i3pystatus.core.command import run_through_shell
from i3pystatus.updates import Backend
from re import split


class Dnf(Backend):
    """
    Gets update count for RPM-based distributions with dnf.

    https://dnf.readthedocs.org/en/latest/command_ref.html#check-update-command
    """

    @property
    def updates(self):
        command = ["dnf", "check-update"]
        dnf = run_through_shell(command)

        update_count = 0
        if dnf.rc == 100:
            lines = dnf.out.splitlines()[2:]
            lines = [l for l in lines if len(split("\s{2,}", l.rstrip())) == 3]
            update_count = len(lines)
        return update_count<commit_msg>Now returns both the count and a notification body<commit_after>from i3pystatus.core.command import run_through_shell
from i3pystatus.updates import Backend
from re import split, sub


class Dnf(Backend):
    """
    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
    """

    @property
    def updates(self):
        command = ["dnf", "check-update"]
        dnf = run_through_shell(command)
        raw = dnf.out

        update_count = 0
        if dnf.rc == 100:
            lines = raw.splitlines()[2:]
            lines = [l for l in lines if len(split("\s{2,}", l.rstrip())) == 3]
            update_count = len(lines)
        notif_body = sub(r"(\S+)\s+(\S+)\s+\S+\s*\n", r"\1: \2\n", raw)
        return update_count, notif_body
{'fraction_non_alphanumeric': 0.12034208918753818, 'fraction_numerical': 0.012217470983506415, 'mean_word_length': 2.648106904231626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254058', 'n_tokens_mistral': 534, 'n_tokens_neox': 510, 'n_words': 138}