From b47f099dcf724b32cbac4fe7b463a6c4532ba102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Mand=C3=A1k?= Date: Tue, 2 Jun 2015 19:40:18 +0200 Subject: [PATCH] Added backend for apt-get. --- i3pystatus/updates/aptget.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 i3pystatus/updates/aptget.py diff --git a/i3pystatus/updates/aptget.py b/i3pystatus/updates/aptget.py new file mode 100644 index 0000000..acf583b --- /dev/null +++ b/i3pystatus/updates/aptget.py @@ -0,0 +1,32 @@ +import os + +from i3pystatus.core.command import run_through_shell +from i3pystatus.updates import Backend + + +class AptGet(Backend): + """ + Gets update count for Debian based distributions. + + This mimics the Arch Linux `checkupdates` script + but with apt-get and written in python. + """ + + @property + def updates(self): + cache_dir = "/tmp/update-cache-" + os.getenv("USER") + if not os.path.exists(cache_dir): + os.mkdir(cache_dir) + + command = "apt-get update -o Dir::State::Lists=" + cache_dir + run_through_shell(command) + command = "apt-get upgrade -s -o Dir::State::Lists=" + cache_dir + apt = run_through_shell(command) + + update_count = 0 + for line in apt.out.split("\n"): + if line.startswith("Inst"): + update_count += 1 + return update_count + +Backend = AptGet