Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing plugin parameters with dashes in names #1839

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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