1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

make things like $FILE(/etc/path/foo.conf) and $ENV(HOME) work without having to use brackets to index them

This commit is contained in:
Michael DeHaan 2013-02-09 22:35:27 -05:00
parent e906271f91
commit e6ead2ca74

View file

@ -110,14 +110,18 @@ def _varFind(basedir, text, vars, lookup_fatal, depth=0):
else: else:
is_complex = False is_complex = False
brace_level = 1 brace_level = 1
# is_lookup is true for $FILE(...) and friends # is_lookup is true for $FILE(...) and friends
is_lookup = False is_lookup = False
lookup_plugin_name = None lookup_plugin_name = None
end = var_start end = var_start
# part_start is an index of where the current part started # part_start is an index of where the current part started
part_start = var_start part_start = var_start
space = vars space = vars
while end < len(text) and (((is_lookup or is_complex) and brace_level > 0) or (not is_complex and not is_lookup)): while end < len(text) and (((is_lookup or is_complex) and brace_level > 0) or (not is_complex and not is_lookup)):
if text[end].isalnum() or text[end] == '_': if text[end].isalnum() or text[end] == '_':
pass pass
elif not is_complex and not is_lookup and text[end] == '(' and text[part_start:end].isupper(): elif not is_complex and not is_lookup and text[end] == '(' and text[part_start:end].isupper():
@ -145,7 +149,9 @@ def _varFind(basedir, text, vars, lookup_fatal, depth=0):
# This breaks out of the loop on non-variable name characters # This breaks out of the loop on non-variable name characters
break break
end += 1 end += 1
var_end = end var_end = end
# Handle "This has $ in it" # Handle "This has $ in it"
if var_end == part_start: if var_end == part_start:
return {'replacement': None, 'start': start, 'end': end} return {'replacement': None, 'start': start, 'end': end}
@ -162,7 +168,7 @@ def _varFind(basedir, text, vars, lookup_fatal, depth=0):
lookup_plugin_name, args = args.split(",", 1) lookup_plugin_name, args = args.split(",", 1)
args = args.strip() args = args.strip()
# args have to be templated # args have to be templated
args = varReplace(basedir, args, vars, depth=depth+1, expand_lists=True) args = varReplace(basedir, args, vars, depth=depth+1, expand_lists=False)
instance = utils.plugins.lookup_loader.get(lookup_plugin_name.lower(), basedir=basedir) instance = utils.plugins.lookup_loader.get(lookup_plugin_name.lower(), basedir=basedir)
if instance is not None: if instance is not None:
try: try: