[PATCH] Include options from global koji configs located in /etc/koji.conf.d

Brian Stinson bstinson at ksu.edu
Mon Dec 1 02:21:55 UTC 2014


Hi All,

The koji cli tool allows for configs to be placed in /etc/koji.conf.d It would
be helpful if rpkg knew about this too. This patch builds a list of any configs
in the global koji dir, adds any files specified by the rpkg configuration file,
and then adds the user koji config (to maintain the correct precedence).  

Thanks!
Brian

---
 src/pyrpkg/__init__.py | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 73fe7da..9941e74 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -176,6 +176,27 @@ class Commands(object):
             self._repo = None
         self._path = value
 
+    def _get_koji_dir_configs(self, koji_confdir):
+        configfiles = []
+
+        if not os.path.exists(koji_confdir):
+            # if the directory doesn't exist, return an empty list
+            self.log.debug("Could not load config files from directory "
+                           "{0}".format(koji_confdir))
+            return configfiles
+
+        files = os.listdir(koji_confdir)
+
+        for file in sorted(files):
+            # we are only interested in files with the .conf extension
+            if not file.endswith('.conf'):
+                continue
+
+            configfullpath = os.path.join(koji_confdir, file)
+            configfiles.append(configfullpath)
+
+        return configfiles
+
     @property
     def anon_kojisession(self):
         """This property ensures the anon kojisession attribute"""
@@ -204,8 +225,15 @@ class Commands(object):
                     'topurl': None
                     }
         # Process the configs in order, global, user, then any option passed
-        for configfile in (self.kojiconfig,
-                           os.path.expanduser('~/.koji/config')):
+        configs = self._get_koji_dir_configs('/etc/koji.conf.d')
+        configs.extend(
+                        [
+                         self.kojiconfig,
+                         os.path.expanduser('~/.koji/config'),
+                        ]
+                      )
+
+        for configfile in configs:
             try:
                 f = open(configfile)
             except IOError:
-- 
1.8.3.1



More information about the buildsys mailing list