Skip to content

Commit

Permalink
Allow passing plugin parameters with dashes in names (RhBug:1980712)
Browse files Browse the repository at this point in the history
= changelog =
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1980712
  • Loading branch information
jan-kolarik authored and m-blaha committed Aug 11, 2022
1 parent 401aee0 commit 5b319fa
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions dnf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,17 @@ def _get_plugins_files(paths, disable_plugins, enable_plugins):
matched = True
enable_pattern_tested = False
for pattern_skip in disable_plugins:
if fnmatch.fnmatch(plugin_name, pattern_skip):
if _plugin_name_matches_pattern(plugin_name, pattern_skip):
pattern_disable_found.add(pattern_skip)
matched = False
for pattern_enable in enable_plugins:
if fnmatch.fnmatch(plugin_name, pattern_enable):
if _plugin_name_matches_pattern(plugin_name, pattern_enable):
matched = True
pattern_enable_found.add(pattern_enable)
enable_pattern_tested = True
if not enable_pattern_tested:
for pattern_enable in enable_plugins:
if fnmatch.fnmatch(plugin_name, pattern_enable):
if _plugin_name_matches_pattern(plugin_name, pattern_enable):
pattern_enable_found.add(pattern_enable)
if matched:
plugins.append(fn)
Expand All @@ -249,6 +249,20 @@ def _get_plugins_files(paths, disable_plugins, enable_plugins):
return plugins


def _plugin_name_matches_pattern(plugin_name, pattern):
"""
Checks plugin name matches the pattern.
The alternative plugin name using dashes instead of underscores is tried
in case of original name is not matched.
(see https://bugzilla.redhat.com/show_bug.cgi?id=1980712)
"""

try_names = set((plugin_name, plugin_name.replace('_', '-')))
return any(fnmatch.fnmatch(name, pattern) for name in try_names)


def register_command(command_class):
# :api
"""A class decorator for automatic command registration."""
Expand Down

0 comments on commit 5b319fa

Please sign in to comment.