aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/common/__init__.py
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-11-09 13:57:26 +0100
committerDennis Eriksen <d@ennis.no>2023-11-09 13:57:26 +0100
commit4ad7f2e5111ca9e27dcbe5781c87f249bc7377ad (patch)
treed605620535229e741f7e2da473086fe185f78e5f /scripts/common/__init__.py
parentsmall fixes (diff)
downloadenergyscripts-4ad7f2e5111ca9e27dcbe5781c87f249bc7377ad.tar.gz
added new function to get env
which handles missing env better...
Diffstat (limited to 'scripts/common/__init__.py')
-rw-r--r--scripts/common/__init__.py17
1 files changed, 16 insertions, 1 deletions
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]