[modules/pacman] Update to latest API
This commit is contained in:
parent
2586e4e78c
commit
c1ce545bcd
2 changed files with 41 additions and 27 deletions
22
bin/pacman-updates
Executable file
22
bin/pacman-updates
Executable 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
|
|
@ -13,23 +13,22 @@ Requires the following executables:
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import bumblebee.util
|
import core.module
|
||||||
import bumblebee.input
|
import core.widget
|
||||||
import bumblebee.output
|
import core.decorators
|
||||||
import bumblebee.engine
|
|
||||||
|
import util.cli
|
||||||
|
import util.format
|
||||||
|
|
||||||
#list of repositories.
|
#list of repositories.
|
||||||
#the last one should always be other
|
#the last one should always be other
|
||||||
repos = ['core', 'extra', 'community', 'multilib', 'testing', 'other']
|
repos = ['core', 'extra', 'community', 'multilib', 'testing', 'other']
|
||||||
|
|
||||||
def get_pacman_info(widget, path):
|
def get_pacman_info(widget, path):
|
||||||
try:
|
|
||||||
cmd = '{}/../../bin/pacman-updates'.format(path)
|
cmd = '{}/../../bin/pacman-updates'.format(path)
|
||||||
if not os.path.exists(cmd):
|
if not os.path.exists(cmd):
|
||||||
cmd = '/usr/share/bumblebee-status/bin/pacman-update'
|
cmd = '/usr/share/bumblebee-status/bin/pacman-update'
|
||||||
result = bumblebee.util.execute(cmd)
|
result = util.cli.execute(cmd, ignore_errors=True)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
count = len(repos)*[0]
|
count = len(repos)*[0]
|
||||||
|
|
||||||
|
@ -44,30 +43,23 @@ def get_pacman_info(widget, path):
|
||||||
|
|
||||||
for i in range(len(repos)):
|
for i in range(len(repos)):
|
||||||
widget.set(repos[i], count[i])
|
widget.set(repos[i], count[i])
|
||||||
|
core.event.trigger('update', [ widget.module().id ], redraw_only=True)
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
class Module(bumblebee.engine.Module):
|
@core.decorators.every(minutes=30)
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config):
|
||||||
super(Module, self).__init__(engine, config,
|
super().__init__(config, core.widget.Widget(self.updates))
|
||||||
bumblebee.output.Widget(full_text=self.updates)
|
|
||||||
)
|
|
||||||
self._count = 0
|
|
||||||
|
|
||||||
def updates(self, widget):
|
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 str(sum(map(lambda x: widget.get(x, 0), repos)))
|
||||||
return '/'.join(map(lambda x: str(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__))
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
if self._count == 0:
|
thread = threading.Thread(target=get_pacman_info, args=(self.widget(), path))
|
||||||
thread = threading.Thread(target=get_pacman_info, args=(widgets[0], path))
|
|
||||||
thread.start()
|
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):
|
def state(self, widget):
|
||||||
weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1], 0), enumerate(repos)))
|
weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1], 0), enumerate(repos)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue