-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
95 lines (67 loc) · 2.35 KB
/
Copy pathconfig.py
File metadata and controls
95 lines (67 loc) · 2.35 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#! /usr/bin/env python3
### TODO
# understand the program_parameters.py file and merge into this file as appropriate.
"""
config.py
Two main jobs for this:
1. Loads the environment variables.
2. Configures the logger, to be imported into main scripts.
It also, only temporarily, includes hard-coded credentials for FTPing into CDDIS server.
"""
import logging
from os import getenv, path
from pathlib import Path
from dotenv import load_dotenv
import sys
### useful globals:
base_dir = path.dirname(__file__)
### load the environment ###
load_dotenv() # this finds and loads `.env` files automatically.
"""
Environment variables keys:
SFB_DB_USER=
SFB_DB_PASSWD=
SFB_EMAIL=
SFB_SMTP_HOST=
SFB_SMTP_PORT=
SFB_TLS_USER=
SFB_TLS_PASSWD=
"""
smtp_conf = {"host": getenv("SFB_SMTP_HOST"), "port": getenv("SFB_SMTP_PORT")}
tls_conf = {"user": getenv("SFB_TLS_USER"), "passwd": getenv("SFB_TLS_PASSWD")}
# and these are what we 'export':
db_conf = {
"user": getenv("SFB_DB_USER"),
"passwd": getenv("SFB_DB_PASSWD"),
"host": getenv("SFB_DB_HOST"),
"name": getenv("SFB_DB_NAME"),
}
email_conf = {"email": getenv("SFB_EMAIL"), "smtp": smtp_conf, "tls": tls_conf}
### cddis ftp set-up ###
cddis_ftp = {"host": "gdc.cddis.eosdis.nasa.gov", "user": "anonymous", "passwd": "tiegem@utas.edu.au", "timeout": 20} ### FIXME: the credentials need to be in the .env
### configure the logger ###
# log format: "timestamp-log_level: file-line_number: message".
fmt = logging.Formatter(
"[%(asctime)s-%(levelname)s] %(threadName)s-%(filename)s-%(lineno)d: %(message)s", "%Y.%j.%H:%M:%S"
)
# Choose whether to log to stdout or to a file.
log_2_stdout = True # set to False to log to file instead.
if log_2_stdout:
handle = logging.StreamHandler(sys.stdout)
else:
log_output_dir = "/var/log/ivs_station_fb_logs"
log_output_file = "stationFeedback.log"
# make log output directory
log_dir_path = Path(log_output_dir)
log_dir_path.mkdir(parents=True, exist_ok=True)
log_file_path = log_dir_path / log_output_file
handle = logging.FileHandler(log_file_path)
# set up logger
logger = logging.getLogger(__name__)
handle.setFormatter(fmt)
logger.addHandler(handle)
logger.setLevel(logging.DEBUG) # set default level
### other miscellaneous settings ###
stations_config_file = path.abspath(
path.join(path.dirname(__file__), "stations.yaml")
)