From b88a13560261765f26e4fd603c11b1497226d449 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 30 Sep 2015 14:14:40 -0400 Subject: [PATCH] Have the config.conf autoinit if needed If something makes a call out of sequence, attempt to auto-init. --- confluent_server/confluent/config/conf.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/config/conf.py b/confluent_server/confluent/config/conf.py index 80bf032f..aeca1cd6 100644 --- a/confluent_server/confluent/config/conf.py +++ b/confluent_server/confluent/config/conf.py @@ -15,12 +15,13 @@ # limitations under the License. -#This defines config variable to store the global configuration for confluent +# This defines config variable to store the global configuration for confluent import ConfigParser import os _config = None + def init_config(): global _config configfile = "/etc/confluent/service.cfg" @@ -30,25 +31,39 @@ def init_config(): _config = ConfigParser.ConfigParser() _config.read(configfile) + def get_config(): + if _config is None: + init_config() return _config + def get_int_option(section, option): + if _config is None: + init_config() try: return _config.getint(section, option) except ( - ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): + ConfigParser.NoSectionError, ConfigParser.NoOptionError, + ValueError): return None + def get_boolean_option(section, option): + if _config is None: + init_config() try: return _config.getboolean(section, option) except ( - ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): + ConfigParser.NoSectionError, ConfigParser.NoOptionError, + ValueError): return None + def get_option(section, option): + if _config is None: + init_config() try: return _config.get(section, option) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): - return None + return None \ No newline at end of file