From 4ad7f2e5111ca9e27dcbe5781c87f249bc7377ad Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Thu, 9 Nov 2023 13:57:26 +0100 Subject: added new function to get env which handles missing env better... --- scripts/common/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'scripts/common/__init__.py') diff --git a/scripts/common/__init__.py b/scripts/common/__init__.py index e349610..e3ea442 100644 --- a/scripts/common/__init__.py +++ b/scripts/common/__init__.py @@ -6,7 +6,22 @@ import os import sys from datetime import datetime -QUEUE = bool(os.environ.get("el_QUEUE", False)) + +# Get env var +def env(var_name, default=None): + value = os.getenv(var_name) + if value is not None: + return value + + if default is not None: + return default + + print(f"Error: Could not find environment variable '{var_name}'") + print("That variable is required for running this program.") + sys.exit(1) + + +QUEUE = bool(env("el_QUEUE", False)) name = os.path.splitext(os.path.split(sys.argv[0])[-1])[0] -- cgit v1.2.3