-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckupdates.py
35 lines (30 loc) · 998 Bytes
/
checkupdates.py
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
import subprocess
import shutil
from qtile_extras import widget
from modules.settings import colors
def chkup():
try:
num = len(subprocess.check_output("checkupdates").decode("utf-8").splitlines())
return str(num)
except subprocess.CalledProcessError as e:
if e.returncode == 0:
return str(num)
elif e.returncode == 2:
return "0"
else:
shutil.rmtree("/tmp/checkup-db-1000")
return chkup()
class CheckUpdates(widget.GenPollText):
defaults = [
("update_interval", 3600, "Update interval in seconds"),
("padding", 5, ""),
("fontsize", 12, ""),
("foreground", colors["fg2"], ""),
]
def __init__(self, **config):
widget.GenPollText.__init__(self, **config)
self.add_defaults(CheckUpdates.defaults)
def poll(self):
data = chkup()
self.foreground = colors["lightgreen"] if data == "0" else colors["red"]
return data