Skip to content

Commit 0d74fe9

Browse files
committed
dnf_updates: new module from scratch
1 parent a742454 commit 0d74fe9

File tree

3 files changed

+82
-100
lines changed

3 files changed

+82
-100
lines changed

py3status/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@
229229
"new": ["playerctl"],
230230
"msg": "Module {old} has been replaced with a module {new}.",
231231
},
232+
"fedora_updates": {
233+
"new": ["dnf_updates"],
234+
"msg": "Module {old} has been replaced with a module {new}.",
235+
},
232236
"gpmdp": {
233237
"new": ["playerctl"],
234238
"msg": "Module {old} has been replaced with a module {new}.",

py3status/modules/dnf_updates.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
Display number of pending updates for Fedora Linux.
3+
4+
Configuration parameters:
5+
cache_timeout: refresh interval for this module (default 600)
6+
format: display format for this module
7+
(default "DNF [\?if=security&color=bad {updates}|\?color=updates {updates}]")
8+
thresholds: specify color thresholds to use
9+
(default [(0, 'good'), (1, 'degraded')])
10+
11+
Format placeholders:
12+
{updates} number of pending updates
13+
{bugfix} number of pending bugfix updates
14+
{enhancement} number of pending enhancement updates
15+
{security} number of pending security updates
16+
{unspecified} number of pending unspecified updates
17+
18+
Color thresholds:
19+
format:
20+
`xxx`: print a color based on the value of `xxx` placeholder
21+
22+
Examples:
23+
```
24+
# individual colorized updates
25+
dnf_updates {
26+
format = "[\?if=security&color=tomato SECURITY {security}][\?soft ]"
27+
format += "[\?if=bugfix&color=limegreen BUGFIX {bugfix}][\?soft ]"
28+
format += "[\?if=enhancement&color=lightskyblue ENHANCEMENT {enhancement}][\?soft ]"
29+
format += "[\?if=unspecified&color=darkgray OTHER {unspecified}]"
30+
}
31+
```
32+
33+
@author tobes
34+
@license BSD
35+
36+
SAMPLE OUTPUT
37+
[{'full_text': 'DNF '}, {'full_text': '14', 'color': '#FF0000'}]
38+
39+
no_updates
40+
[{'full_text': 'DNF '}, {'full_text': '0', 'color': '#00FF00'}]
41+
"""
42+
43+
from collections import Counter
44+
from json import loads
45+
46+
47+
class Py3status:
48+
""" """
49+
50+
# available configuration parameters
51+
cache_timeout = 600
52+
format = "DNF [\?if=security&color=bad {updates}|\?color=updates {updates}]"
53+
thresholds = [(0, "good"), (1, "degraded")]
54+
55+
def post_config_hook(self):
56+
self.thresholds_init = self.py3.get_color_names_list(self.format)
57+
58+
def dnf_updates(self):
59+
updates = loads(self.py3.command_output("dnf updateinfo list --json"))
60+
dnf_data = dict(Counter(x['type'] for x in updates)) | {"updates": len(updates)}
61+
62+
for x in self.thresholds_init:
63+
if x in dnf_data:
64+
self.py3.threshold_get_color(dnf_data[x], x)
65+
66+
return {
67+
"cached_until": self.py3.time_in(self.cache_timeout),
68+
"full_text": self.py3.safe_format(self.format, dnf_data),
69+
}
70+
71+
72+
if __name__ == "__main__":
73+
"""
74+
Run module in test mode.
75+
"""
76+
from py3status.module_test import module_test
77+
78+
module_test(Py3status)

py3status/modules/fedora_updates.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)