Alon Bar-Lev has uploaded a new change for review.

Change subject: config: support conf.d notation for configuration
......................................................................

config: support conf.d notation for configuration

Read the config file and all config files within the .d directory sorted
by name.

It will make the configuration of the package simpler during
installation of 3rd party packages.

Change-Id: I16837ce0cf5877f760521797821722520b9928f5
Signed-off-by: Alon Bar-Lev <alo...@redhat.com>
---
M src/__main__.py
1 file changed, 22 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-iso-uploader 
refs/changes/40/13140/1

diff --git a/src/__main__.py b/src/__main__.py
index 67ef23a..b522439 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -210,10 +210,14 @@
         """Loads the user-supplied config file or the system default.
            If the user supplies a bad filename we will stop."""
 
+        conf_file = DEFAULT_CONFIGURATION_FILE
+
         if self.options and getattr(self.options, "conf_file"):
-            if os.path.isfile(self.options.conf_file):
-                self.from_file(self.options.conf_file)
-            else:
+            conf_file = self.options.conf_file
+            if (
+                not os.path.exists(conf_file) and
+                not os.path.exists("%s.d" % conf_file)
+            ):
                 raise Exception(
                     (
                         "The specified configuration file "
@@ -221,8 +225,7 @@
                     ) % self.options.conf_file
                 )
 
-        elif os.path.isfile(DEFAULT_CONFIGURATION_FILE):
-            self.from_file(DEFAULT_CONFIGURATION_FILE)
+        self.from_file(conf_file)
 
     def from_option_groups(self, options, parser):
         for optGrp in parser.option_groups:
@@ -238,10 +241,22 @@
                 if opt_value is not None:
                     self[option.dest] = opt_value
 
-    def from_file(self, filename):
+    def from_file(self, configFile):
         import ConfigParser
+        import glob
+
+        configs = []
+        configDir = '%s.d' % configFile
+        if os.path.exists(configFile):
+            configs.append(configFile)
+        configs += sorted(
+            glob.glob(
+                os.path.join(configDir, "*.conf")
+            )
+        )
+
         cp = ConfigParser.ConfigParser()
-        cp.read(filename)
+        cp.read(configs)
 
         # we want the items from the ISOUploader section only
         try:


--
To view, visit http://gerrit.ovirt.org/13140
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16837ce0cf5877f760521797821722520b9928f5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-iso-uploader
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to