2016-12-11 12:42:49 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays update information per repository for pacman."
|
2017-01-05 04:55:14 +01:00
|
|
|
|
|
|
|
Requires the following executables:
|
|
|
|
* fakeroot
|
|
|
|
* pacman
|
2016-12-11 12:42:49 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2017-03-10 16:21:30 +01:00
|
|
|
import threading
|
|
|
|
|
2016-12-11 12:42:49 +01:00
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
2017-03-10 16:39:31 +01:00
|
|
|
#list of repositories.
|
2017-07-07 17:16:07 +02:00
|
|
|
#the last one should always be other
|
2017-03-10 16:39:31 +01:00
|
|
|
repos = ["core", "extra", "community", "multilib", "testing", "other"]
|
2017-03-10 13:41:59 +01:00
|
|
|
|
2017-03-10 16:21:30 +01:00
|
|
|
def get_pacman_info(widget, path):
|
|
|
|
try:
|
|
|
|
result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
count = len(repos)*[0]
|
|
|
|
|
|
|
|
for line in result.splitlines():
|
2017-03-10 18:48:34 +01:00
|
|
|
if line.startswith(("http", "rsync")):
|
2017-03-10 16:21:30 +01:00
|
|
|
for i in range(len(repos)-1):
|
|
|
|
if "/" + repos[i] + "/" in line:
|
|
|
|
count[i] += 1
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
result[-1] += 1
|
|
|
|
|
|
|
|
for i in range(len(repos)):
|
|
|
|
widget.set(repos[i], count[i])
|
|
|
|
|
|
|
|
|
2016-12-11 12:42:49 +01:00
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.updates)
|
|
|
|
)
|
|
|
|
self._count = 0
|
|
|
|
|
|
|
|
def updates(self, widget):
|
2017-10-13 17:06:18 +02:00
|
|
|
return '/'.join(map(lambda x: str(widget.get(x, 0)), repos))
|
2016-12-11 12:42:49 +01:00
|
|
|
|
|
|
|
def update(self, widgets):
|
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
if self._count == 0:
|
2017-10-13 17:06:18 +02:00
|
|
|
thread = threading.Thread(target=get_pacman_info, args=(widgets[0], path))
|
2017-03-10 16:21:30 +01:00
|
|
|
thread.start()
|
2017-10-13 17:09:09 +02:00
|
|
|
|
2016-12-11 12:42:49 +01:00
|
|
|
# TODO: improve this waiting mechanism a bit
|
|
|
|
self._count += 1
|
|
|
|
self._count = 0 if self._count > 300 else self._count
|
|
|
|
|
|
|
|
def state(self, widget):
|
2017-10-13 17:06:18 +02:00
|
|
|
weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1], 0), enumerate(repos)))
|
2017-03-10 17:23:52 +01:00
|
|
|
|
|
|
|
if weightedCount < 10:
|
|
|
|
return "good"
|
|
|
|
|
|
|
|
return self.threshold_state(weightedCount, 100, 150)
|
2016-12-11 12:42:49 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|