2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-17 13:13:18 +00:00

Have the config.conf autoinit if needed

If something makes a call out of sequence, attempt
to auto-init.
This commit is contained in:
Jarrod Johnson 2015-09-30 14:14:40 -04:00
parent 2115fb3f78
commit b88a135602

View File

@ -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