Repository: qtile/qtile

Issue:
widget.CheckUpdates on Fedora: show the correct number of updates
widget.CheckUpdates on Fedora shows -2 updates when no updates found.

Excerpt from my config.py:
```
widget.CheckUpdates(
                     distro='Fedora',
                     display_format='  {updates} updates',
                     colour_have_updates=colors[3],
                     no_update_string='  no update',
                     update_interval=1800,
                     colour_no_updates=colors[5],
                     background=colors[8],
                     ),
```
# Qtile version
0.17.1dev
# distro
Fedora 34


Discussion:
The widget should work by running `dnf list updates`, counting the number of lines and subtracting 3. So, if you're getting `-2` then there's only a single line output at the moment.

Run the command in a terminal and see what the output is.
Correct. Only one line about last metadata check date.
So the problem is not the widget.

I don't use Fedora but try searching for that error message.
Last metadata expiration check date is a standard message, doesn't mean errors.
I think Fedora maintaners won't change the behaviour of dnf package manager for a Qtile widget.
Ah. Fair enough. Said I didn't use Fedora!

Does that mean there are no updates?

If so, maybe we just change the widget so that, if there are fewer than the
minimum number, it treats it as no updates.


Alternatively, can the metadata message be silenced? Could change the command that the widget runs.
_"-q, --quiet
    In combination with a non-interactive command, shows just the relevant content. Suppresses messages notifying about the current state or actions of DNF."_

So, `dnf list updates -q` is what we are looking for. Tried it, no output on a fully upgraded system.
Excellent. Does it produce the same number of lines when there are updates (i.e. is it still correct to subtract 3?)

If it does work, can to submit the pull request with the fix?
Needs some testing, I have a fully upgraded system atm. I have to wait for a few upgrades to land in the repos.
I think I'll be able to submit a PR with the fix.

Resolving patch:
diff --git a/libqtile/widget/check_updates.py b/libqtile/widget/check_updates.py
--- a/libqtile/widget/check_updates.py
+++ b/libqtile/widget/check_updates.py
@@ -55,7 +55,7 @@ def __init__(self, **config):
                          "Arch_yay": ("yay -Qu", 0),
                          "Debian": ("apt-show-versions -u -b", 0),
                          "Ubuntu": ("aptitude search ~U", 0),
-                         "Fedora": ("dnf list updates", 3),
+                         "Fedora": ("dnf list updates -q", 1),
                          "FreeBSD": ("pkg_version -I -l '<'", 0),
                          "Mandriva": ("urpmq --auto-select", 0)
                          }
@@ -86,6 +86,8 @@ def _check_updates(self):
             updates = ""
         num_updates = self.custom_command_modify(len(updates.splitlines()))
 
+        if num_updates < 0:
+            num_updates = 0
         if num_updates == 0:
             self.layout.colour = self.colour_no_updates
             return self.no_update_string


Test patch: