File size: 648 Bytes
01e655b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
def get_env_val(key, val_type):
env_val = os.getenv(key.upper())
if env_val is not None and env_val != "":
if val_type == bool:
return env_val.lower() in ("true", "1", "t")
return val_type(env_val)
if env_val == "":
return None
return env_val
def get_env_or_arg(args, arg_name, default, arg_type):
arg_val = getattr(args, arg_name)
env_val = get_env_val(arg_name, arg_type)
if arg_type == bool and env_val is not None:
return env_val
if arg_val is not None:
return arg_val
elif env_val is not None:
return env_val
return default
|