Última atividade 1704241163

xbps update checker for waybar

Revisão ba3034e84aab706926f6fd0730c0f4b149eb915a

xbps-check-updates.py Bruto
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
12import json
13import os
14from typing import Any, NamedTuple
15
16## updated with hourly cronjob that contains:
17# xbps-install -S
18# xbps-checkvers -I > /tmp/xbps_updates_available
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 ?
22UPDATE_FILE = "/tmp/xbps_updates_available"
23
24
25class Update(NamedTuple):
26 package: str
27 current_ver: str
28 new_ver: str
29
30 def __str__(self) -> str:
31 return f"{self.package}: {self.current_ver} -> {self.new_ver}"
32
33
34def main():
35 total_packages = int(os.popen("xbps-query -l | wc -l").read())
36 output = {
37 "text": "",
38 "alt": "",
39 "tooltip": "",
40 "percentage": Any,
41 }
42 updates = []
43 # get list of updates from UPDATE_FILE
44 with open(UPDATE_FILE) as file:
45 for line in file:
46 split_line = line.split(" ")
47 updates.append(Update(split_line[0], split_line[1], split_line[2]))
48 num_updates = len(updates)
49
50 # format updates for waybar
51 output["text"] = str(num_updates)
52 if num_updates <= 0:
53 output["tooltip"] = "Up to date!"
54 else:
55 output["tooltip"] = f"Updates available:\n{'\n'.join(str(x) for x in updates)}"
56 output["alt"] = f"Updates: {num_updates} / {total_packages}"
57 output["percentage"] = num_updates / total_packages
58
59 print(json.dumps(output))
60
61
62if __name__ == "__main__":
63 main()
64