Skip to content

Commit 928964c

Browse files
author
matthias_schaub
committed
load config now definied in definitions.py. Import CONFIG dict from definitions.
1 parent 0d57903 commit 928964c

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

mapswipe_workers/mapswipe_workers/auth.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
1-
#!/usr/bin/python3
2-
#
3-
# Author: B. Herfort, M. Reinmuth, 2017
4-
############################################
5-
6-
import json
7-
81
import psycopg2
92
import firebase_admin
103
from firebase_admin import credentials
114
from firebase_admin import db
125

136
from mapswipe_workers.definitions import CONFIG_PATH
7+
from mapswipe_workers.definitions import CONFIG
148
from mapswipe_workers.definitions import SERVICE_ACCOUNT_KEY_PATH
159

1610

17-
def load_config():
18-
"""
19-
Loads the user configuration values.
20-
21-
Returns
22-
-------
23-
dictonary
24-
"""
25-
with open(CONFIG_PATH) as f:
26-
CONFIG = json.load(f)
27-
return CONFIG
28-
29-
3011
def get_api_key(tileserver):
31-
CONFIG = load_config()
3212
try:
3313
if tileserver == "custom":
3414
return None
@@ -43,7 +23,6 @@ def get_api_key(tileserver):
4323

4424

4525
def get_tileserver_url(tileserver):
46-
CONFIG = load_config()
4726
try:
4827
if tileserver == "custom":
4928
return None
@@ -66,8 +45,7 @@ def firebaseDB():
6645
return db
6746
except ValueError:
6847
cred = credentials.Certificate(SERVICE_ACCOUNT_KEY_PATH)
69-
config = load_config()
70-
databaseName = config["firebase"]["database_name"]
48+
databaseName = CONFIG["firebase"]["database_name"]
7149
databaseURL = f"https://{databaseName}.firebaseio.com"
7250

7351
# Initialize the app with a service account, granting admin privileges
@@ -82,7 +60,6 @@ class postgresDB(object):
8260
_db_cur = None
8361

8462
def __init__(self):
85-
CONFIG = load_config()
8663
try:
8764
host = CONFIG["postgres"]["host"]
8865
port = CONFIG["postgres"]["port"]

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import logging.config
34
import os
@@ -10,12 +11,25 @@
1011
)
1112
from mapswipe_workers.project_types.footprint.footprint_project import FootprintProject
1213

14+
15+
class CustomError(Exception):
16+
pass
17+
18+
19+
def load_config(CONFIG_PATH) -> dict:
20+
"""Read the configuration file."""
21+
with open(CONFIG_PATH) as f:
22+
return json.load(f)
23+
24+
1325
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
1426

1527
CONFIG_DIR = os.path.abspath("/usr/share/config/mapswipe_workers/")
1628

1729
CONFIG_PATH = os.path.join(CONFIG_DIR, "configuration.json")
1830

31+
CONFIG = load_config(CONFIG_PATH)
32+
1933
SERVICE_ACCOUNT_KEY_PATH = os.path.join(CONFIG_DIR, "serviceAccountKey.json")
2034

2135
LOGGING_CONFIG_PATH = os.path.join(CONFIG_DIR, "logging.cfg")
@@ -36,7 +50,3 @@
3650

3751
logging.config.fileConfig(fname=LOGGING_CONFIG_PATH, disable_existing_loggers=True)
3852
logger = logging.getLogger("Mapswipe Workers")
39-
40-
41-
class CustomError(Exception):
42-
pass

0 commit comments

Comments
 (0)