Merge pull request #514 from qba10/new_apt
[modules/apt] Change modules to use aptitude instead apt notifier
This commit is contained in:
commit
5e16733efa
2 changed files with 26 additions and 21 deletions
|
@ -2,7 +2,7 @@
|
||||||
|Name |Description |
|
|Name |Description |
|
||||||
|-----|------------|
|
|-----|------------|
|
||||||
|amixer |get volume level<br><br> |
|
|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> |
|
|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-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> |
|
|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> |
|
||||||
|
|
|
@ -1,19 +1,30 @@
|
||||||
# pylint: disable=C0111,R0903
|
# 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:
|
Requires the following debian packages:
|
||||||
* update-notifier-common
|
* python-parse
|
||||||
|
* aptitude
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
from parse import *
|
||||||
|
|
||||||
import bumblebee.util
|
import bumblebee.util
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
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):
|
def get_apt_check_info(widget):
|
||||||
try:
|
try:
|
||||||
|
@ -23,22 +34,16 @@ def get_apt_check_info(widget):
|
||||||
widget.set("error", "unable to query APT: {}".format(e))
|
widget.set("error", "unable to query APT: {}".format(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
all_pkg = 0
|
to_upgrade = 0
|
||||||
security = 0
|
to_remove = 0
|
||||||
|
|
||||||
res_array = res.split(';')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = res_array[0]
|
to_upgrade, to_remove = parse_result(res)
|
||||||
if s.isdigit(): all_pkg = int(s)
|
except e:
|
||||||
|
widget.set("error", "parse error: {}".format(e))
|
||||||
|
return
|
||||||
|
|
||||||
s = res_array[1]
|
widget.set("to_upgrade", to_upgrade)
|
||||||
if s.isdigit(): security = int(s)
|
widget.set("to_remove", to_remove)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
widget.set("all_pkg", all_pkg)
|
|
||||||
widget.set("security", security)
|
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
|
@ -51,7 +56,7 @@ class Module(bumblebee.engine.Module):
|
||||||
result = []
|
result = []
|
||||||
if widget.get("error"):
|
if widget.get("error"):
|
||||||
return 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)))
|
result.append(str(widget.get(t, 0)))
|
||||||
return "/".join(result)
|
return "/".join(result)
|
||||||
|
|
||||||
|
@ -62,9 +67,9 @@ class Module(bumblebee.engine.Module):
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
cnt = 0
|
cnt = 0
|
||||||
ret = "good"
|
ret = "good"
|
||||||
for t in ["all_pkg", "security"]:
|
for t in ["to_upgrade", "to_remove"]:
|
||||||
cnt += widget.get(t, 0)
|
cnt += widget.get(t, 0)
|
||||||
if cnt > 50 or widget.get("security", 0) > 0:
|
if cnt > 50:
|
||||||
ret = "critical"
|
ret = "critical"
|
||||||
elif cnt > 0:
|
elif cnt > 0:
|
||||||
ret = "warning"
|
ret = "warning"
|
||||||
|
|
Loading…
Reference in a new issue