2020-04-24 16:40:21 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays update information per repository for pacman.
|
|
|
|
|
|
|
|
Parameters:
|
2020-04-24 16:40:39 +02:00
|
|
|
* pacman.sum: If you prefere displaying updates with a single digit (defaults to 'False')
|
2020-04-24 16:40:21 +02:00
|
|
|
|
|
|
|
Requires the following executables:
|
|
|
|
* fakeroot
|
|
|
|
* pacman
|
|
|
|
"""
|
|
|
|
|
|
|
|
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-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-03 11:15:52 +02:00
|
|
|
cmd = "{}/../../bin/pacman-updates".format(path)
|
2020-04-24 16:46:31 +02:00
|
|
|
if not os.path.exists(cmd):
|
2020-05-03 11:15:52 +02:00
|
|
|
cmd = "/usr/share/bumblebee-status/bin/pacman-update"
|
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
|