move helpers up

This commit is contained in:
alsadi 2019-05-09 23:16:40 +03:00
parent 079cc0fd9b
commit 5f7e46dbbe

View File

@ -25,10 +25,22 @@ PY3 = sys.version_info[0] == 3
if PY3:
basestring = str
# helper functions
is_str = lambda s: isinstance(s, basestring)
is_dict = lambda d: isinstance(d, dict)
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
# https://docs.docker.com/compose/compose-file/#variable-substitution
# 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]
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):
"""
given a dictionary {key1:value1, key2: None} or list