aboutsummaryrefslogtreecommitdiff
path: root/i3/check-updates.py
blob: cdac7e6aee38a29edbb1b9d957e3c6a38d7568eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3

# add a crontab entry with crontab -e:
# 0 */6 * * *     $HOME/.config/nvim/i3/check-updates.py
#
# create /etc/apt/apt.conf.d/10periodic with:
# APT::Periodic::Enable "1";
# APT::Periodic::Update-Package-Lists "1";
# APT::Periodic::AutocleanInterval "7";
# APT::Periodic::Verbose "1";
#


import subprocess
import pathlib
import os

CMD = ["apt", "list", "--upgradeable"]


def check_updates():
    output = str(subprocess.check_output(CMD, stderr=subprocess.DEVNULL))
    output = output.split("\\n")
    return len(output[1:-1])


if __name__ == "__main__":
    pending = check_updates()
    if pending == 0:
        result = ""
    else:
        result = f"{pending} update" + ("s" if pending > 1 else "")

    with open(os.path.join(pathlib.Path.home(), ".pending_updates"), "wt") as fd:
        fd.write(result)