Commit bd419263 authored by Marco Mariani's avatar Marco Mariani

removed support for 'required=False' in config file

parent 42d75411
...@@ -28,34 +28,14 @@ class ConfigCommand(Command): ...@@ -28,34 +28,14 @@ class ConfigCommand(Command):
(self.default_config_var, self.default_config_path)) (self.default_config_var, self.default_config_path))
return ap return ap
def _get_config(self, cfg_path, required=False): def fetch_config(self, args):
""" """
Returns a configuration object if file exists/readable/valid, Returns a configuration object if file exists/readable/valid,
None otherwise. will raise an error otherwise. The exception may come from the
Will raise an error instead of returning None if required is True. configparser itself if the configuration content is very broken,
Even if required is False, may still raise an exception from the and will clearly show what is wrong with the file.
configparser if the configuration content is very broken.
We don't catch that exception as it will clearly show what is
wrong with the file.
""" """
if not os.path.exists(cfg_path):
if required:
raise ConfigError('Configuration file does not exist: %s' % cfg_path)
else:
return None
configp = ConfigParser.SafeConfigParser()
if configp.read(cfg_path) != [cfg_path]:
# bad permission, etc.
if required:
raise ConfigError('Cannot parse configuration file: %s' % cfg_path)
else:
return None
return configp
def fetch_config(self, args):
if args.cfg: if args.cfg:
cfg_path = args.cfg cfg_path = args.cfg
else: else:
...@@ -65,7 +45,15 @@ class ConfigCommand(Command): ...@@ -65,7 +45,15 @@ class ConfigCommand(Command):
self.log.debug('Loading config: %s' % cfg_path) self.log.debug('Loading config: %s' % cfg_path)
return self._get_config(cfg_path, required=True) if not os.path.exists(cfg_path):
raise ConfigError('Configuration file does not exist: %s' % cfg_path)
configp = ConfigParser.SafeConfigParser()
if configp.read(cfg_path) != [cfg_path]:
# bad permission, etc.
raise ConfigError('Cannot parse configuration file: %s' % cfg_path)
return configp
class ClientConfigCommand(ConfigCommand): class ClientConfigCommand(ConfigCommand):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment