Skip to content

Instantly share code, notes, and snippets.

@b10n1k
Created March 15, 2021 21:54
Show Gist options
  • Save b10n1k/3677efcbcfe4f7ae8e70032bf2edfd99 to your computer and use it in GitHub Desktop.
Save b10n1k/3677efcbcfe4f7ae8e70032bf2edfd99 to your computer and use it in GitHub Desktop.
"""
* 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