diff --git a/bumblebee/modules/apt.py b/bumblebee/modules/apt.py new file mode 100644 index 0000000..0e373c9 --- /dev/null +++ b/bumblebee/modules/apt.py @@ -0,0 +1,66 @@ +# pylint: disable=C0111,R0903 + +"""Displays APT package update information (/) +Requires the following debian packages: + * update-notifier-common + +""" + +import threading + +import bumblebee.util +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +APT_CHECK_PATH = "/usr/lib/update-notifier/apt_check.py" + +def get_apt_check_info(widget): + try: + res = bumblebee.util.execute(APT_CHECK_PATH) + except RuntimeError: + pass + + all_pkg = 0 + security = 0 + + res_array = res.split(';') + + s = res_array[0] + if s.isdigit(): all_pkg = int(s) + + s = res_array[1] + if s.isdigit(): security = int(s) + + widget.set("all_pkg", all_pkg) + widget.set("security", security) + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + widget = bumblebee.output.Widget(full_text=self.updates) + super(Module, self).__init__(engine, config, widget) + self.interval(30) + + def updates(self, widget): + result = [] + for t in ["all_pkg", "security"]: + result.append(str(widget.get(t, 0))) + return "/".join(result) + + def update(self, widgets): + thread = threading.Thread(target=get_apt_check_info, args=(widgets[0],)) + thread.start() + + def state(self, widget): + cnt = 0 + ret = "good" + for t in ["all_pkg", "security"]: + cnt += widget.get(t, 0) + if cnt > 50 or widget.get("security", 0) > 0: + ret = "critical" + elif cnt > 0: + ret = "warning" + + return ret + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/greyish-powerline.json b/themes/greyish-powerline.json index c962e4e..1cbaaf6 100644 --- a/themes/greyish-powerline.json +++ b/themes/greyish-powerline.json @@ -21,6 +21,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "pacman": { "good": { "fg": "#002b36", diff --git a/themes/gruvbox-light.json b/themes/gruvbox-light.json index 8b1ae50..11ef684 100644 --- a/themes/gruvbox-light.json +++ b/themes/gruvbox-light.json @@ -28,6 +28,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#1d2021", diff --git a/themes/gruvbox-powerline-light.json b/themes/gruvbox-powerline-light.json index e10039f..b4c4311 100644 --- a/themes/gruvbox-powerline-light.json +++ b/themes/gruvbox-powerline-light.json @@ -28,6 +28,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#1d2021", diff --git a/themes/gruvbox-powerline.json b/themes/gruvbox-powerline.json index 528ac97..f4cee5d 100644 --- a/themes/gruvbox-powerline.json +++ b/themes/gruvbox-powerline.json @@ -28,6 +28,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#1d2021", diff --git a/themes/gruvbox.json b/themes/gruvbox.json index e2b3002..3f8df28 100644 --- a/themes/gruvbox.json +++ b/themes/gruvbox.json @@ -28,6 +28,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#1d2021", diff --git a/themes/iceberg-powerline.json b/themes/iceberg-powerline.json index 3cc5781..f6af51b 100644 --- a/themes/iceberg-powerline.json +++ b/themes/iceberg-powerline.json @@ -25,6 +25,12 @@ "bg": "#161821" } }, + "apt": { + "good": { + "fg": "#b4be82", + "bg": "#161821" + } + }, "pacman": { "good": { "fg": "b4be82", diff --git a/themes/iceberg-rainbow.json b/themes/iceberg-rainbow.json index 784f5c8..e8cef97 100644 --- a/themes/iceberg-rainbow.json +++ b/themes/iceberg-rainbow.json @@ -25,6 +25,12 @@ "bg": "#161821" } }, + "apt": { + "good": { + "fg": "#b4be82", + "bg": "#161821" + } + }, "pacman": { "good": { "fg": "b4be82", diff --git a/themes/iceberg.json b/themes/iceberg.json index 83d90e0..5739b83 100644 --- a/themes/iceberg.json +++ b/themes/iceberg.json @@ -19,6 +19,12 @@ "bg": "#b4be82" } }, + "apt": { + "good": { + "fg": "#0f1117", + "bg": "#b4be82" + } + }, "pacman": { "good": { "fg": "#0f1117", diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 92da250..6cc79bb 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -6,6 +6,7 @@ "cpu": { "prefix": "cpu" }, "disk": { "prefix": "hdd" }, "dnf": { "prefix": "dnf" }, + "apt": { "prefix": "apt" }, "brightness": { "prefix": "o" }, "cmus": { "playing": { "prefix": ">" }, diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 60ec397..d62c643 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -10,6 +10,7 @@ "cpu": { "prefix": "" }, "disk": { "prefix": "" }, "dnf": { "prefix": "" }, + "apt": { "prefix": "" }, "pacman": { "prefix": "" }, "brightness": { "prefix": "" }, "load": { "prefix": "" }, diff --git a/themes/icons/ionicons.json b/themes/icons/ionicons.json index 6fe71cc..29f2303 100644 --- a/themes/icons/ionicons.json +++ b/themes/icons/ionicons.json @@ -10,6 +10,7 @@ "cpu": { "prefix": "\uf4b0" }, "disk": { "prefix": "\u26c1" }, "dnf": { "prefix": "\uf2be" }, + "apt": { "prefix": "\uf2be" }, "pacman": { "prefix": "\uf2be" }, "brightness": { "prefix": "\u263c" }, "load": { "prefix": "\uf13d" }, diff --git a/themes/powerline.json b/themes/powerline.json index 80be8cf..02f21f6 100644 --- a/themes/powerline.json +++ b/themes/powerline.json @@ -28,6 +28,12 @@ "bg": "#41db00" } }, + "apt": { + "good": { + "fg": "#494949", + "bg": "#41db00" + } + }, "battery": { "charged": { "fg": "#494949", diff --git a/themes/solarized-dark-awesome.json b/themes/solarized-dark-awesome.json index 1ec6dfe..9c3a6b3 100644 --- a/themes/solarized-dark-awesome.json +++ b/themes/solarized-dark-awesome.json @@ -19,6 +19,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "pacman": { "good": { "fg": "#002b36", diff --git a/themes/solarized-powerline.json b/themes/solarized-powerline.json index e1fbe1d..f940e5c 100644 --- a/themes/solarized-powerline.json +++ b/themes/solarized-powerline.json @@ -27,6 +27,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#002b36", diff --git a/themes/solarized.json b/themes/solarized.json index 12a71ae..03cabec 100644 --- a/themes/solarized.json +++ b/themes/solarized.json @@ -29,6 +29,12 @@ "bg": "#859900" } }, + "apt": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#002b36", diff --git a/themes/wal-powerline.json b/themes/wal-powerline.json index 049ecf8..dcb4fa9 100644 --- a/themes/wal-powerline.json +++ b/themes/wal-powerline.json @@ -29,6 +29,12 @@ "bg": "color3" } }, + "apt": { + "good": { + "fg": "background", + "bg": "color3" + } + }, "battery": { "charged": { "fg": "background",