From b8c1e1f16212f31e6c9f10041a4290ee1e88d5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C3=B3rkowski?= Date: Thu, 2 Jan 2020 14:20:58 +0100 Subject: [PATCH] [modules/apt] Change modules to use aptitude instead apt notifier --- Modules.md | 2 +- bumblebee/modules/apt.py | 45 ++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Modules.md b/Modules.md index 7d39865..86b2a16 100644 --- a/Modules.md +++ b/Modules.md @@ -2,7 +2,7 @@ |Name |Description | |-----|------------| |amixer |get volume level

| -|apt |Displays APT package update information (/)
Requires the following debian packages:
* update-notifier-common

| +|apt |Displays APT package update information (/)
Requires the following debian packages:
* aptitude

* python-parse

| |arch-update |Check updates to Arch Linux.
| |battery-upower |Displays battery status, remaining percentage and charging information.

Parameters:
* battery-upower.warning : Warning threshold in % of remaining charge (defaults to 20)
* battery-upower.critical : Critical threshold in % of remaining charge (defaults to 10)
* battery-upower.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged
| |battery |Displays battery status, remaining percentage and charging information.

Parameters:
* battery.device : Comma-separated list of battery devices to read information from (defaults to auto for auto-detection)
* battery.warning : Warning threshold in % of remaining charge (defaults to 20)
* battery.critical : Critical threshold in % of remaining charge (defaults to 10)
* battery.showdevice : If set to "true", add the device name to the widget (defaults to False)
* battery.decorate : If set to "false", hides additional icons (charging, etc.) (defaults to True)
| diff --git a/bumblebee/modules/apt.py b/bumblebee/modules/apt.py index f20cd52..99c7819 100644 --- a/bumblebee/modules/apt.py +++ b/bumblebee/modules/apt.py @@ -1,19 +1,30 @@ # pylint: disable=C0111,R0903 -"""Displays APT package update information (/) +"""Displays APT package update information (/) 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"