This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_env.py
70 lines (64 loc) · 2.38 KB
/
check_env.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
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
import sys
def get_keys_from_file(file_name):
all_keys = {}
try:
with open(file_name, "r") as stream:
lines = stream.readlines()
for line in lines:
split_line = line.split("=")
if len(split_line) == 2:
if split_line[1] == "\n":
all_keys[split_line[0]] = False
else:
all_keys[split_line[0]] = True
except FileNotFoundError:
print(f"Could not find file {file_name}. Aborting.")
sys.exit(1)
return all_keys
def get_keys_from_config_file(file_name):
all_keys = {}
try:
with open(file_name, "r") as stream:
lines = stream.readlines()
for line in lines:
split_line = line.split(":")
if len(split_line) >= 2:
if split_line[1] == "\n":
all_keys[split_line[0].strip()] = False
else:
all_keys[split_line[0].strip()] = True
except FileNotFoundError:
print(f"Could not find file {file_name}. Aborting.")
sys.exit(1)
return all_keys
if __name__ == "__main__":
if sys.argv[3] == "env":
env_in = get_keys_from_file(sys.argv[1])
env_to_check = get_keys_from_file(sys.argv[2])
for k, v in env_in.items():
if k in env_to_check:
if env_to_check[k]:
continue
else:
print(f"{k} is not set in your env file.")
else:
print(f"{k} is missing as a key in your env file.")
elif sys.argv[3] == "config":
config_in = get_keys_from_config_file(sys.argv[1])
config_to_check = get_keys_from_config_file(sys.argv[2])
for k, v in config_in.items():
if k in config_to_check:
if config_to_check[k]:
continue
else:
if not v:
print(
f"{k} is not set in your config file. Could also be a yml key."
)
else:
print(f"{k} is not set in your config file.")
else:
print(f"{k} is missing as a key in your config file.")
else:
print("No information which files to check. Aborting.")
sys.exit(1)