Updated so we do a param find stage and then only attempt to replace those that we found in the find stage, this should make comments not be a problem
This commit is contained in:
parent
95e9310ecb
commit
065b4f5241
@ -144,7 +144,6 @@ alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_
|
|||||||
def _generate_nova_env(self):
|
def _generate_nova_env(self):
|
||||||
lines = list()
|
lines = list()
|
||||||
lines.append('# Nova stuff')
|
lines.append('# Nova stuff')
|
||||||
key_params = keystone.get_shared_params(self.cfg)
|
|
||||||
lines.extend(self._make_export_cfg('NOVA_VERSION',
|
lines.extend(self._make_export_cfg('NOVA_VERSION',
|
||||||
('nova', 'nova_version')))
|
('nova', 'nova_version')))
|
||||||
lines.extend(self._make_export_cfg('NOVA_CERT',
|
lines.extend(self._make_export_cfg('NOVA_CERT',
|
||||||
|
@ -351,6 +351,30 @@ def param_replace_list(values, replacements, ignore_missing=False):
|
|||||||
return new_values
|
return new_values
|
||||||
|
|
||||||
|
|
||||||
|
def params_find(text):
|
||||||
|
|
||||||
|
#knock off all comments
|
||||||
|
cleaned_text = list()
|
||||||
|
for line in text.splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if len(line) == 0:
|
||||||
|
continue
|
||||||
|
if line.startswith("#"):
|
||||||
|
continue
|
||||||
|
#TODO: handle inline comments??
|
||||||
|
cleaned_text.append(line)
|
||||||
|
|
||||||
|
found_params = set()
|
||||||
|
|
||||||
|
def finder(match):
|
||||||
|
found_params.add(match.group(1))
|
||||||
|
|
||||||
|
for line in cleaned_text:
|
||||||
|
PARAM_SUB_REGEX.sub(finder, line)
|
||||||
|
|
||||||
|
return found_params
|
||||||
|
|
||||||
|
|
||||||
def param_replace(text, replacements, ignore_missing=False):
|
def param_replace(text, replacements, ignore_missing=False):
|
||||||
|
|
||||||
if not replacements:
|
if not replacements:
|
||||||
@ -364,19 +388,25 @@ def param_replace(text, replacements, ignore_missing=False):
|
|||||||
else:
|
else:
|
||||||
LOG.debug("Performing parameter replacements (not ignoring missing) on text [%s]" % (text))
|
LOG.debug("Performing parameter replacements (not ignoring missing) on text [%s]" % (text))
|
||||||
|
|
||||||
def replacer(match):
|
possible_params = params_find(text)
|
||||||
org = match.group(0)
|
LOG.debug("Potential parameters are [%s]" % (", ".join(possible_params)))
|
||||||
name = match.group(1)
|
|
||||||
|
|
||||||
v = replacements.get(name)
|
if not ignore_missing:
|
||||||
if v is None and ignore_missing:
|
for r in possible_params:
|
||||||
v = org
|
if r not in replacements:
|
||||||
elif v is None and not ignore_missing:
|
msg = "No replacement found for parameter %s" % (r)
|
||||||
msg = "No replacement found for parameter %s" % (org)
|
raise excp.NoReplacementException(msg)
|
||||||
raise excp.NoReplacementException(msg)
|
|
||||||
else:
|
def replacer(match):
|
||||||
LOG.debug("Replacing [%s] with [%s]" % (org, str(v)))
|
org_val = match.group(0)
|
||||||
return str(v)
|
param_name = match.group(1)
|
||||||
|
replacement_value = org_val
|
||||||
|
if param_name in possible_params:
|
||||||
|
replacement_value = replacements.get(param_name)
|
||||||
|
if replacement_value is None:
|
||||||
|
replacement_value = org_val
|
||||||
|
LOG.debug("Replacing [%s] with [%s]" % (org_val, str(replacement_value)))
|
||||||
|
return replacement_value
|
||||||
|
|
||||||
return PARAM_SUB_REGEX.sub(replacer, text)
|
return PARAM_SUB_REGEX.sub(replacer, text)
|
||||||
|
|
||||||
|
6
stack
6
stack
@ -92,8 +92,10 @@ def run(args):
|
|||||||
if not rootdir:
|
if not rootdir:
|
||||||
print(utils.color_text("No root directory specified!", "red"))
|
print(utils.color_text("No root directory specified!", "red"))
|
||||||
return False
|
return False
|
||||||
(rep, maxlen) = utils.welcome(_WELCOME_MAP.get(action))
|
|
||||||
print(utils.center_text("Action Runner", rep, maxlen))
|
#welcome!
|
||||||
|
(repeat_string, line_max_len) = utils.welcome(_WELCOME_MAP.get(action))
|
||||||
|
print(utils.center_text("Action Runner", repeat_string, line_max_len))
|
||||||
|
|
||||||
#here on out we should be using the logger (and not print)
|
#here on out we should be using the logger (and not print)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
Loading…
Reference in New Issue
Block a user