[modules/apt] Add APT update checking module

This commit is contained in:
Piotr Piórkowski 2019-01-07 20:56:13 +01:00
parent 2fa3a0e250
commit 1860b7abb3
No known key found for this signature in database
GPG key ID: E5AC204C40D6D77B
17 changed files with 147 additions and 0 deletions

66
bumblebee/modules/apt.py Normal file
View file

@ -0,0 +1,66 @@
# pylint: disable=C0111,R0903
"""Displays APT package update information (<toupgrade>/<security>)
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

View file

@ -21,6 +21,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"pacman": { "pacman": {
"good": { "good": {
"fg": "#002b36", "fg": "#002b36",

View file

@ -28,6 +28,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#1d2021", "fg": "#1d2021",

View file

@ -28,6 +28,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#1d2021", "fg": "#1d2021",

View file

@ -28,6 +28,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#1d2021", "fg": "#1d2021",

View file

@ -28,6 +28,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#1d2021", "fg": "#1d2021",

View file

@ -25,6 +25,12 @@
"bg": "#161821" "bg": "#161821"
} }
}, },
"apt": {
"good": {
"fg": "#b4be82",
"bg": "#161821"
}
},
"pacman": { "pacman": {
"good": { "good": {
"fg": "b4be82", "fg": "b4be82",

View file

@ -25,6 +25,12 @@
"bg": "#161821" "bg": "#161821"
} }
}, },
"apt": {
"good": {
"fg": "#b4be82",
"bg": "#161821"
}
},
"pacman": { "pacman": {
"good": { "good": {
"fg": "b4be82", "fg": "b4be82",

View file

@ -19,6 +19,12 @@
"bg": "#b4be82" "bg": "#b4be82"
} }
}, },
"apt": {
"good": {
"fg": "#0f1117",
"bg": "#b4be82"
}
},
"pacman": { "pacman": {
"good": { "good": {
"fg": "#0f1117", "fg": "#0f1117",

View file

@ -6,6 +6,7 @@
"cpu": { "prefix": "cpu" }, "cpu": { "prefix": "cpu" },
"disk": { "prefix": "hdd" }, "disk": { "prefix": "hdd" },
"dnf": { "prefix": "dnf" }, "dnf": { "prefix": "dnf" },
"apt": { "prefix": "apt" },
"brightness": { "prefix": "o" }, "brightness": { "prefix": "o" },
"cmus": { "cmus": {
"playing": { "prefix": ">" }, "playing": { "prefix": ">" },

View file

@ -10,6 +10,7 @@
"cpu": { "prefix": "" }, "cpu": { "prefix": "" },
"disk": { "prefix": "" }, "disk": { "prefix": "" },
"dnf": { "prefix": "" }, "dnf": { "prefix": "" },
"apt": { "prefix": "" },
"pacman": { "prefix": "" }, "pacman": { "prefix": "" },
"brightness": { "prefix": "" }, "brightness": { "prefix": "" },
"load": { "prefix": "" }, "load": { "prefix": "" },

View file

@ -10,6 +10,7 @@
"cpu": { "prefix": "\uf4b0" }, "cpu": { "prefix": "\uf4b0" },
"disk": { "prefix": "\u26c1" }, "disk": { "prefix": "\u26c1" },
"dnf": { "prefix": "\uf2be" }, "dnf": { "prefix": "\uf2be" },
"apt": { "prefix": "\uf2be" },
"pacman": { "prefix": "\uf2be" }, "pacman": { "prefix": "\uf2be" },
"brightness": { "prefix": "\u263c" }, "brightness": { "prefix": "\u263c" },
"load": { "prefix": "\uf13d" }, "load": { "prefix": "\uf13d" },

View file

@ -28,6 +28,12 @@
"bg": "#41db00" "bg": "#41db00"
} }
}, },
"apt": {
"good": {
"fg": "#494949",
"bg": "#41db00"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#494949", "fg": "#494949",

View file

@ -19,6 +19,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"pacman": { "pacman": {
"good": { "good": {
"fg": "#002b36", "fg": "#002b36",

View file

@ -27,6 +27,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#002b36", "fg": "#002b36",

View file

@ -29,6 +29,12 @@
"bg": "#859900" "bg": "#859900"
} }
}, },
"apt": {
"good": {
"fg": "#002b36",
"bg": "#859900"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "#002b36", "fg": "#002b36",

View file

@ -29,6 +29,12 @@
"bg": "color3" "bg": "color3"
} }
}, },
"apt": {
"good": {
"fg": "background",
"bg": "color3"
}
},
"battery": { "battery": {
"charged": { "charged": {
"fg": "background", "fg": "background",