-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_reader.py
36 lines (25 loc) · 970 Bytes
/
config_reader.py
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
import sys, getopt, json
from libs import api_config
#config_reader.py is used to retrieved config parameters from either json file or environment variables (i.e. api_config)
def getConfig(argv):
jsonFilePath = None
try:
opts, args = getopt.getopt(argv,"j:",["json="])
except getopt.GetoptError:
print('json_test.py -j <JSON config file>')
sys.exit(2)
for opt, arg in opts:
if opt in ("-j", "--json"):
jsonFilePath = arg
print("[config_reader.py] Input JSON file is ", jsonFilePath)
jsonData = None
if jsonFilePath is not None:
with open(jsonFilePath) as f:
jsonData = json.load(f)
config = api_config.get_config_from_env() if jsonData is None else jsonData
print("[config_reader.py] config dictionary: ", config)
return config
# if __name__ == "__main__":
# argv = sys.argv[1:]
# config = getConfig(argv)
# print("[config_reader.py] config dictionary: ", config)