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: I702336baaf0258f2ee40069889f7c3a0764a664e Signed-off-by: Alon Bar-Lev <[email protected]> --- M src/__main__.py 1 file changed, 26 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector refs/changes/42/13142/1 diff --git a/src/__main__.py b/src/__main__.py index d7cae54..2476404 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -243,17 +243,22 @@ """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 does not exist. \ -File=(%s)" % self.options.conf_file + ( + "The specified configuration file " + "does not exist. File=(%s)" + ) % self.options.conf_file ) - elif os.path.isfile(config.DEFAULT_CONFIGURATION_FILE): - self.from_file(config.DEFAULT_CONFIGURATION_FILE) + self.from_file(conf_file) def from_option_groups(self, options, parser): for optGrp in parser.option_groups: @@ -269,10 +274,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 LogCollector section only try: -- To view, visit http://gerrit.ovirt.org/13142 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I702336baaf0258f2ee40069889f7c3a0764a664e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-log-collector Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
