[modules/pacman] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-24 16:46:31 +02:00
parent 2586e4e78c
commit c1ce545bcd
2 changed files with 41 additions and 27 deletions

22
bin/pacman-updates Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/bash
if ! type -P fakeroot >/dev/null; then
error 'Cannot find the fakeroot binary.'
exit 1
fi
if [[ -z $CHECKUPDATES_DB ]]; then
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
fi
trap 'rm -f $CHECKUPDATES_DB/db.lck' INT TERM EXIT
DBPath="${DBPath:-/var/lib/pacman/}"
eval $(awk -F' *= *' '$1 ~ /DBPath/ { print $1 "=" $2 }' /etc/pacman.conf)
mkdir -p "$CHECKUPDATES_DB"
ln -s "${DBPath}/local" "$CHECKUPDATES_DB" &> /dev/null
fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> /dev/null
fakeroot pacman -Su -p --dbpath "$CHECKUPDATES_DB"
exit 0

View file

@ -13,23 +13,22 @@ Requires the following executables:
import os
import threading
import bumblebee.util
import bumblebee.input
import bumblebee.output
import bumblebee.engine
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):
try:
cmd = '{}/../../bin/pacman-updates'.format(path)
if not os.path.exists(cmd):
cmd = '/usr/share/bumblebee-status/bin/pacman-update'
result = bumblebee.util.execute(cmd)
except:
pass
result = util.cli.execute(cmd, ignore_errors=True)
count = len(repos)*[0]
@ -44,30 +43,23 @@ def get_pacman_info(widget, path):
for i in range(len(repos)):
widget.set(repos[i], count[i])
core.event.trigger('update', [ widget.module().id ], redraw_only=True)
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
class Module(core.module.Module):
@core.decorators.every(minutes=30)
def __init__(self, config):
super().__init__(config, core.widget.Widget(self.updates))
def updates(self, widget):
if bumblebee.util.asbool(self.parameter('sum')):
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, widgets):
def update(self):
path = os.path.dirname(os.path.abspath(__file__))
if self._count == 0:
thread = threading.Thread(target=get_pacman_info, args=(widgets[0], path))
thread = threading.Thread(target=get_pacman_info, args=(self.widget(), path))
thread.start()
# TODO: improve this waiting mechanism a bit
self._count += 1
self._count = 0 if self._count > 300 else self._count
def state(self, widget):
weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1], 0), enumerate(repos)))