Allow our config parser to have case insensitive sections/keys
This commit is contained in:
parent
6b231348d6
commit
651a1cf7b8
@ -48,10 +48,12 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
|||||||
DEF_BOOLEAN = False
|
DEF_BOOLEAN = False
|
||||||
DEF_BASE = None
|
DEF_BASE = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, cs=True):
|
||||||
ConfigParser.RawConfigParser.__init__(self)
|
ConfigParser.RawConfigParser.__init__(self)
|
||||||
#make option names case sensitive
|
if cs:
|
||||||
self.optionxform = str
|
# Make option names case sensitive
|
||||||
|
# See: http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser.optionxform
|
||||||
|
self.optionxform = str
|
||||||
|
|
||||||
def get(self, section, option):
|
def get(self, section, option):
|
||||||
value = IgnoreMissingConfigParser.DEF_BASE
|
value = IgnoreMissingConfigParser.DEF_BASE
|
||||||
@ -80,8 +82,8 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
|||||||
|
|
||||||
|
|
||||||
class StackConfigParser(IgnoreMissingConfigParser):
|
class StackConfigParser(IgnoreMissingConfigParser):
|
||||||
def __init__(self):
|
def __init__(self, cs=True):
|
||||||
IgnoreMissingConfigParser.__init__(self)
|
IgnoreMissingConfigParser.__init__(self, cs)
|
||||||
self.configs_fetched = dict()
|
self.configs_fetched = dict()
|
||||||
|
|
||||||
def _resolve_value(self, section, option, value_gotten):
|
def _resolve_value(self, section, option, value_gotten):
|
||||||
|
@ -129,7 +129,7 @@ class GlanceInstaller(GlanceMixin, comp.PythonInstallComponent):
|
|||||||
# then extract known configs that
|
# then extract known configs that
|
||||||
# will need locations/directories/files made (or touched)...
|
# will need locations/directories/files made (or touched)...
|
||||||
with io.BytesIO(contents) as stream:
|
with io.BytesIO(contents) as stream:
|
||||||
config = cfg.IgnoreMissingConfigParser()
|
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||||
config.readfp(stream)
|
config.readfp(stream)
|
||||||
if config.getboolean('default', 'image_cache_enabled'):
|
if config.getboolean('default', 'image_cache_enabled'):
|
||||||
cache_dir = config.get('default', "image_cache_datadir")
|
cache_dir = config.get('default', "image_cache_datadir")
|
||||||
|
@ -142,7 +142,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
|||||||
# then extract known configs that
|
# then extract known configs that
|
||||||
# ill need locations/directories/files made (or touched)...
|
# ill need locations/directories/files made (or touched)...
|
||||||
with io.BytesIO(contents) as stream:
|
with io.BytesIO(contents) as stream:
|
||||||
config = cfg.IgnoreMissingConfigParser()
|
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||||
config.readfp(stream)
|
config.readfp(stream)
|
||||||
log_filename = config.get('default', 'log_file')
|
log_filename = config.get('default', 'log_file')
|
||||||
if log_filename:
|
if log_filename:
|
||||||
|
@ -85,11 +85,14 @@ class MelangeInstaller(comp.PythonInstallComponent):
|
|||||||
self._sync_db()
|
self._sync_db()
|
||||||
|
|
||||||
def _sync_db(self):
|
def _sync_db(self):
|
||||||
LOG.info("Syncing the database with melange.")
|
LOG.info("Syncing melange to database named %r", DB_NAME)
|
||||||
mp = dict()
|
utils.execute_template(*DB_SYNC_CMD, params=self._get_param_map(None))
|
||||||
mp['BIN_DIR'] = self.bin_dir
|
|
||||||
|
def _get_param_map(self, config_fn):
|
||||||
|
mp = comp.PythonInstallComponent._get_param_map(self, config_fn)
|
||||||
mp['CFG_FILE'] = sh.joinpths(self.cfg_dir, ROOT_CONF_REAL_NAME)
|
mp['CFG_FILE'] = sh.joinpths(self.cfg_dir, ROOT_CONF_REAL_NAME)
|
||||||
utils.execute_template(*DB_SYNC_CMD, params=mp)
|
mp['BIN_DIR'] = self.bin_dir
|
||||||
|
return mp
|
||||||
|
|
||||||
def _get_config_files(self):
|
def _get_config_files(self):
|
||||||
return list(CONFIGS)
|
return list(CONFIGS)
|
||||||
@ -98,12 +101,12 @@ class MelangeInstaller(comp.PythonInstallComponent):
|
|||||||
if config_fn == ROOT_CONF:
|
if config_fn == ROOT_CONF:
|
||||||
newcontents = contents
|
newcontents = contents
|
||||||
with io.BytesIO(contents) as stream:
|
with io.BytesIO(contents) as stream:
|
||||||
config = cfg.IgnoreMissingConfigParser()
|
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||||
config.readfp(stream)
|
config.readfp(stream)
|
||||||
db_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
db_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
||||||
old_dbsn = config.get('DEFAULT', 'sql_connection')
|
old_dbsn = config.get('default', 'sql_connection')
|
||||||
if db_dsn != old_dbsn:
|
if db_dsn != old_dbsn:
|
||||||
config.set('DEFAULT', 'sql_connection', db_dsn)
|
config.set('default', 'sql_connection', db_dsn)
|
||||||
with io.BytesIO() as outputstream:
|
with io.BytesIO() as outputstream:
|
||||||
config.write(outputstream)
|
config.write(outputstream)
|
||||||
outputstream.flush()
|
outputstream.flush()
|
||||||
|
@ -97,11 +97,11 @@ class QuantumInstaller(QuantumMixin, comp.PkgInstallComponent):
|
|||||||
# Need to fix the "Quantum plugin provider module"
|
# Need to fix the "Quantum plugin provider module"
|
||||||
newcontents = contents
|
newcontents = contents
|
||||||
with io.BytesIO(contents) as stream:
|
with io.BytesIO(contents) as stream:
|
||||||
config = cfg.IgnoreMissingConfigParser()
|
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||||
config.readfp(stream)
|
config.readfp(stream)
|
||||||
provider = config.get("PLUGIN", "provider")
|
provider = config.get("plugin", "provider")
|
||||||
if provider != V_PROVIDER:
|
if provider != V_PROVIDER:
|
||||||
config.set("PLUGIN", "provider", V_PROVIDER)
|
config.set("plugin", "provider", V_PROVIDER)
|
||||||
with io.BytesIO() as outputstream:
|
with io.BytesIO() as outputstream:
|
||||||
config.write(outputstream)
|
config.write(outputstream)
|
||||||
outputstream.flush()
|
outputstream.flush()
|
||||||
@ -111,13 +111,13 @@ class QuantumInstaller(QuantumMixin, comp.PkgInstallComponent):
|
|||||||
# Need to adjust the sql connection
|
# Need to adjust the sql connection
|
||||||
newcontents = contents
|
newcontents = contents
|
||||||
with io.BytesIO(contents) as stream:
|
with io.BytesIO(contents) as stream:
|
||||||
config = cfg.IgnoreMissingConfigParser()
|
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||||
config.readfp(stream)
|
config.readfp(stream)
|
||||||
db_dsn = config.get("DATABASE", "sql_connection")
|
db_dsn = config.get("database", "sql_connection")
|
||||||
if db_dsn:
|
if db_dsn:
|
||||||
generated_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
generated_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
||||||
if generated_dsn != db_dsn:
|
if generated_dsn != db_dsn:
|
||||||
config.set("DATABASE", "sql_connection", generated_dsn)
|
config.set("database", "sql_connection", generated_dsn)
|
||||||
with io.BytesIO() as outputstream:
|
with io.BytesIO() as outputstream:
|
||||||
config.write(outputstream)
|
config.write(outputstream)
|
||||||
outputstream.flush()
|
outputstream.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user