Skip to content

Commit 5cb09fa

Browse files
Ondřej Sojkajamescassell
authored andcommitted
Implement drop-in configuration folder (RhBug:1352234)
1 parent bd00c04 commit 5cb09fa

6 files changed

Lines changed: 15 additions & 2 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ DNF CONTRIBUTORS
9393
Tomas Kasparek <tkasparek@redhat.com>
9494
Vladan Kudlac <vladankudlac@gmail.com>
9595
Will Woods <wwoods@redhat.com>
96+
Ondřej Sojka <ondrej.sojka@gmail.com>

dnf/cli/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ def configure(self, args, option_parser=None):
870870
self.demands.cacheonly = True
871871
self.base.conf._configure_from_options(opts)
872872
self._read_conf_file(opts.releasever)
873+
self.base.conf.read_dropin_dir()
873874
if 'arch' in opts:
874875
self.base.conf.arch = opts.arch
875876
self.base.conf._adjust_conf_options()

dnf/conf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
places, hard to change and debug. The new structure here will replace that. Its
2525
goal is to:
2626
27-
* accept configuration options from all three sources (the main config file,
28-
repo config files, command line switches)
27+
* accept configuration options from all four sources (the main config file,
28+
drop-in configuration folder, repo config files, command line switches)
2929
* handle all the logic of storing those and producing related values.
3030
* returning configuration values.
3131
* optionally: asserting no value is overridden once it has been applied

dnf/conf/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
PRIO_REPOCONFIG = libdnf.conf.Option.Priority_REPOCONFIG
4343
PRIO_PLUGINDEFAULT = libdnf.conf.Option.Priority_PLUGINDEFAULT
4444
PRIO_PLUGINCONFIG = libdnf.conf.Option.Priority_PLUGINCONFIG
45+
PRIO_DROPINCONFIG = libdnf.conf.Option.Priority_DROPINCONFIG
4546
PRIO_COMMANDLINE = libdnf.conf.Option.Priority_COMMANDLINE
4647
PRIO_RUNTIME = libdnf.conf.Option.Priority_RUNTIME
4748

@@ -417,6 +418,10 @@ def read(self, filename=None, priority=PRIO_DEFAULT):
417418
# update to where we read the file from
418419
self._set_value('config_file_path', filename, priority)
419420

421+
def read_dropin_dir(self, dirname=dnf.const.CONF_DROPIN_DIR, priority=PRIO_DROPINCONFIG):
422+
for filename in sorted(os.listdir(dirname)):
423+
self.read(os.path.join(dirname, filename), priority)
424+
420425
@property
421426
def verbose(self):
422427
return self._get_value('debuglevel') >= dnf.const.VERBOSE_LEVEL

dnf/const.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import distutils.sysconfig
2323

2424
CONF_FILENAME='/etc/dnf/dnf.conf' # :api
2525
CONF_AUTOMATIC_FILENAME='/etc/dnf/automatic.conf'
26+
CONF_DROPIN_DIR='/etc/dnf/conf.d/'
2627
DISTROVERPKG=('system-release(releasever)', 'system-release',
2728
'distribution-release(releasever)', 'distribution-release',
2829
'redhat-release', 'suse-release')

doc/conf_ref.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
all \*.repo files found under ``/etc/yum.repos.d``. The latter is typically used
3030
for repository configuration and takes precedence over global configuration.
3131

32+
It is also possible to drop configuration snippets into ``/etc/dnf/conf.d/``.
33+
These are read in alphabetical order and can override all configuration. Every
34+
option must be part of a section to be read correctly; therefore start every
35+
dropped-in configuration file with ``[main]`` or ``[repo]``.
36+
3237
The configuration file has INI format consisting of section declaration and
3338
``name=value`` options below each on separate line. There are two types of sections
3439
in the configuration files: main and repository. Main section defines all global

0 commit comments

Comments
 (0)