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: I09219762a7f548f41c58547e463153ea25f13034
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M src/__main__.py
1 file changed, 29 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-image-uploader 
refs/changes/41/13141/1

diff --git a/src/__main__.py b/src/__main__.py
index 3750346..1bb7695 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -174,15 +174,22 @@
         """Loads the user-supplied config file or the system default.
            If the user supplies a bad filename we will stop."""
 
-        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:
-                raise Exception("The specified configuration file does not 
exist.  File=(%s)" %
-                                self.options.conf_file)
+        conf_file = DEFAULT_CONFIGURATION_FILE
 
-        elif os.path.isfile(DEFAULT_CONFIGURATION_FILE):
-            self.from_file(DEFAULT_CONFIGURATION_FILE)
+        if self.options and getattr(self.options, "conf_file"):
+            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 "
+                        "does not exist.  File=(%s)"
+                    ) % self.options.conf_file
+                )
+
+        self.from_file(conf_file)
 
     def from_option_groups(self, options, parser):
         for optGrp in parser.option_groups:
@@ -198,10 +205,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 ImageUploader section only
         try:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09219762a7f548f41c58547e463153ea25f13034
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-image-uploader
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to