From e5a30424d51f9c20cd0ec6cd3e515ac5509a9287 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Thu, 18 Jul 2019 09:50:43 +0200
Subject: [PATCH 1/6] [config-manager] --setopt: Fix crash with "--save --dump"
(RhBug:1702678)
Removes useless code which only causes crash.
Example of crash:
dnf config-manager --save --dump --setopt=fedora.gpgcheck=1 fedora
============================================================== repo: fedora ==============================================================
Error: Error parsing '['1']': Wrong number or type of arguments for overloaded function 'OptionChildBool_set'.
Possible C/C++ prototypes are:
libdnf::OptionChild< libdnf::OptionBool >::set(libdnf::Option::Priority,libdnf::OptionBool::ValueType const &)
libdnf::OptionChild< libdnf::OptionBool >::set(libdnf::Option::Priority,std::string const &)
---
plugins/config_manager.py | 5 -----
1 file changed, 5 deletions(-)
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
index 38fd51d..6db1bcb 100644
--- a/plugins/config_manager.py
+++ b/plugins/config_manager.py
@@ -90,8 +90,6 @@ class ConfigManagerCommand(dnf.cli.Command):
self.base.conf.write_raw_configfile(dnf.const.CONF_FILENAME, 'main', sbc.substitutions, modify)
if self.opts.dump:
print(self.base.output.fmtSection('main'))
- for name, val in modify.items():
- sbc._set_value(name, val)
print(self.base.conf.dump())
if self.opts.set_enabled or self.opts.set_disabled:
@@ -120,9 +118,6 @@ class ConfigManagerCommand(dnf.cli.Command):
self.base.conf.write_raw_configfile(repo.repofile, repo.id, sbc.substitutions, repo_modify)
if self.opts.dump:
print(self.base.output.fmtSection('repo: ' + repo.id))
- for name, val in repo_modify.items():
- if repo._has_option(name):
- repo._set_value(name, val)
print(repo.dump())
def add_repo(self):
--
2.21.0
From f096fe3e88884f8cc212bfcee5549bfc6b8a3ad0 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Wed, 10 Jul 2019 09:21:37 +0200
Subject: [PATCH 2/6] [config-manager] --setopt: Add globs support to repoid
(RhBug:1702678)
Set key in all repositories whose id starts with "updates-testing":
dnf config-manager --save --setopt=updates-testing*.skip_if_unavailable=true
---
plugins/config_manager.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
index 6db1bcb..dedcc82 100644
--- a/plugins/config_manager.py
+++ b/plugins/config_manager.py
@@ -23,6 +23,7 @@ from dnfpluginscore import _, logger, P_
import dnf
import dnf.cli
import dnf.pycomp
+import fnmatch
import os
import re
import shutil
@@ -111,9 +112,10 @@ class ConfigManagerCommand(dnf.cli.Command):
repo_modify['enabled'] = "1"
elif self.opts.set_disabled:
repo_modify['enabled'] = "0"
- if (hasattr(self.opts, 'repo_setopts')
- and repo.id in self.opts.repo_setopts):
- repo_modify.update(self.opts.repo_setopts[repo.id])
+ if hasattr(self.opts, 'repo_setopts'):
+ for repoid, setopts in self.opts.repo_setopts.items():
+ if fnmatch.fnmatch(repo.id, repoid):
+ repo_modify.update(setopts)
if self.opts.save and repo_modify:
self.base.conf.write_raw_configfile(repo.repofile, repo.id, sbc.substitutions, repo_modify)
if self.opts.dump:
--
2.21.0
From c2ef00188a7ec911a5efc36d3df0cceae5a682c1 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Tue, 16 Jul 2019 13:32:39 +0200
Subject: [PATCH 3/6] [config-manager] --setopt=key=value is not applied to
repositories config (RhBug:1702678)
The command "dnf config-manager --setopt=key=value repo1 main" set key value
in repo1 and global config before the patch. It was inconsistent with the rest
of DNF because "--setopt=key=value" means to set key in global config only.
To set key in repos we can use "--setopt=*.key=value".
---
plugins/config_manager.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
index dedcc82..1dcf085 100644
--- a/plugins/config_manager.py
+++ b/plugins/config_manager.py
@@ -107,7 +107,7 @@ class ConfigManagerCommand(dnf.cli.Command):
raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
% ', '.join(self.opts.crepo))
for repo in sorted(matched):
- repo_modify = dict(modify) # create local copy
+ repo_modify = {}
if self.opts.set_enabled:
repo_modify['enabled'] = "1"
elif self.opts.set_disabled:
--
2.21.0
From 3af60a1613877ad2fd090a83ba9da00623a00818 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Tue, 16 Jul 2019 14:05:54 +0200
Subject: [PATCH 4/6] [config-manager] --setopt and empty list of repositories
(RhBug:1702678)
This:
"dnf config-manager --save --setopts=repo1.key1=value1 --setopt=repo2.key2=value2 repo1 repo2"
can be replaced by this now:
"dnf config-manager --save --setopts=repo1.key1=value1 --setopt=repo2.key2=value2"
Empty list of repositories allowed to change only the global configuration
before. Now empty list of repositories means that setopt works
for any repository too.
Better compatibility with YUM.
It solves : https://bugzilla.redhat.com/show_bug.cgi?id=1702678
---
plugins/config_manager.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
index 1dcf085..41b36fa 100644
--- a/plugins/config_manager.py
+++ b/plugins/config_manager.py
@@ -96,12 +96,16 @@ class ConfigManagerCommand(dnf.cli.Command):
if self.opts.set_enabled or self.opts.set_disabled:
self.opts.save = True
+ matched = []
if self.opts.crepo:
- matched = []
for name in self.opts.crepo:
matched.extend(self.base.repos.get_matching(name))
else:
- return
+ if hasattr(self.opts, 'repo_setopts'):
+ for name in self.opts.repo_setopts.keys():
+ matched.extend(self.base.repos.get_matching(name))
+ if not matched:
+ return
if not matched:
raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
--
2.21.0
From 27205851a592a3383a7592d87ceee5b69c9dfb70 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Tue, 16 Jul 2019 15:51:38 +0200
Subject: [PATCH 5/6] [config-manager] --setopt: Add check for existence of
input repositories (RhBug:1702678)
Examples:
dnf config-manager --save --setopt=non_existent.key=value
Error: No matching repo to modify: non_existent.
dnf config-manager --save --setopt=non_existent*.key=value
Error: No matching repo to modify: non_existent*.
None change in configuration is done after the error.
---
plugins/config_manager.py | 44 ++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
index 41b36fa..83d58be 100644
--- a/plugins/config_manager.py
+++ b/plugins/config_manager.py
@@ -78,6 +78,31 @@ class ConfigManagerCommand(dnf.cli.Command):
def modify_repo(self):
""" process --set-enabled, --set-disabled and --setopt options """
+ matching_repos = [] # list of matched repositories
+ not_matching_repos_id = set() # IDs of not matched repositories
+
+ def match_repos(key, add_matching_repos):
+ matching = self.base.repos.get_matching(key)
+ if not matching:
+ not_matching_repos_id.add(name)
+ elif add_matching_repos:
+ matching_repos.extend(matching)
+
+ if self.opts.crepo:
+ for name in self.opts.crepo:
+ match_repos(name, True)
+ if hasattr(self.opts, 'repo_setopts'):
+ for name in self.opts.repo_setopts.keys():
+ match_repos(name, False)
+ else:
+ if hasattr(self.opts, 'repo_setopts'):
+ for name in self.opts.repo_setopts.keys():
+ match_repos(name, True)
+
+ if not_matching_repos_id:
+ raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
+ % ', '.join(not_matching_repos_id))
+
sbc = self.base.conf
modify = {}
if hasattr(self.opts, 'main_setopts') and self.opts.main_setopts:
@@ -93,24 +118,13 @@ class ConfigManagerCommand(dnf.cli.Command):
print(self.base.output.fmtSection('main'))
print(self.base.conf.dump())
+ if not matching_repos:
+ return
+
if self.opts.set_enabled or self.opts.set_disabled:
self.opts.save = True
- matched = []
- if self.opts.crepo:
- for name in self.opts.crepo:
- matched.extend(self.base.repos.get_matching(name))
- else:
- if hasattr(self.opts, 'repo_setopts'):
- for name in self.opts.repo_setopts.keys():
- matched.extend(self.base.repos.get_matching(name))
- if not matched:
- return
-
- if not matched:
- raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
- % ', '.join(self.opts.crepo))
- for repo in sorted(matched):
+ for repo in sorted(matching_repos):
repo_modify = {}
if self.opts.set_enabled:
repo_modify['enabled'] = "1"
--
2.21.0
From f7d1fa8e5f657b3cc8ed60acdeaa02f6b725312a Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Thu, 18 Jul 2019 12:13:43 +0200
Subject: [PATCH 6/6] [config-manager] Update documentation (RhBug:1702678)
---
doc/config_manager.rst | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/doc/config_manager.rst b/doc/config_manager.rst
index 2feafcb..80ee0fa 100644
--- a/doc/config_manager.rst
+++ b/doc/config_manager.rst
@@ -19,22 +19,25 @@
DNF config-manager Plugin
==========================
-Manage main DNF configuration options, toggle which
+Manage main and repository DNF configuration options, toggle which
repositories are enabled or disabled, and add new repositories.
--------
Synopsis
--------
-``dnf config-manager [options] <repoid>...``
+``dnf config-manager [options] <section>...``
---------
Arguments
---------
-``<repoid>``
- Display / modify a repository identified by <repoid>. If not specified, display / modify
- main DNF configuration. Repositories can be specified using globs.
+``<section>``
+ This argument can be used to explicitly select the configuration sections to manage.
+ A section can either be ``main`` or a repoid.
+ If not specified, the program will select the ``main`` section and each repoid
+ used within any ``--setopt`` options.
+ A repoid can be specified using globs.
-------
Options
@@ -51,13 +54,17 @@ Options
Print dump of current configuration values to stdout.
``--set-disabled``, ``--disable``
- Disable the specified repos (automatically saves).
+ Disable the specified repos (implies ``--save``).
``--set-enabled``, ``--enable``
- Enable the specified repos (automatically saves).
+ Enable the specified repos (implies ``--save``).
``--save``
- Save the current options (useful with --setopt).
+ Save the current options (useful with ``--setopt``).
+
+``--setopt=<option>=<value>``
+ Set a configuration option. To set configuration options for repositories, use
+ ``repoid.option`` for the ``<option>``. Globs are supported in repoid.
--------
Examples
@@ -71,12 +78,15 @@ Examples
``dnf config-manager --dump``
Display main DNF configuration.
-``dnf config-manager <repoid> --dump``
- Display configuration of a repository identified by <repoid>.
+``dnf config-manager --dump <section>``
+ Display configuration of a repository identified by <section>.
``dnf config-manager --set-enabled <repoid>``
Enable repository identified by <repoid> and make the change permanent.
-``dnf config-manager --setopt proxy=http://proxy.example.com:3128/ <repo1> <repo2> --save``
+``dnf config-manager --save --setopt=*.proxy=http://proxy.example.com:3128/ <repo1> <repo2>``
Update proxy setting in repositories with repoid <repo1> and <repo2> and make the change
permanent.
+
+``dnf config-manager --save --setopt=*-debuginfo.gpgcheck=0``
+ Update gpgcheck setting in all repositories whose id ends with -debuginfo and make the change permanent.
--
2.21.0