<commit_before>"""Check updates to Arch Linux.

Requires the following executable:
    * checkupdates (from pacman-contrib)

contributed by `lucassouto <https://github.com/lucassouto>`_ - many thanks!
"""

import logging

import core.module
import core.widget
import core.decorators

import util.cli


class Module(core.module.Module):
    @core.decorators.every(minutes=60)
    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)

    def hidden(self):
        return self.__packages == 0 and not self.__error

    def update(self):
        self.__error = False
        code, result = util.cli.execute(
            "checkupdates", ignore_errors=True, return_exitcode=True
        )

        if code == 0:
            self.__packages = len(result.split("\n"))
        elif code == 2:
            self.__packages = 0
        else:
            self.__error = True
            logging.error("checkupdates exited with {}: {}".format(code, result))

    def state(self, widget):
        if self.__error:
            return "warning"
        return self.threshold_state(self.__packages, 1, 100)


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
<commit_msg>[modules/arch-update] perform update in background<commit_after>"""Check updates to Arch Linux.

Requires the following executable:
    * checkupdates (from pacman-contrib)

contributed by `lucassouto <https://github.com/lucassouto>`_ - many thanks!
"""

import logging

import core.module
import core.widget
import core.decorators

import util.cli


class Module(core.module.Module):
    @core.decorators.every(minutes=60)
    def __init__(self, config, theme):
        super().__init__(config, theme, core.widget.Widget(self.utilization))
        self.background = True
        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)

    def hidden(self):
        return self.__packages == 0 and not self.__error

    def update(self):
        self.__error = False
        code, result = util.cli.execute(
            "checkupdates", ignore_errors=True, return_exitcode=True
        )

        if code == 0:
            self.__packages = len(result.split("\n"))
        elif code == 2:
            self.__packages = 0
        else:
            self.__error = True
            logging.error("checkupdates exited with {}: {}".format(code, result))

    def state(self, widget):
        if self.__error:
            return "warning"
        return self.threshold_state(self.__packages, 1, 100)


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

{'fraction_non_alphanumeric': 0.11163101604278075, 'fraction_numerical': 0.009358288770053475, 'mean_word_length': 2.67239263803681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4221667', 'n_tokens_mistral': 890, 'n_tokens_neox': 836, 'n_words': 218}