Blame SOURCES/0033-Allow-passing-plugin-parameters-with-dashes-in-names.patch

922fe2
From 7a265cf17fe3531e45dde8ae622c496bef1e17ae Mon Sep 17 00:00:00 2001
922fe2
From: Jan Kolarik <jkolarik@redhat.com>
922fe2
Date: Wed, 10 Aug 2022 16:24:08 +0200
922fe2
Subject: [PATCH] Allow passing plugin parameters with dashes in names
922fe2
 (RhBug:1980712)
922fe2
922fe2
= changelog =
922fe2
type: bugfix
922fe2
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1980712
922fe2
---
922fe2
 dnf/plugin.py | 20 +++++++++++++++++---
922fe2
 1 file changed, 17 insertions(+), 3 deletions(-)
922fe2
922fe2
diff --git a/dnf/plugin.py b/dnf/plugin.py
922fe2
index 87c1f08f..b083727d 100644
922fe2
--- a/dnf/plugin.py
922fe2
+++ b/dnf/plugin.py
922fe2
@@ -225,17 +225,17 @@ def _get_plugins_files(paths, disable_plugins, enable_plugins):
922fe2
             matched = True
922fe2
             enable_pattern_tested = False
922fe2
             for pattern_skip in disable_plugins:
922fe2
-                if fnmatch.fnmatch(plugin_name, pattern_skip):
922fe2
+                if _plugin_name_matches_pattern(plugin_name, pattern_skip):
922fe2
                     pattern_disable_found.add(pattern_skip)
922fe2
                     matched = False
922fe2
                     for pattern_enable in enable_plugins:
922fe2
-                        if fnmatch.fnmatch(plugin_name, pattern_enable):
922fe2
+                        if _plugin_name_matches_pattern(plugin_name, pattern_enable):
922fe2
                             matched = True
922fe2
                             pattern_enable_found.add(pattern_enable)
922fe2
                     enable_pattern_tested = True
922fe2
             if not enable_pattern_tested:
922fe2
                 for pattern_enable in enable_plugins:
922fe2
-                    if fnmatch.fnmatch(plugin_name, pattern_enable):
922fe2
+                    if _plugin_name_matches_pattern(plugin_name, pattern_enable):
922fe2
                         pattern_enable_found.add(pattern_enable)
922fe2
             if matched:
922fe2
                 plugins.append(fn)
922fe2
@@ -250,6 +250,20 @@ def _get_plugins_files(paths, disable_plugins, enable_plugins):
922fe2
     return plugins
922fe2
 
922fe2
 
922fe2
+def _plugin_name_matches_pattern(plugin_name, pattern):
922fe2
+    """
922fe2
+    Checks plugin name matches the pattern.
922fe2
+
922fe2
+    The alternative plugin name using dashes instead of underscores is tried
922fe2
+    in case of original name is not matched.
922fe2
+
922fe2
+    (see https://bugzilla.redhat.com/show_bug.cgi?id=1980712)
922fe2
+    """
922fe2
+
922fe2
+    try_names = set((plugin_name, plugin_name.replace('_', '-')))
922fe2
+    return any(fnmatch.fnmatch(name, pattern) for name in try_names)
922fe2
+
922fe2
+
922fe2
 def register_command(command_class):
922fe2
     # :api
922fe2
     """A class decorator for automatic command registration."""
922fe2
-- 
922fe2
2.37.1
922fe2