2020-04-24 16:40:21 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays update information per repository for pacman.
|
|
|
|
|
|
|
|
Parameters:
|
2022-07-21 08:07:33 +02:00
|
|
|
* pacman.sum: If you prefer displaying updates with a single digit (defaults to 'False')
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
Requires the following executables:
|
|
|
|
* fakeroot
|
|
|
|
* pacman
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
contributed by `Pseudonick47 <https://github.com/Pseudonick47>`_ - many thanks!
|
2020-04-24 16:40:21 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import threading
|
|
|
|
|
2020-04-24 16:46:31 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.decorators
|
|
|
|
|
|
|
|
import util.cli
|
|
|
|
import util.format
|
2020-04-24 16:40:21 +02:00
|
|
|
|
2020-05-10 12:52:20 +02:00
|
|
|
from bumblebee_status.discover import utility
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
# list of repositories.
|
|
|
|
# the last one should always be other
|
|
|
|
repos = ["core", "extra", "community", "multilib", "testing", "other"]
|
|
|
|
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
def get_pacman_info(widget, path):
|
2020-05-10 12:52:20 +02:00
|
|
|
cmd = utility("pacman-updates")
|
2020-04-24 16:46:31 +02:00
|
|
|
result = util.cli.execute(cmd, ignore_errors=True)
|
2020-04-24 16:40:21 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
count = len(repos) * [0]
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
for line in result.splitlines():
|
2020-05-03 11:15:52 +02:00
|
|
|
if line.startswith(("http", "rsync")):
|
|
|
|
for i in range(len(repos) - 1):
|
|
|
|
if "/" + repos[i] + "/" in line:
|
2020-04-24 16:40:21 +02:00
|
|
|
count[i] += 1
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
result[-1] += 1
|
|
|
|
|
|
|
|
for i in range(len(repos)):
|
|
|
|
widget.set(repos[i], count[i])
|
2020-05-03 11:15:52 +02:00
|
|
|
core.event.trigger("update", [widget.module.id], redraw_only=True)
|
|
|
|
|
2020-04-24 16:40:21 +02:00
|
|
|
|
2020-04-24 16:46:31 +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:40:21 +02:00
|
|
|
|
|
|
|
def updates(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
if util.format.asbool(self.parameter("sum")):
|
2020-04-24 16:40:21 +02:00
|
|
|
return str(sum(map(lambda x: widget.get(x, 0), repos)))
|
2020-05-03 11:15:52 +02:00
|
|
|
return "/".join(map(lambda x: str(widget.get(x, 0)), repos))
|
2020-04-24 16:40:21 +02:00
|
|
|
|
2020-04-24 16:46:31 +02:00
|
|
|
def update(self):
|
2020-04-24 16:40:21 +02:00
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
2020-04-24 16:46:31 +02:00
|
|
|
thread = threading.Thread(target=get_pacman_info, args=(self.widget(), path))
|
|
|
|
thread.start()
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
def state(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
weightedCount = sum(
|
|
|
|
map(lambda x: (len(repos) - x[0]) * widget.get(x[1], 0), enumerate(repos))
|
|
|
|
)
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
if weightedCount < 10:
|
2020-05-03 11:15:52 +02:00
|
|
|
return "good"
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
return self.threshold_state(weightedCount, 100, 150)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-24 16:40:21 +02:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|