Cleaned up some formatting and doc issues in apt module
# -*- coding: utf-8 -*-
"""
-Display number of pending updates for Ubuntu based Distros.
+Display number of pending updates for Debian based Distros.
Thanks to Iain Tatch <iain.tatch@gmail.com> for the script that this is based on.
@@ -9,8 +9,7 @@ This will display a count of how many 'apt' updates are waiting to be installed.
Configuration parameters:
cache_timeout: How often we refresh this module in seconds (default 600)
format: Display format to use
- (default 'UPD: {apt}')
- no_updates: Display format to use if there are no updates
+ (default 'UPD[\?not_zero : {apt}]')
Format placeholders:
{apt} Number of pending apt updates
@@ -28,19 +27,12 @@ SAMPLE OUTPUT
import subprocess
import sys
-FORMAT = 'UPD: {apt}'
-NO_UPDATES = 'UPD'
LINE_SEPARATOR = "\\n" if sys.version_info > (3, 0) else "\n"
-
class Py3status:
# available configuration parameters
cache_timeout = 600
- format = FORMAT
- no_updates = NO_UPDATES
-
- def post_config_hook(self):
- self.include_apt = self.py3.format_contains(self.format, 'apt')
+ format = 'UPD[\?not_zero : {apt}]'
def check_updates(self):
apt_updates = self._check_apt_updates()
@@ -48,10 +40,8 @@ class Py3status:
color = self.py3.COLOR_DEGRADED
if apt_updates == 0:
color = self.py3.COLOR_GOOD
- full_text = self.no_updates
- else:
full_text = self.py3.safe_format(
- self.include_apt,
+ self.format,
{
'apt': apt_updates
}
@@ -68,10 +58,9 @@ class Py3status:
to determine how many updates are waiting to be installed via
'apt list --upgradeable'.
"""
- pending_updates = str(subprocess.check_output(["apt", "list", "--upgradeable"]))
- pending_updates = pending_updates.split(LINE_SEPARATOR)
- pending_updates = pending_updates[1:-1]
- return len(pending_updates)
+ output = str(subprocess.check_output(["apt", "list", "--upgradeable"]))
+ output = output.split(LINE_SEPARATOR)
+ return len(output[1:-1])
if __name__ == "__main__":
