This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
forked from Tinkerforge/warp-charger
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_doc_completeness.py
executable file
·72 lines (55 loc) · 1.88 KB
/
check_doc_completeness.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
71
72
#!/usr/bin/python3
import json
import sys
from bs4 import BeautifulSoup
if len(sys.argv) != 2:
print("Usage: {} [path/to/debug_report.json]".format(sys.argv[0]))
sys.exit(0)
UNDOCUMENTED = [
"free_heap_bytes",
"largest_free_heap_block",
"devices",
"error_counters",
"modules",
"debug/state",
"proxy/devices",
"proxy/error_counters"
]
with open("warp-charger.com/api.html") as fp:
soup = BeautifulSoup(fp, 'html.parser')
entries = sum([s.select('div[id]') for s in soup.select('#reference')[0].select('section')], [])
documented = {}
def first_line(x):
for br in x.find_all("br"):
br.replace_with("\n")
result = x.get_text()
if " \n" in result:
result = result.split(" \n")[0]
return result
for e in entries:
topic = first_line(e)
payload_keys = [first_line(x) for x in e.parent.select('th[scope="row"]')]
documented[topic] = payload_keys
with open(sys.argv[1]) as f:
debug_report = json.load(f)
for k, v in debug_report.items():
if k in UNDOCUMENTED:
continue
if k.endswith("_update") and k.replace("_update", "") in debug_report:
continue
if k not in documented:
print("Topic {} is undocumented.".format(k))
continue
impl_dict = isinstance(v, dict)
doc_dict = len(documented[k]) > 0
if impl_dict != doc_dict:
print("Topic {} is {}implemented as object, but is {}documented as such.".format(k, "" if impl_dict else "not ", "" if doc_dict else "not "))
continue
if not impl_dict:
continue
for impl_key, impl_val in v.items():
if impl_key not in documented[k]:
print("Topic {} is missing the implemented key {}.".format(k, impl_key))
for doc_key in documented[k]:
if doc_key not in v:
print("Topic {} documents key {}, but this key is missing in the implementation.".format(k, doc_key))