# -*- coding: utf-8 -*-
"""
The number of package updates pending for a Fedora Linux installation.

This will display a count of how many `dnf` updates are waiting
to be installed.
Additionally check if any update security notices.

Configuration parameters:
    cache_timeout: How often we refresh this module in seconds
        (default 600)
    format: Display format to use
        (default 'DNF: {updates}')

Format placeholders:
    {updates} number of pending dnf updates

Color options:
    color_bad: Security notice
    color_degraded: Upgrade available
    color_good: No upgrades needed

@author tobes
@license BSD
"""

import subprocess
import re


class Py3status:
    # available configuration parameters
    cache_timeout = 600
    format = 'DNF: {updates}'

    def __init__(self):
        self._reg_ex_sec = re.compile('\d+(?=\s+Security)')
        self._reg_ex_pkg = re.compile(b'^\S+\.', re.M)
        self._first = True
        self._updates = None
        self._security_notice = False

    def check_updates(self):
        if self._first:
            self._first = False
            response = {
                'cached_until': self.py3.time_in(),
                'full_text': self.py3.safe_format(self.format, {'updates': '?'})
            }
            return response

        output, error = subprocess.Popen(
            ['dnf', 'check-update'],
            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
            self._security_notice = False
        else:
            if not self._security_notice and self._updates != updates:
                output, error = subprocess.Popen(
                    ['dnf', 'updateinfo'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE).communicate()
                notices = str(output)
                self._security_notice = len(self._reg_ex_sec.findall(notices))
                self._updates = updates
            if self._security_notice:
                color = self.py3.COLOR_BAD
            else:
                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__":
    """
    Test this module by calling it directly.
    """
    """
    Run module in test mode.
    """
    from py3status.module_test import module_test
    module_test(Py3status)

@@ -337,16 +337,86 @@
 lt 600)%0A
+    check_security: Check for security updates%0A        (default True)%0A
     form
@@ -441,16 +441,16 @@
  to use%0A
-
         
@@ -836,16 +836,42 @@
 pdates%7D'
+%0A    check_security = True
 %0A%0A    de
@@ -1773,16 +1773,40 @@
      if 
+self.check_security and 
 not self
@@ -2197,32 +2197,32 @@
 dates = updates%0A
-
             if s
@@ -2216,24 +2216,48 @@
          if 
+self.check_security and 
 self._securi

Add option for checking security updates