diff --git a/bin/pacman-updates b/bin/pacman-updates new file mode 100755 index 0000000..baf0b93 --- /dev/null +++ b/bin/pacman-updates @@ -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 diff --git a/modules/contrib/pacman.py b/modules/contrib/pacman.py index a252942..10c22c8 100644 --- a/modules/contrib/pacman.py +++ b/modules/contrib/pacman.py @@ -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 + 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] @@ -44,29 +43,22 @@ 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.start() - - # TODO: improve this waiting mechanism a bit - self._count += 1 - self._count = 0 if self._count > 300 else self._count + 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)))