mirror of
https://github.com/containers/podman-compose.git
synced 2025-04-13 03:58:52 +02:00
move helpers up
This commit is contained in:
parent
079cc0fd9b
commit
5f7e46dbbe
@ -25,10 +25,22 @@ PY3 = sys.version_info[0] == 3
|
|||||||
if PY3:
|
if PY3:
|
||||||
basestring = str
|
basestring = str
|
||||||
|
|
||||||
|
# helper functions
|
||||||
|
|
||||||
is_str = lambda s: isinstance(s, basestring)
|
is_str = lambda s: isinstance(s, basestring)
|
||||||
is_dict = lambda d: isinstance(d, dict)
|
is_dict = lambda d: isinstance(d, dict)
|
||||||
is_list = lambda l: not is_str(l) and not is_dict(l) and hasattr(l, "__iter__")
|
is_list = lambda l: not is_str(l) and not is_dict(l) and hasattr(l, "__iter__")
|
||||||
|
|
||||||
|
def try_int(i, fallback=None):
|
||||||
|
try:
|
||||||
|
return int(i)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
# docker and docker-compose support subset of bash variable substitution
|
# docker and docker-compose support subset of bash variable substitution
|
||||||
# https://docs.docker.com/compose/compose-file/#variable-substitution
|
# https://docs.docker.com/compose/compose-file/#variable-substitution
|
||||||
# https://docs.docker.com/compose/env-file/
|
# https://docs.docker.com/compose/env-file/
|
||||||
@ -79,17 +91,6 @@ def rec_subs(value, dicts):
|
|||||||
value = [rec_subs(i, dicts) for i in value]
|
value = [rec_subs(i, dicts) for i in value]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
# helper functions
|
|
||||||
def try_int(i, fallback=None):
|
|
||||||
try:
|
|
||||||
return int(i)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
return fallback
|
|
||||||
|
|
||||||
def norm_as_list(src):
|
def norm_as_list(src):
|
||||||
"""
|
"""
|
||||||
given a dictionary {key1:value1, key2: None} or list
|
given a dictionary {key1:value1, key2: None} or list
|
||||||
|
Loading…
Reference in New Issue
Block a user