[core] restructure to allow PIP packaging
OK - so I have to admit I *hate* the fact that PIP seems to require a subdirectory named like the library. But since the PIP package is something really nifty to have (thanks to @tony again!!!), I updated the codebase to hopefully conform with what PIP expects. Testruns so far look promising...
This commit is contained in:
parent
1d25be2059
commit
320827d577
146 changed files with 2509 additions and 2 deletions
78
bumblebee_status/modules/contrib/pacman.py
Normal file
78
bumblebee_status/modules/contrib/pacman.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays update information per repository for pacman.
|
||||
|
||||
Parameters:
|
||||
* pacman.sum: If you prefere displaying updates with a single digit (defaults to 'False')
|
||||
|
||||
Requires the following executables:
|
||||
* fakeroot
|
||||
* pacman
|
||||
|
||||
contributed by `Pseudonick47 <https://github.com/Pseudonick47>`_ - many thanks!
|
||||
"""
|
||||
|
||||
import os
|
||||
import threading
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
import core.decorators
|
||||
|
||||
import util.cli
|
||||
import util.format
|
||||
|
||||
# list of repositories.
|
||||
# the last one should always be other
|
||||
repos = ["core", "extra", "community", "multilib", "testing", "other"]
|
||||
|
||||
|
||||
def get_pacman_info(widget, path):
|
||||
cmd = "{}/../../bin/pacman-updates".format(path)
|
||||
if not os.path.exists(cmd):
|
||||
cmd = "/usr/share/bumblebee-status/bin/pacman-update"
|
||||
result = util.cli.execute(cmd, ignore_errors=True)
|
||||
|
||||
count = len(repos) * [0]
|
||||
|
||||
for line in result.splitlines():
|
||||
if line.startswith(("http", "rsync")):
|
||||
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])
|
||||
core.event.trigger("update", [widget.module.id], redraw_only=True)
|
||||
|
||||
|
||||
class Module(core.module.Module):
|
||||
@core.decorators.every(minutes=30)
|
||||
def __init__(self, config, theme):
|
||||
super().__init__(config, theme, core.widget.Widget(self.updates))
|
||||
|
||||
def updates(self, widget):
|
||||
if util.format.asbool(self.parameter("sum")):
|
||||
return str(sum(map(lambda x: widget.get(x, 0), repos)))
|
||||
return "/".join(map(lambda x: str(widget.get(x, 0)), repos))
|
||||
|
||||
def update(self):
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
thread = threading.Thread(target=get_pacman_info, args=(self.widget(), path))
|
||||
thread.start()
|
||||
|
||||
def state(self, widget):
|
||||
weightedCount = sum(
|
||||
map(lambda x: (len(repos) - x[0]) * widget.get(x[1], 0), enumerate(repos))
|
||||
)
|
||||
|
||||
if weightedCount < 10:
|
||||
return "good"
|
||||
|
||||
return self.threshold_state(weightedCount, 100, 150)
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue