-
Notifications
You must be signed in to change notification settings - Fork 14
/
check-properties.py
executable file
·48 lines (38 loc) · 1.07 KB
/
check-properties.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
#!/usr/bin/env python3
import sys
def check(file):
print(f"Check {file.name}")
dic = {}
for line in file.readlines():
line = line.strip()
if line.startswith("#"):
continue
if "=" not in line:
continue
comp = line.split("=")
dic[comp[0]] = comp[1]
for key in ["registration.url", "db.user", "db.password", "db.url"]:
if not assert_key(dic, key):
print(f"{key} is not set in {file.name}", file=sys.stderr)
exit(1)
for key in ["sync.url"]:
if not assert_key_not_empty(dic, key):
print(f"{key} is empty in {file.name}", file=sys.stderr)
exit(1)
def assert_key_not_empty(dic, key):
if key not in dic:
return True
if not dic[key].strip():
return False
return True
def assert_key(dic, key):
if key not in dic:
return False
if not dic[key].strip():
return False
return True
if __name__ == "__main__":
if len(sys.argv) < 2:
exit(1)
with open(sys.argv[1]) as f:
check(f)