aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/common
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/common')
-rw-r--r--scripts/common/__init__.py17
-rw-r--r--scripts/common/postgres.py11
-rw-r--r--scripts/common/queue.py7
3 files changed, 26 insertions, 9 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]
diff --git a/scripts/common/postgres.py b/scripts/common/postgres.py
index 5f6ea31..5692535 100644
--- a/scripts/common/postgres.py
+++ b/scripts/common/postgres.py
@@ -1,15 +1,16 @@
#!/usr/bin/env python3
""" common functions and stuff """
-import os
import sys
import psycopg
-pg_db = os.environ["el_pg_db"]
-pg_host = os.environ["el_pg_host"]
-pg_user = os.environ.get("el_pg_user", "")
-pg_pass = os.environ.get("el_pg_pass", "")
+from . import env
+
+pg_db = env("el_pg_db")
+pg_host = env("el_pg_host")
+pg_user = env("el_pg_user", "")
+pg_pass = env("el_pg_pass", "")
def dbi(sql, values, **kwargs):
diff --git a/scripts/common/queue.py b/scripts/common/queue.py
index de49802..f67acbb 100644
--- a/scripts/common/queue.py
+++ b/scripts/common/queue.py
@@ -2,13 +2,14 @@
""" common functions and stuff """
import logging
-import os
import pickle
from litequeue import SQLQueue
-QUEUE_DB = os.environ.get("el_QUEUE_db", "litequeue.db")
-QUEUE_DIR = os.environ.get("el_QUEUE_dir", "queue")
+from . import env
+
+QUEUE_DB = env("el_QUEUE_db", "litequeue.db")
+QUEUE_DIR = env("el_QUEUE_dir", "queue")
QUEUE_DB = QUEUE_DIR + "/" + QUEUE_DB