Skip to content

Commit 6013025

Browse files
authored
dnf_updates: new module from scratch replaces fedora_updates (#2291)
1 parent 7e4974c commit 6013025

File tree

3 files changed

+109
-100
lines changed

3 files changed

+109
-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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 {available}|\?color=available {available}]")
8+
thresholds: specify color thresholds to use
9+
(default [(0, 'good'), (1, 'degraded')])
10+
11+
Format placeholders:
12+
{available} number of pending available 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+
# i3status theme
25+
dnf_updates {
26+
format = "[\?if=security&color=bad DNF: {available}"
27+
format += "|\?color=available DNF: {available}]"
28+
}
29+
30+
# hide module when no available updates
31+
dnf_updates {
32+
format = "[\?if=available DNF [\?if=security&color=bad {available}"
33+
format += "|\?color=available {available}]]"
34+
}
35+
36+
# individual colorized updates
37+
dnf_updates {
38+
format = "[\?if=security SECURITY [\?color=tomato {security}]][\?soft ]"
39+
format += "[\?if=bugfix BUGFIX [\?color=limegreen {bugfix}]][\?soft ]"
40+
format += "[\?if=enhancement ENHANCEMENT [\?color=lightskyblue {enhancement}]][\?soft ]"
41+
format += "[\?if=unspecified OTHER [\?color=darkgray {unspecified}]]"
42+
}
43+
```
44+
45+
@author tobes
46+
@license BSD
47+
48+
SAMPLE OUTPUT
49+
[{'full_text': 'DNF '}, {'full_text': '14', 'color': '#FF0000'}]
50+
51+
no_updates
52+
[{'full_text': 'DNF '}, {'full_text': '0', 'color': '#00FF00'}]
53+
"""
54+
55+
from collections import Counter
56+
from json import loads
57+
58+
ADVISORIES = ["available", "bugfix", "enhancement", "security", "unspecified"]
59+
60+
61+
class Py3status:
62+
""" """
63+
64+
# available configuration parameters
65+
cache_timeout = 600
66+
format = "DNF [\?if=security&color=bad {available}|\?color=available {available}]"
67+
thresholds = [(0, "good"), (1, "degraded")]
68+
69+
def post_config_hook(self):
70+
self.thresholds_init = self.py3.get_color_names_list(self.format, ADVISORIES)
71+
72+
def _get_dnf_data(self):
73+
try:
74+
updates = loads(self.py3.command_output("dnf updateinfo list --json"))
75+
temporary = (
76+
dict.fromkeys(ADVISORIES, 0)
77+
| Counter(x['type'] for x in updates)
78+
| {ADVISORIES[0]: len(updates)}
79+
)
80+
cached_until = self.cache_timeout
81+
except self.py3.CommandError:
82+
temporary = dict.fromkeys(ADVISORIES, None)
83+
cached_until = 10
84+
85+
return (temporary, cached_until)
86+
87+
def dnf_updates(self):
88+
(dnf_data, cached_until) = self._get_dnf_data()
89+
90+
for x in self.thresholds_init:
91+
self.py3.threshold_get_color(dnf_data[x], x)
92+
93+
return {
94+
"cached_until": self.py3.time_in(cached_until),
95+
"full_text": self.py3.safe_format(self.format, dnf_data),
96+
}
97+
98+
99+
if __name__ == "__main__":
100+
"""
101+
Run module in test mode.
102+
"""
103+
from py3status.module_test import module_test
104+
105+
module_test(Py3status)

py3status/modules/fedora_updates.py

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

0 commit comments

Comments
 (0)