From 64c6a307c826c4a197dccb4748312cbc12c0461c Mon Sep 17 00:00:00 2001 From: Milos Miljanic Date: Thu, 24 Nov 2016 19:01:48 +0100 Subject: [PATCH] [modules] Show updates for pacman. --- bumblebee/bin/customupdates | 21 +++++++++++++ bumblebee/modules/pacman.py | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 bumblebee/bin/customupdates create mode 100644 bumblebee/modules/pacman.py diff --git a/bumblebee/bin/customupdates b/bumblebee/bin/customupdates new file mode 100755 index 0000000..3176c9d --- /dev/null +++ b/bumblebee/bin/customupdates @@ -0,0 +1,21 @@ +#!/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/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py new file mode 100644 index 0000000..c1399f9 --- /dev/null +++ b/bumblebee/modules/pacman.py @@ -0,0 +1,60 @@ +import bumblebee.module +import subprocess +import os + +def description(): + return "Displays available updates per repository for pacman." + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._count = 0 + + def widgets(self): + #path = os.path.dirname(os.path.abspath(__file__)) + path = os.path.realpath(__file__) + #path = "/home/pseudonick/bumblebee-status/bumblebee/" + if self._count == 0: + self._out = "?/?/?/?" + process = subprocess.Popen([path[:-9]+"../bin/customupdates"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + self._query, self._error = process.communicate() + + if not process.returncode == 0: + self._out = "?/?/?/?" + else: + self._community = 0 + self._core = 0 + self._extra = 0 + self._other = 0 + + for line in self._query.splitlines(): + if line.startswith(b'http'): + if b"community" in line: + self._community += 1 + continue + if b"core" in line: + self._core += 1; + continue + if b"extra" in line: + self._extra += 1 + continue + self._other += 1 + self._out = str(self._core)+"/"+str(self._extra)+"/"+str(self._community)+"/"+str(self._other) + + self._count += 1 + self._count = 0 if self._count > 300 else self._count + return bumblebee.output.Widget(self, "{}".format(self._out)) + + def sumUpdates(self): + return self._core + self._community + self._extra + self._other + + def critical(self, widget): + #return self._sumUpdates(self) + return self.sumUpdates() > 0 + + + + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4