Created
March 15, 2021 21:54
-
-
Save b10n1k/3677efcbcfe4f7ae8e70032bf2edfd99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
* name file something like zypper_up.py | |
* copy into ~/.config/py3status/modules/ | |
* edit i3status conf file | |
*Ctl+Shift+r | |
""" | |
import subprocess | |
import re | |
class Py3status: | |
""" | |
""" | |
# available configuration parameters | |
cache_timeout = 600 | |
format = "zypper: {updates}" | |
def post_config_hook(self): | |
self._reg_ex_pkg = re.compile(b"v\\s\\S+", re.M) | |
self._first = True | |
self._updates = 0 | |
def zypper_updates(self): | |
if self._first: | |
self._first = False | |
response = { | |
"cached_until": self.py3.time_in(0), | |
"full_text": self.py3.safe_format(self.format, {"updates": "?"}), | |
} | |
return response | |
output, error = subprocess.Popen( | |
["zypper", "lu"], stdout=subprocess.PIPE, stderr=subprocess.PIPE | |
).communicate() | |
updates = len(self._reg_ex_pkg.findall(output)) | |
if updates == 0: | |
color = self.py3.COLOR_GOOD | |
self._updates = 0 | |
else: | |
self._updates = updates | |
color = self.py3.COLOR_DEGRADED | |
response = { | |
"cached_until": self.py3.time_in(self.cache_timeout), | |
"color": color, | |
"full_text": self.py3.safe_format(self.format, {"updates": updates}), | |
} | |
return response | |
if __name__ == "__main__": | |
""" | |
Run module in test mode. | |
""" | |
from py3status.module_test import module_test | |
module_test(Py3status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment