mirror of
https://github.com/containers/podman-compose.git
synced 2025-01-23 22:39:04 +01:00
resolve conflict
This commit is contained in:
parent
2ad7daa81f
commit
00840d0613
@ -146,25 +146,19 @@ def fix_mount_dict(mount_dict, proj_name, srv_name):
|
|||||||
# ${VARIABLE?err} raise error if not set
|
# ${VARIABLE?err} raise error if not set
|
||||||
# $$ means $
|
# $$ means $
|
||||||
|
|
||||||
var_re = re.compile(r'\$(\{(?:[^\s\$:\-\}]+)\}|(?:[^\s\$\{\}]+))')
|
var_re = re.compile(r"""
|
||||||
var_def_re = re.compile(r'\$\{([^\s\$:\-\}]+)(:)?-([^\}]*)\}')
|
\$(?:
|
||||||
var_err_re = re.compile(r'\$\{([^\s\$:\-\}]+)(:)?\?([^\}]*)\}')
|
(?P<escaped>\$) |
|
||||||
|
(?P<named>[_a-zA-Z][_a-zA-Z0-9]*) |
|
||||||
def dicts_get(dicts, key, fallback='', fallback_empty=False):
|
(?:{
|
||||||
"""
|
(?P<braced>[_a-zA-Z][_a-zA-Z0-9]*)
|
||||||
get the given key from any dict in dicts, trying them one by one
|
(?:
|
||||||
if not found in any, then use fallback, if fallback is Exception raise is
|
(?::?-(?P<default>[^}]+)) |
|
||||||
"""
|
(?::?\?(?P<err>[^}]+))
|
||||||
value = None
|
)?
|
||||||
for d in dicts:
|
})
|
||||||
value = d.get(key, None)
|
)
|
||||||
if value is not None: break
|
""", re.VERBOSE)
|
||||||
if not value:
|
|
||||||
if fallback_empty or value is None:
|
|
||||||
value = fallback
|
|
||||||
if isinstance(value, Exception):
|
|
||||||
raise value
|
|
||||||
return value
|
|
||||||
|
|
||||||
def rec_subs(value, dicts):
|
def rec_subs(value, dicts):
|
||||||
"""
|
"""
|
||||||
@ -173,13 +167,18 @@ def rec_subs(value, dicts):
|
|||||||
if is_dict(value):
|
if is_dict(value):
|
||||||
value = dict([(k, rec_subs(v, dicts)) for k, v in value.items()])
|
value = dict([(k, rec_subs(v, dicts)) for k, v in value.items()])
|
||||||
elif is_str(value):
|
elif is_str(value):
|
||||||
value = var_re.sub(lambda m: dicts_get(dicts, m.group(1).strip('{}')), value)
|
def convert(m):
|
||||||
sub_def = lambda m: dicts_get(dicts, m.group(1), m.group(3), m.group(2) == ':')
|
if m.group("escaped") is not None:
|
||||||
value = var_def_re.sub(sub_def, value)
|
return "$"
|
||||||
sub_err = lambda m: dicts_get(dicts, m.group(1), RuntimeError(m.group(3)),
|
name = m.group("named") or m.group("braced")
|
||||||
m.group(2) == ':')
|
for d in dicts:
|
||||||
value = var_err_re.sub(sub_err, value)
|
value = d.get(name)
|
||||||
value = value.replace('$$', '$')
|
if value is not None:
|
||||||
|
return "%s" % value
|
||||||
|
if m.group("err") is not None:
|
||||||
|
raise RuntimeError(m.group("err"))
|
||||||
|
return m.group("default") or ""
|
||||||
|
value = var_re.sub(convert, value)
|
||||||
elif hasattr(value, "__iter__"):
|
elif hasattr(value, "__iter__"):
|
||||||
value = [rec_subs(i, dicts) for i in value]
|
value = [rec_subs(i, dicts) for i in value]
|
||||||
return value
|
return value
|
||||||
|
Loading…
Reference in New Issue
Block a user