From dd6b13265de166a994b0c8e19b4ea5cca4454c9e Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 11 Dec 2016 12:42:49 +0100 Subject: [PATCH] [modules/pacman] Re-enable pacman update information see #23 --- bin/pacman-updates | 22 ++++++++++++++ bin/toggle-display.sh | 12 ++++++++ bumblebee/modules/pacman.py | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100755 bin/pacman-updates create mode 100755 bin/toggle-display.sh create mode 100644 bumblebee/modules/pacman.py 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/bin/toggle-display.sh b/bin/toggle-display.sh new file mode 100755 index 0000000..bd13a29 --- /dev/null +++ b/bin/toggle-display.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +echo $(dirname $(readlink -f "$0")) + +i3bar_update=$(dirname $(readlink -f "$0"))/load-i3-bars.sh + +xrandr "$@" + +if [ -f $i3bar_update ]; then + sleep 1 + $i3bar_update +fi diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py new file mode 100644 index 0000000..da3e66f --- /dev/null +++ b/bumblebee/modules/pacman.py @@ -0,0 +1,60 @@ +# pylint: disable=C0111,R0903 + +"""Displays update information per repository for pacman." +""" + +import os +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +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 + self._out = "" + + def updates(self, widget): + return self._out + + def update(self, widgets): + path = os.path.dirname(os.path.abspath(__file__)) + if self._count == 0: + self._out = "?/?/?/?" + try: + result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path)) + self._community = 0 + self._core = 0 + self._extra = 0 + self._other = 0 + + for line in result.splitlines(): + if line.startswith("http"): + if "community" in line: + self._community += 1 + continue + if "core" in line: + self._core += 1; + continue + if "extra" in line: + self._extra += 1 + continue + self._other += 1 + self._out = str(self._core)+"/"+str(self._extra)+"/"+str(self._community)+"/"+str(self._other) + except RuntimeError: + self._out = "?/?/?/?" + + # TODO: improve this waiting mechanism a bit + self._count += 1 + self._count = 0 if self._count > 300 else self._count + + def sumUpdates(self): + return self._core + self._community + self._extra + self._other + + def state(self, widget): + if self.sumUpdates() > 0: + return "critical" + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4