[modules/apt] Change modules to use aptitude instead apt notifier

This commit is contained in:
Piotr Piórkowski 2020-01-02 14:20:58 +01:00
parent 25bed762fc
commit b8c1e1f162
2 changed files with 26 additions and 21 deletions

View file

@ -2,7 +2,7 @@
|Name |Description |
|-----|------------|
|amixer |get volume level<br><br> |
|apt |Displays APT package update information (<toupgrade>/<security>)<br>Requires the following debian packages:<br> * update-notifier-common<br><br> |
|apt |Displays APT package update information (<toupgrade>/<toremove>)<br>Requires the following debian packages:<br> * aptitude<br><br> * python-parse<br><br> |
|arch-update |Check updates to Arch Linux.<br> |
|battery-upower |Displays battery status, remaining percentage and charging information.<br><br>Parameters:<br> * battery-upower.warning : Warning threshold in % of remaining charge (defaults to 20)<br> * battery-upower.critical : Critical threshold in % of remaining charge (defaults to 10)<br> * battery-upower.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged<br> |
|battery |Displays battery status, remaining percentage and charging information.<br><br>Parameters:<br> * battery.device : Comma-separated list of battery devices to read information from (defaults to auto for auto-detection)<br> * battery.warning : Warning threshold in % of remaining charge (defaults to 20)<br> * battery.critical : Critical threshold in % of remaining charge (defaults to 10)<br> * battery.showdevice : If set to "true", add the device name to the widget (defaults to False)<br> * battery.decorate : If set to "false", hides additional icons (charging, etc.) (defaults to True)<br> |

View file

@ -1,19 +1,30 @@
# pylint: disable=C0111,R0903
"""Displays APT package update information (<toupgrade>/<security>)
"""Displays APT package update information (<to upgrade>/<to remove >)
Requires the following debian packages:
* update-notifier-common
* python-parse
* aptitude
"""
import threading
from parse import *
import bumblebee.util
import bumblebee.input
import bumblebee.output
import bumblebee.engine
APT_CHECK_PATH = "/usr/lib/update-notifier/apt_check.py"
APT_CHECK_PATH = ("aptitude full-upgrade --simulate --assume-yes")
PATTERN = "{} packages upgraded, {} newly installed, {} to remove and {} not upgraded."
def parse_result(to_parse):
# We want to line with the iforamtion about package upgrade
line_to_parse = to_parse.split("\n")[-4]
result = parse(PATTERN, line_to_parse)
return int(result[0]), int(result[2])
def get_apt_check_info(widget):
try:
@ -23,22 +34,16 @@ def get_apt_check_info(widget):
widget.set("error", "unable to query APT: {}".format(e))
return
all_pkg = 0
security = 0
res_array = res.split(';')
to_upgrade = 0
to_remove = 0
try:
s = res_array[0]
if s.isdigit(): all_pkg = int(s)
to_upgrade, to_remove = parse_result(res)
except e:
widget.set("error", "parse error: {}".format(e))
return
s = res_array[1]
if s.isdigit(): security = int(s)
except:
pass
widget.set("all_pkg", all_pkg)
widget.set("security", security)
widget.set("to_upgrade", to_upgrade)
widget.set("to_remove", to_remove)
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
@ -51,7 +56,7 @@ class Module(bumblebee.engine.Module):
result = []
if widget.get("error"):
return widget.get("error")
for t in ["all_pkg", "security"]:
for t in ["to_upgrade", "to_remove"]:
result.append(str(widget.get(t, 0)))
return "/".join(result)
@ -62,9 +67,9 @@ class Module(bumblebee.engine.Module):
def state(self, widget):
cnt = 0
ret = "good"
for t in ["all_pkg", "security"]:
for t in ["to_upgrade", "to_remove"]:
cnt += widget.get(t, 0)
if cnt > 50 or widget.get("security", 0) > 0:
if cnt > 50:
ret = "critical"
elif cnt > 0:
ret = "warning"