Lilian Jónsdóttir revised this gist . Go to revision
1 file changed, 1 insertion
xbps-check-updates.py
@@ -15,6 +15,7 @@ from typing import Any, NamedTuple | |||
15 | 15 | ||
16 | 16 | ## updated with hourly cronjob that contains: | |
17 | 17 | # xbps-install -S | |
18 | + | # cd $HOME/void-packages && git pull | |
18 | 19 | # xbps-checkvers -I > /tmp/xbps_updates_available | |
19 | 20 | ## by befault output is formatted like: | |
20 | 21 | # pkg name old_ver new_ver template name repository (if known) |
Lilian Jónsdóttir revised this gist . Go to revision
1 file changed, 9 insertions, 7 deletions
xbps-check-updates.py(file created)
@@ -10,14 +10,15 @@ | |||
10 | 10 | # } | |
11 | 11 | ||
12 | 12 | import json | |
13 | - | from typing import NamedTuple | |
13 | + | import os | |
14 | + | from typing import Any, NamedTuple | |
14 | 15 | ||
15 | 16 | ## updated with hourly cronjob that contains: | |
16 | 17 | # xbps-install -S | |
17 | 18 | # xbps-checkvers -I > /tmp/xbps_updates_available | |
18 | - | ## output is formatted like: | |
19 | - | # pkg name old_ver new_ver name again? random question mark?? | |
20 | - | # minizip 1.2.13_1 1.3_1 minizip ? | |
19 | + | ## by befault output is formatted like: | |
20 | + | # pkg name old_ver new_ver template name repository (if known) | |
21 | + | # minizip 1.2.13_1 1.3_1 minizip ? | |
21 | 22 | UPDATE_FILE = "/tmp/xbps_updates_available" | |
22 | 23 | ||
23 | 24 | ||
@@ -31,11 +32,12 @@ class Update(NamedTuple): | |||
31 | 32 | ||
32 | 33 | ||
33 | 34 | def main(): | |
35 | + | total_packages = int(os.popen("xbps-query -l | wc -l").read()) | |
34 | 36 | output = { | |
35 | 37 | "text": "", | |
36 | 38 | "alt": "", | |
37 | 39 | "tooltip": "", | |
38 | - | "percentage": "", | |
40 | + | "percentage": Any, | |
39 | 41 | } | |
40 | 42 | updates = [] | |
41 | 43 | # get list of updates from UPDATE_FILE | |
@@ -51,8 +53,8 @@ def main(): | |||
51 | 53 | output["tooltip"] = "Up to date!" | |
52 | 54 | else: | |
53 | 55 | output["tooltip"] = f"Updates available:\n{'\n'.join(str(x) for x in updates)}" | |
54 | - | output["alt"] = f"Updates: {num_updates}" | |
55 | - | output["percentage"] = "0" | |
56 | + | output["alt"] = f"Updates: {num_updates} / {total_packages}" | |
57 | + | output["percentage"] = num_updates / total_packages | |
56 | 58 | ||
57 | 59 | print(json.dumps(output)) | |
58 | 60 |
celediel revised this gist . Go to revision
No changes
celediel revised this gist . Go to revision
1 file changed, 61 insertions
xbps-check-updates.py(file created)
@@ -0,0 +1,61 @@ | |||
1 | + | #!/bin/env python | |
2 | + | ||
3 | + | ### Add to ~/.config/waybar/config like so | |
4 | + | # "custom/xbps-updates": { | |
5 | + | # "format": "{} ", | |
6 | + | # "interval": 3600, | |
7 | + | # "return-type": "json", | |
8 | + | # "exec": "xbps-checkup-updates | jq --unbuffered --compact-output", | |
9 | + | # "tooltip": true, | |
10 | + | # } | |
11 | + | ||
12 | + | import json | |
13 | + | from typing import NamedTuple | |
14 | + | ||
15 | + | ## updated with hourly cronjob that contains: | |
16 | + | # xbps-install -S | |
17 | + | # xbps-checkvers -I > /tmp/xbps_updates_available | |
18 | + | ## output is formatted like: | |
19 | + | # pkg name old_ver new_ver name again? random question mark?? | |
20 | + | # minizip 1.2.13_1 1.3_1 minizip ? | |
21 | + | UPDATE_FILE = "/tmp/xbps_updates_available" | |
22 | + | ||
23 | + | ||
24 | + | class Update(NamedTuple): | |
25 | + | package: str | |
26 | + | current_ver: str | |
27 | + | new_ver: str | |
28 | + | ||
29 | + | def __str__(self) -> str: | |
30 | + | return f"{self.package}: {self.current_ver} -> {self.new_ver}" | |
31 | + | ||
32 | + | ||
33 | + | def main(): | |
34 | + | output = { | |
35 | + | "text": "", | |
36 | + | "alt": "", | |
37 | + | "tooltip": "", | |
38 | + | "percentage": "", | |
39 | + | } | |
40 | + | updates = [] | |
41 | + | # get list of updates from UPDATE_FILE | |
42 | + | with open(UPDATE_FILE) as file: | |
43 | + | for line in file: | |
44 | + | split_line = line.split(" ") | |
45 | + | updates.append(Update(split_line[0], split_line[1], split_line[2])) | |
46 | + | num_updates = len(updates) | |
47 | + | ||
48 | + | # format updates for waybar | |
49 | + | output["text"] = str(num_updates) | |
50 | + | if num_updates <= 0: | |
51 | + | output["tooltip"] = "Up to date!" | |
52 | + | else: | |
53 | + | output["tooltip"] = f"Updates available:\n{'\n'.join(str(x) for x in updates)}" | |
54 | + | output["alt"] = f"Updates: {num_updates}" | |
55 | + | output["percentage"] = "0" | |
56 | + | ||
57 | + | print(json.dumps(output)) | |
58 | + | ||
59 | + | ||
60 | + | if __name__ == "__main__": | |
61 | + | main() |